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" }]])
end
it "returns localized persona names and descriptions" do
context "with translations" do
before do
SiteSetting.default_locale = "fr"
get "/admin/plugins/discourse-ai/ai_personas.json"
TranslationOverride.upsert!(:fr, "discourse_ai.ai_bot.personas.general.name", "Général")
TranslationOverride.upsert!(
:fr,
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
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
it "returns localized persona names and descriptions" do
get "/admin/plugins/discourse-ai/ai_personas.json"
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")
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(name)
expect(persona["description"]).to eq(description)
expect(persona["name"]).to eq("Général")
expect(persona["description"]).to eq("Général Description")
end
end
end