2025-05-29 17:28:06 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe Jobs::PostLocalizationBackfill do
|
|
|
|
before do
|
2025-06-21 15:45:09 +08:00
|
|
|
SiteSetting.ai_translation_backfill_hourly_rate = 100
|
2025-06-19 12:23:56 +08:00
|
|
|
SiteSetting.content_localization_supported_locales = "en"
|
2025-05-29 17:28:06 +08:00
|
|
|
Fabricate(:fake_model).tap do |fake_llm|
|
|
|
|
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
|
|
|
|
end
|
2025-06-21 15:45:09 +08:00
|
|
|
SiteSetting.ai_translation_enabled = true
|
|
|
|
SiteSetting.discourse_ai_enabled = true
|
2025-05-29 17:28:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not enqueue post translation when translator disabled" do
|
|
|
|
SiteSetting.discourse_ai_enabled = false
|
|
|
|
|
|
|
|
described_class.new.execute({})
|
|
|
|
|
|
|
|
expect_not_enqueued_with(job: :localize_posts)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not enqueue post translation when experimental translation disabled" do
|
|
|
|
SiteSetting.ai_translation_enabled = false
|
|
|
|
|
|
|
|
described_class.new.execute({})
|
|
|
|
|
|
|
|
expect_not_enqueued_with(job: :localize_posts)
|
|
|
|
end
|
|
|
|
|
2025-06-21 15:45:09 +08:00
|
|
|
it "does not enqueue post translation if backfill languages are not set" do
|
2025-06-19 12:23:56 +08:00
|
|
|
SiteSetting.content_localization_supported_locales = ""
|
2025-05-29 17:28:06 +08:00
|
|
|
|
|
|
|
described_class.new.execute({})
|
|
|
|
|
|
|
|
expect_not_enqueued_with(job: :localize_posts)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not enqueue post translation if backfill limit is set to 0" do
|
|
|
|
SiteSetting.discourse_ai_enabled = true
|
|
|
|
SiteSetting.ai_translation_enabled = true
|
2025-06-21 15:45:09 +08:00
|
|
|
SiteSetting.ai_translation_backfill_hourly_rate = 0
|
2025-05-29 17:28:06 +08:00
|
|
|
|
|
|
|
described_class.new.execute({})
|
|
|
|
|
|
|
|
expect_not_enqueued_with(job: :localize_posts)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "enqueues post translation with correct limit" do
|
|
|
|
SiteSetting.discourse_ai_enabled = true
|
|
|
|
SiteSetting.ai_translation_enabled = true
|
2025-06-21 15:45:09 +08:00
|
|
|
SiteSetting.ai_translation_backfill_hourly_rate = 100
|
2025-05-29 17:28:06 +08:00
|
|
|
|
|
|
|
described_class.new.execute({})
|
|
|
|
|
2025-06-21 15:45:09 +08:00
|
|
|
expect_job_enqueued(job: :localize_posts, args: { limit: 8 })
|
2025-05-29 17:28:06 +08:00
|
|
|
end
|
|
|
|
end
|