From 8eb1e851fc409f86f3e1916ea706973b2ab7ea62 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 16 Jan 2024 16:28:24 +0100 Subject: [PATCH] DEV: Spec didn't work correctly with translations (#429) --- .../admin/ai_personas_controller_spec.rb | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/spec/requests/admin/ai_personas_controller_spec.rb b/spec/requests/admin/ai_personas_controller_spec.rb index 652370fa..c7de6d63 100644 --- a/spec/requests/admin/ai_personas_controller_spec.rb +++ b/spec/requests/admin/ai_personas_controller_spec.rb @@ -58,26 +58,45 @@ RSpec.describe DiscourseAi::Admin::AiPersonasController do expect(serializer_persona2["commands"]).to eq([["SearchCommand", { "base_query" => "test" }]]) end - it "returns localized persona names and descriptions" do - SiteSetting.default_locale = "fr" + context "with translations" do + before do + SiteSetting.default_locale = "fr" - get "/admin/plugins/discourse-ai/ai_personas.json" + TranslationOverride.upsert!( + SiteSetting.default_locale, + "discourse_ai.ai_bot.personas.general.name", + "Général", + ) + TranslationOverride.upsert!( + SiteSetting.default_locale, + "discourse_ai.ai_bot.personas.general.description", + "Général Description", + ) + end - TranslationOverride.upsert!(:fr, "discourse_ai.ai_bot.personas.general.name", "Général") - TranslationOverride.upsert!( - :fr, - "discourse_ai.ai_bot.personas.general.description", - "Général Description", - ) + after do + TranslationOverride.revert!( + SiteSetting.default_locale, + "discourse_ai.ai_bot.personas.general.name", + ) + TranslationOverride.revert!( + SiteSetting.default_locale, + "discourse_ai.ai_bot.personas.general.description", + ) + end - id = - DiscourseAi::AiBot::Personas::Persona.system_personas[DiscourseAi::AiBot::Personas::General] - name = I18n.t("discourse_ai.ai_bot.personas.general.name") - description = I18n.t("discourse_ai.ai_bot.personas.general.description") - persona = response.parsed_body["ai_personas"].find { |p| p["id"] == id } + it "returns localized persona names and descriptions" do + get "/admin/plugins/discourse-ai/ai_personas.json" - expect(persona["name"]).to eq(name) - expect(persona["description"]).to eq(description) + id = + DiscourseAi::AiBot::Personas::Persona.system_personas[ + DiscourseAi::AiBot::Personas::General + ] + persona = response.parsed_body["ai_personas"].find { |p| p["id"] == id } + + expect(persona["name"]).to eq("Général") + expect(persona["description"]).to eq("Général Description") + end end end