DEV: Defer topic view spec (#28052)

Followup e954eb234e

Adds a test for the defer_track_view method on topic controller
to check that the early returns (nexts) work correctly
without errors.
This commit is contained in:
Martin Brennan 2024-07-25 15:24:46 +10:00 committed by GitHub
parent 205a2bf0d6
commit 3838514d4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 48 additions and 0 deletions

View File

@ -5747,4 +5747,52 @@ RSpec.describe TopicsController do
end end
end end
end end
describe ".defer_topic_view" do
fab!(:topic)
fab!(:user)
before do
Jobs.run_immediately!
Scheduler::Defer.async = true
Scheduler::Defer.timeout = 0.1
end
after do
Scheduler::Defer.async = false
Scheduler::Defer.timeout = Scheduler::Deferrable::DEFAULT_TIMEOUT
end
it "does nothing if topic does not exist" do
topic.destroy!
expect {
TopicsController.defer_topic_view(topic.id, "1.2.3.4", user.id)
Scheduler::Defer.do_all_work
}.not_to change { TopicViewItem.count }
end
it "does nothing if user from ID does not exist" do
user.destroy!
expect {
TopicsController.defer_topic_view(topic.id, "1.2.3.4", user.id)
Scheduler::Defer.do_all_work
}.not_to change { TopicViewItem.count }
end
it "does nothing if user cannot see topic" do
topic.update!(category: Fabricate(:private_category, group: Fabricate(:group)))
expect {
TopicsController.defer_topic_view(topic.id, "1.2.3.4", user.id)
Scheduler::Defer.do_all_work
}.not_to change { TopicViewItem.count }
end
it "creates a topic view" do
expect {
TopicsController.defer_topic_view(topic.id, "1.2.3.4", user.id)
Scheduler::Defer.do_all_work
}.to change { TopicViewItem.count }
end
end
end end