DEV: Spec didn't work correctly with translations (#429)

This commit is contained in:
Gerhard Schlager 2024-01-16 16:28:24 +01:00 committed by GitHub
parent 14020e7095
commit 8eb1e851fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 16 deletions

View File

@ -58,26 +58,45 @@ RSpec.describe DiscourseAi::Admin::AiPersonasController do
expect(serializer_persona2["commands"]).to eq([["SearchCommand", { "base_query" => "test" }]]) expect(serializer_persona2["commands"]).to eq([["SearchCommand", { "base_query" => "test" }]])
end end
it "returns localized persona names and descriptions" do context "with translations" do
SiteSetting.default_locale = "fr" 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") after do
TranslationOverride.upsert!( TranslationOverride.revert!(
:fr, SiteSetting.default_locale,
"discourse_ai.ai_bot.personas.general.description", "discourse_ai.ai_bot.personas.general.name",
"Général Description", )
) TranslationOverride.revert!(
SiteSetting.default_locale,
"discourse_ai.ai_bot.personas.general.description",
)
end
id = it "returns localized persona names and descriptions" do
DiscourseAi::AiBot::Personas::Persona.system_personas[DiscourseAi::AiBot::Personas::General] get "/admin/plugins/discourse-ai/ai_personas.json"
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 }
expect(persona["name"]).to eq(name) id =
expect(persona["description"]).to eq(description) 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
end end