|
28 | 28 | describe ".detect!" do |
29 | 29 | it "returns the detected language" do |
30 | 30 | locale = "de" |
31 | | - DiscourseAi::Completions::Llm.with_prepared_responses([locale_json(locale)]) do |
| 31 | + DiscourseAi::Completions::Llm.with_prepared_responses([locale]) do |
32 | 32 | expect(DiscourseTranslator::Provider::DiscourseAi.detect!(post)).to eq locale |
33 | 33 | end |
34 | 34 | end |
|
41 | 41 | end |
42 | 42 |
|
43 | 43 | it "translates the post and returns [locale, translated_text]" do |
44 | | - DiscourseAi::Completions::Llm.with_prepared_responses( |
45 | | - [translation_json("some translated text")], |
46 | | - ) do |
| 44 | + DiscourseAi::Completions::Llm.with_prepared_responses(["some translated text"]) do |
47 | 45 | translated_text = DiscourseTranslator::Provider::DiscourseAi.translate_translatable!(post) |
48 | 46 | expect(translated_text).to eq "<p>some translated text</p>" |
49 | 47 | end |
50 | 48 | end |
51 | 49 |
|
52 | 50 | it "translates the topic" do |
53 | 51 | allow(::DiscourseAi::TopicTranslator).to receive(:new).and_call_original |
54 | | - DiscourseAi::Completions::Llm.with_prepared_responses( |
55 | | - [translation_json("some translated text")], |
56 | | - ) do |
| 52 | + DiscourseAi::Completions::Llm.with_prepared_responses(["some translated text"]) do |
57 | 53 | translated_text = DiscourseTranslator::Provider::DiscourseAi.translate_translatable!(topic) |
58 | 54 | expect(translated_text).to eq "some translated text" |
59 | 55 | end |
60 | 56 | end |
61 | 57 |
|
62 | 58 | it "sends the content for splitting and the split content for translation" do |
63 | 59 | post.update(raw: "#{"a" * 3000} #{"b" * 3000}") |
64 | | - DiscourseAi::Completions::Llm.with_prepared_responses( |
65 | | - %w[lol wut].map { |content| translation_json(content) }, |
66 | | - ) do |
| 60 | + DiscourseAi::Completions::Llm.with_prepared_responses(%w[lol wut]) do |
67 | 61 | expect( |
68 | 62 | DiscourseTranslator::Provider::DiscourseAi.translate_translatable!(post), |
69 | 63 | ).to eq "<p>lolwut</p>" |
|
73 | 67 |
|
74 | 68 | describe ".translate_text!" do |
75 | 69 | it "returns the translated text" do |
76 | | - DiscourseAi::Completions::Llm.with_prepared_responses( |
77 | | - [translation_json("some translated text")], |
78 | | - ) do |
| 70 | + DiscourseAi::Completions::Llm.with_prepared_responses(["some translated text"]) do |
79 | 71 | translated_text = DiscourseTranslator::Provider::DiscourseAi.translate_text!("derp") |
80 | 72 | expect(translated_text).to eq "some translated text" |
81 | 73 | end |
82 | 74 | end |
83 | 75 | end |
84 | | - |
85 | | - def locale_json(content) |
86 | | - { locale: content }.to_json |
87 | | - end |
88 | | - |
89 | | - def translation_json(content) |
90 | | - { translation: content }.to_json |
91 | | - end |
92 | 76 | end |
0 commit comments