2021-06-24 05:35:36 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
|
RSpec.describe Jobs::RemoveBanner do
|
2023-11-09 17:47:59 -05:00
|
|
|
|
fab!(:topic)
|
2021-06-24 05:35:36 -04:00
|
|
|
|
fab!(:user) { topic.user }
|
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
|
context "when topic is not bannered until" do
|
2021-06-24 05:35:36 -04:00
|
|
|
|
it "doesn’t enqueue a future job to remove it" do
|
2022-07-19 10:03:03 -04:00
|
|
|
|
expect do topic.make_banner!(user) end.not_to change { Jobs::RemoveBanner.jobs.size }
|
2021-06-24 05:35:36 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
|
context "when topic is bannered until" do
|
|
|
|
|
context "when bannered_until is a valid date" do
|
2021-06-24 05:35:36 -04:00
|
|
|
|
it "enqueues a future job to remove it" do
|
|
|
|
|
bannered_until = 5.days.from_now
|
|
|
|
|
|
|
|
|
|
expect(topic.archetype).to eq(Archetype.default)
|
|
|
|
|
|
|
|
|
|
expect do topic.make_banner!(user, bannered_until.to_s) end.to change {
|
|
|
|
|
Jobs::RemoveBanner.jobs.size
|
|
|
|
|
}.by(1)
|
|
|
|
|
|
|
|
|
|
topic.reload
|
|
|
|
|
expect(topic.archetype).to eq(Archetype.banner)
|
|
|
|
|
|
|
|
|
|
job = Jobs::RemoveBanner.jobs[0]
|
|
|
|
|
expect(Time.at(job["at"])).to be_within_one_minute_of(bannered_until)
|
|
|
|
|
expect(job["args"][0]["topic_id"]).to eq(topic.id)
|
|
|
|
|
|
|
|
|
|
job["class"].constantize.new.perform(*job["args"])
|
|
|
|
|
topic.reload
|
|
|
|
|
expect(topic.archetype).to eq(Archetype.default)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
|
context "when bannered_until is an invalid date" do
|
2021-06-24 05:35:36 -04:00
|
|
|
|
it "doesn’t enqueue a future job to remove it" do
|
|
|
|
|
expect do
|
|
|
|
|
expect do topic.make_banner!(user, "xxx") end.to raise_error(Discourse::InvalidParameters)
|
2022-07-19 10:03:03 -04:00
|
|
|
|
end.not_to change { Jobs::RemoveBanner.jobs.size }
|
2021-06-24 05:35:36 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|