2020-11-02 01:48:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::CreateLinkedTopic do
|
2020-11-02 01:48:48 -05:00
|
|
|
it "returns when the post cannot be found" do
|
2023-01-10 00:41:25 -05:00
|
|
|
expect { Jobs::CreateLinkedTopic.new.execute(post_id: 1) }.not_to raise_error
|
2020-11-02 01:48:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with a post" do
|
2020-11-10 14:14:27 -05:00
|
|
|
fab!(:category) { Fabricate(:category) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, category: category) }
|
2020-11-02 01:48:48 -05:00
|
|
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
|
|
fab!(:user_2) { Fabricate(:user) }
|
|
|
|
|
|
|
|
let :watching do
|
|
|
|
TopicUser.notification_levels[:watching]
|
|
|
|
end
|
|
|
|
|
|
|
|
let :tracking do
|
|
|
|
TopicUser.notification_levels[:tracking]
|
|
|
|
end
|
|
|
|
|
|
|
|
let :muted do
|
|
|
|
TopicUser.notification_levels[:muted]
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.auto_close_topics_create_linked_topic = true
|
|
|
|
Fabricate(:topic_user, notification_level: tracking, topic: topic, user: user_1)
|
|
|
|
Fabricate(:topic_user, notification_level: muted, topic: topic, user: user_2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a linked topic" do
|
2020-11-05 12:09:21 -05:00
|
|
|
small_action_post =
|
|
|
|
Fabricate(
|
|
|
|
:post,
|
|
|
|
topic: topic,
|
|
|
|
post_type: Post.types[:small_action],
|
|
|
|
action_code: "closed.enabled",
|
|
|
|
)
|
2020-11-02 01:48:48 -05:00
|
|
|
Jobs::CreateLinkedTopic.new.execute(post_id: post.id)
|
|
|
|
|
|
|
|
raw_title = topic.title
|
|
|
|
topic.reload
|
|
|
|
new_topic = Topic.last
|
|
|
|
linked_topic = new_topic.linked_topic
|
|
|
|
expect(topic.title).to include(
|
|
|
|
I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: raw_title, count: 1),
|
|
|
|
)
|
2020-11-05 12:09:21 -05:00
|
|
|
expect(topic.posts.last.raw).to include(
|
|
|
|
I18n.t(
|
|
|
|
"create_linked_topic.small_action_post_raw",
|
|
|
|
new_title: "[#{new_topic.title}](#{new_topic.url})",
|
2023-01-09 06:18:21 -05:00
|
|
|
),
|
2020-11-02 01:48:48 -05:00
|
|
|
)
|
|
|
|
expect(new_topic.title).to include(
|
|
|
|
I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: raw_title, count: 2),
|
2023-01-09 06:18:21 -05:00
|
|
|
)
|
2020-11-02 01:48:48 -05:00
|
|
|
expect(new_topic.first_post.raw).to include(topic.url)
|
2020-11-10 14:14:27 -05:00
|
|
|
expect(new_topic.category.id).to eq(category.id)
|
2020-11-02 01:48:48 -05:00
|
|
|
expect(new_topic.topic_users.count).to eq(3)
|
|
|
|
expect(new_topic.topic_users.pluck(:notification_level)).to contain_exactly(
|
|
|
|
muted,
|
|
|
|
tracking,
|
|
|
|
watching,
|
|
|
|
)
|
|
|
|
expect(linked_topic.topic_id).to eq(new_topic.id)
|
|
|
|
expect(linked_topic.original_topic_id).to eq(topic.id)
|
|
|
|
expect(linked_topic.sequence).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|