|
88 | 88 | expect { job.execute({ post_id: post.id }) }.not_to raise_error |
89 | 89 | end |
90 | 90 |
|
91 | | - it "skips public content when `ai_translation_backfill_limit_to_public_content ` site setting is enabled" do |
92 | | - SiteSetting.ai_translation_backfill_limit_to_public_content = true |
93 | | - post.topic.category.update!(read_restricted: true) |
| 91 | + describe "with public content and PM limitations" do |
| 92 | + fab!(:private_category) { Fabricate(:private_category, group: Group[:staff]) } |
| 93 | + fab!(:private_topic) { Fabricate(:topic, category: private_category) } |
| 94 | + fab!(:private_post) { Fabricate(:post, topic: private_topic) } |
94 | 95 |
|
95 | | - DiscourseAi::Translation::PostLocaleDetector.expects(:detect_locale).with(post).never |
96 | | - DiscourseAi::Translation::PostLocalizer.expects(:localize).never |
| 96 | + fab!(:personal_pm_topic) { Fabricate(:private_message_topic) } |
| 97 | + fab!(:personal_pm_post) { Fabricate(:post, topic: personal_pm_topic) } |
97 | 98 |
|
98 | | - job.execute({ post_id: post.id }) |
| 99 | + fab!(:group_pm_topic) do |
| 100 | + Fabricate(:group_private_message_topic, recipient_group: Fabricate(:group)) |
| 101 | + end |
| 102 | + fab!(:group_pm_post) { Fabricate(:post, topic: group_pm_topic) } |
| 103 | + |
| 104 | + context "when ai_translation_backfill_limit_to_public_content is true" do |
| 105 | + before { SiteSetting.ai_translation_backfill_limit_to_public_content = true } |
| 106 | + |
| 107 | + it "skips posts from restricted categories and PMs" do |
| 108 | + DiscourseAi::Translation::PostLocaleDetector |
| 109 | + .expects(:detect_locale) |
| 110 | + .with(private_post) |
| 111 | + .never |
| 112 | + DiscourseAi::Translation::PostLocalizer |
| 113 | + .expects(:localize) |
| 114 | + .with(private_post, any_parameters) |
| 115 | + .never |
| 116 | + job.execute({ post_id: private_post.id }) |
| 117 | + |
| 118 | + DiscourseAi::Translation::PostLocaleDetector |
| 119 | + .expects(:detect_locale) |
| 120 | + .with(personal_pm_post) |
| 121 | + .never |
| 122 | + DiscourseAi::Translation::PostLocalizer |
| 123 | + .expects(:localize) |
| 124 | + .with(personal_pm_post, any_parameters) |
| 125 | + .never |
| 126 | + job.execute({ post_id: personal_pm_post.id }) |
| 127 | + |
| 128 | + DiscourseAi::Translation::PostLocaleDetector |
| 129 | + .expects(:detect_locale) |
| 130 | + .with(group_pm_post) |
| 131 | + .never |
| 132 | + DiscourseAi::Translation::PostLocalizer |
| 133 | + .expects(:localize) |
| 134 | + .with(group_pm_post, any_parameters) |
| 135 | + .never |
| 136 | + job.execute({ post_id: group_pm_post.id }) |
| 137 | + end |
| 138 | + end |
99 | 139 |
|
100 | | - pm_post = Fabricate(:post, topic: Fabricate(:private_message_topic)) |
101 | | - job.execute({ post_id: pm_post.id }) |
| 140 | + context "when ai_translation_backfill_limit_to_public_content is false" do |
| 141 | + before { SiteSetting.ai_translation_backfill_limit_to_public_content = false } |
| 142 | + |
| 143 | + it "processes posts from private categories and group PMs but skips personal PMs" do |
| 144 | + DiscourseAi::Translation::PostLocaleDetector.expects(:detect_locale).with(private_post).once |
| 145 | + job.execute({ post_id: private_post.id }) |
| 146 | + |
| 147 | + DiscourseAi::Translation::PostLocaleDetector |
| 148 | + .expects(:detect_locale) |
| 149 | + .with(group_pm_post) |
| 150 | + .once |
| 151 | + job.execute({ post_id: group_pm_post.id }) |
| 152 | + |
| 153 | + DiscourseAi::Translation::PostLocaleDetector |
| 154 | + .expects(:detect_locale) |
| 155 | + .with(personal_pm_post) |
| 156 | + .never |
| 157 | + DiscourseAi::Translation::PostLocalizer |
| 158 | + .expects(:localize) |
| 159 | + .with(personal_pm_post, any_parameters) |
| 160 | + .never |
| 161 | + job.execute({ post_id: personal_pm_post.id }) |
| 162 | + end |
| 163 | + end |
102 | 164 | end |
103 | 165 | end |
0 commit comments