mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 10:43:44 +08:00
6d72c8ab19
This PR revamps the topic timer UI, using the time shortcut selector from the bookmark modal. * Fixes an issue where the duration of hours/days after last reply or auto delete replies was not enforced to be > 0 * Fixed an issue where the timer dropdown options were not reloaded correctly if the topic status changes in the background (use `MessageBus` to publish topic state in the open/close timer jobs) * Moved the duration input and the "based on last post" option from the `future-date-input` component, as it was only used for topic timers. Also moved out the notice that is displayed which was also only relevant for topic timers.
108 lines
3.0 KiB
Ruby
108 lines
3.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe Jobs::OpenTopic do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:topic) do
|
|
Fabricate(:topic_timer, user: admin).topic
|
|
end
|
|
|
|
before do
|
|
topic.update!(closed: true)
|
|
end
|
|
|
|
it 'should work' do
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
|
|
expect(topic.reload.open?).to eq(true)
|
|
|
|
expect(Post.last.raw).to eq(I18n.t(
|
|
'topic_statuses.autoclosed_disabled_minutes', count: 61
|
|
))
|
|
end
|
|
end
|
|
|
|
it "publishes to the topic message bus so the topic status reloads" do
|
|
MessageBus.expects(:publish).at_least_once
|
|
MessageBus.expects(:publish).with("/topic/#{topic.id}", reload_topic: true).once
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
end
|
|
end
|
|
|
|
describe 'when category has auto close configured' do
|
|
fab!(:category) do
|
|
Fabricate(:category,
|
|
auto_close_based_on_last_post: true,
|
|
auto_close_hours: 5
|
|
)
|
|
end
|
|
|
|
fab!(:topic) { Fabricate(:topic, category: category, closed: true) }
|
|
|
|
it "should restore the category's auto close timer" do
|
|
Fabricate(:topic_timer,
|
|
status_type: TopicTimer.types[:open],
|
|
topic: topic,
|
|
user: admin
|
|
)
|
|
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
|
|
expect(topic.reload.open?).to eq(true)
|
|
|
|
topic_timer = topic.public_topic_timer
|
|
|
|
expect(topic_timer.status_type).to eq(TopicTimer.types[:close])
|
|
expect(topic_timer.execute_at).to eq_time(5.hours.from_now)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'when user is no longer authorized to open topics' do
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) do
|
|
Fabricate(:topic_timer, user: user).topic
|
|
end
|
|
|
|
it 'should destroy the topic timer' do
|
|
topic.update!(closed: true)
|
|
freeze_time(topic.public_topic_timer.execute_at + 1.minute)
|
|
|
|
expect do
|
|
described_class.new.execute(topic_timer_id: topic.public_topic_timer.id)
|
|
end.to change { TopicTimer.exists?(topic_id: topic.id) }.from(true).to(false)
|
|
|
|
expect(topic.reload.open?).to eq(false)
|
|
end
|
|
|
|
it "should reconfigure topic timer if category's topics are set to autoclose" do
|
|
category = Fabricate(:category,
|
|
auto_close_based_on_last_post: true,
|
|
auto_close_hours: 5
|
|
)
|
|
|
|
topic = Fabricate(:topic, category: category)
|
|
topic.public_topic_timer.update!(user: user)
|
|
topic.reload
|
|
|
|
freeze_time(topic.public_topic_timer.execute_at + 1.minute)
|
|
|
|
expect do
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: true
|
|
)
|
|
end.to change { topic.reload.public_topic_timer.user }.from(user).to(Discourse.system_user)
|
|
.and change { topic.public_topic_timer.id }
|
|
|
|
expect(topic.reload.closed).to eq(false)
|
|
end
|
|
end
|
|
end
|