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
|
2024-08-12 18:40:23 -04:00
|
|
|
SiteSetting.ai_helper_enabled = true
|
|
|
|
SiteSetting.composer_ai_helper_allowed_groups = "10" # tl0
|
2024-04-26 08:28:35 -04:00
|
|
|
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
|
2024-08-08 16:37:26 -04:00
|
|
|
|
|
|
|
it "will include auto_image_caption field in the user_option if image caption is enabled" do
|
|
|
|
assign_fake_provider_to(:ai_helper_model)
|
|
|
|
assign_fake_provider_to(:ai_helper_image_caption_model)
|
2024-08-12 18:40:23 -04:00
|
|
|
SiteSetting.ai_helper_enabled = true
|
2024-08-08 16:37:26 -04:00
|
|
|
SiteSetting.ai_helper_enabled_features = "image_caption"
|
|
|
|
SiteSetting.ai_auto_image_caption_allowed_groups = "10" # tl0
|
|
|
|
serializer = CurrentUserSerializer.new(english_user, scope: Guardian.new(english_user))
|
|
|
|
|
|
|
|
expect(serializer.user_option.auto_image_caption).to eq(false)
|
|
|
|
end
|
2024-04-26 08:28:35 -04:00
|
|
|
end
|