2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe UserArchivedMessage do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user)
|
2021-08-25 11:17:56 +08:00
|
|
|
fab!(:user_2) { Fabricate(:user) }
|
2016-02-15 07:56:39 +08:00
|
|
|
|
2021-08-25 11:17:56 +08:00
|
|
|
fab!(:private_message) do
|
|
|
|
create_post(
|
|
|
|
user: user,
|
|
|
|
skip_validations: true,
|
|
|
|
target_usernames: [user_2.username, user.username].join(","),
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
).topic
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".move_to_inbox!" do
|
|
|
|
it "moves topic back to inbox correctly" do
|
|
|
|
UserArchivedMessage.archive!(user.id, private_message)
|
|
|
|
|
2021-09-10 09:20:50 +08:00
|
|
|
expect do UserArchivedMessage.move_to_inbox!(user.id, private_message) end.to change {
|
2021-08-25 11:17:56 +08:00
|
|
|
private_message.message_archived?(user)
|
|
|
|
}.from(true).to(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not move archived muted messages back to inbox" do
|
|
|
|
UserArchivedMessage.archive!(user.id, private_message)
|
2016-02-15 07:56:39 +08:00
|
|
|
|
2021-08-25 11:17:56 +08:00
|
|
|
expect(private_message.message_archived?(user)).to eq(true)
|
2016-02-15 07:56:39 +08:00
|
|
|
|
2021-08-25 11:17:56 +08:00
|
|
|
TopicUser.change(
|
|
|
|
user.id,
|
|
|
|
private_message.id,
|
|
|
|
notification_level: TopicUser.notification_levels[:muted],
|
|
|
|
)
|
|
|
|
UserArchivedMessage.move_to_inbox!(user.id, private_message)
|
|
|
|
|
|
|
|
expect(private_message.message_archived?(user)).to eq(true)
|
|
|
|
end
|
2016-02-15 07:56:39 +08:00
|
|
|
end
|
|
|
|
end
|