discourse/spec/jobs/delete_replies_spec.rb
Martin Brennan 4af77f1e38
FEATURE: Allow durations < 1 hour and < 1 day for topic timers where duration is specified (auto delete replies, close based on last post) (#11961)
This PR allows entering a float value for topic timers e.g. 0.5 for 30 minutes when entering hours, 0.5 for 12 hours when entering days. This is achieved by adding a new column to store the duration of a topic timer in minutes instead of the ambiguous both hours and days that it could be before.

This PR has ommitted the post migration to delete the duration column in topic timers; it will be done in a subsequent PR to ensure that no data is lost if the UPDATE query to set duration_mintues fails.

I have to keep the old keyword of duration in set_or_create_topic_timer for backwards compat, will remove at a later date after plugins are updated.
2021-02-05 10:12:56 +10:00

42 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Jobs::DeleteReplies do
fab!(:admin) { Fabricate(:admin) }
fab!(:topic) { Fabricate(:topic) }
fab!(:topic_timer) do
Fabricate(:topic_timer, status_type: TopicTimer.types[:delete_replies], duration_minutes: 2880, user: admin, topic: topic, execute_at: 2.days.from_now)
end
before do
3.times { create_post(topic: topic) }
end
it "can delete replies of a topic" do
SiteSetting.skip_auto_delete_reply_likes = 0
freeze_time (2.days.from_now)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to change { topic.posts.count }.by(-2)
topic_timer.reload
expect(topic_timer.execute_at).to eq_time(2.day.from_now)
end
it "does not delete posts with likes over the threshold" do
SiteSetting.skip_auto_delete_reply_likes = 3
freeze_time (2.days.from_now)
topic.posts.last.update!(like_count: SiteSetting.skip_auto_delete_reply_likes + 1)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to change { topic.posts.count }.by(-1)
end
end