2024-04-26 08:28:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe DiscourseAi::AiHelper::EntryPoint do
|
|
|
|
fab!(:english_user) { Fabricate(:user) }
|
|
|
|
fab!(:french_user) { Fabricate(:user, locale: "fr") }
|
|
|
|
|
|
|
|
it "will correctly localize available prompts" do
|
2024-06-19 17:01:35 -04:00
|
|
|
assign_fake_provider_to(:ai_helper_model)
|
2024-04-26 08:28:35 -04:00
|
|
|
SiteSetting.default_locale = "en"
|
|
|
|
SiteSetting.allow_user_locale = true
|
|
|
|
SiteSetting.composer_ai_helper_enabled = true
|
|
|
|
SiteSetting.ai_helper_allowed_groups = "10" # tl0
|
|
|
|
DiscourseAi::AiHelper::Assistant.clear_prompt_cache!
|
|
|
|
|
|
|
|
Group.refresh_automatic_groups!
|
|
|
|
|
|
|
|
serializer = CurrentUserSerializer.new(english_user, scope: Guardian.new(english_user))
|
|
|
|
parsed = JSON.parse(serializer.to_json)
|
|
|
|
|
|
|
|
translate_prompt =
|
|
|
|
parsed["current_user"]["ai_helper_prompts"].find { |prompt| prompt["name"] == "translate" }
|
|
|
|
|
|
|
|
expect(translate_prompt["translated_name"]).to eq(
|
2024-07-04 11:23:37 -04:00
|
|
|
I18n.t("discourse_ai.ai_helper.prompts.translate", language: "English (US)"),
|
2024-04-26 08:28:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
I18n.with_locale("fr") do
|
|
|
|
serializer = CurrentUserSerializer.new(french_user, scope: Guardian.new(french_user))
|
|
|
|
parsed = JSON.parse(serializer.to_json)
|
|
|
|
|
|
|
|
translate_prompt =
|
|
|
|
parsed["current_user"]["ai_helper_prompts"].find { |prompt| prompt["name"] == "translate" }
|
|
|
|
|
|
|
|
expect(translate_prompt["translated_name"]).to eq(
|
2024-07-04 11:23:37 -04:00
|
|
|
I18n.t("discourse_ai.ai_helper.prompts.translate", locale: "fr", language: "Français"),
|
2024-04-26 08:28:35 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|