mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 06:13:44 +08:00
0a5f548635
As part of this move, we are also renaming `discourse-chat` to `chat`.
41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe Jobs::ChatChannelArchive do
|
|
fab!(:chat_channel) { Fabricate(:category_channel) }
|
|
fab!(:user) { Fabricate(:user, admin: true) }
|
|
fab!(:category) { Fabricate(:category) }
|
|
fab!(:chat_archive) do
|
|
ChatChannelArchive.create!(
|
|
chat_channel: chat_channel,
|
|
archived_by: user,
|
|
destination_topic_title: "This will be the archive topic",
|
|
destination_category_id: category.id,
|
|
total_messages: 10,
|
|
)
|
|
end
|
|
|
|
before { 10.times { Fabricate(:chat_message, chat_channel: chat_channel) } }
|
|
|
|
def run_job
|
|
described_class.new.execute(chat_channel_archive_id: chat_archive.id)
|
|
end
|
|
|
|
it "does nothing if the archive is already complete" do
|
|
chat_channel.chat_messages.destroy_all
|
|
chat_archive.update!(archived_messages: 10)
|
|
expect { run_job }.not_to change { Topic.count }
|
|
end
|
|
|
|
it "does nothing if the archive does not exist" do
|
|
chat_archive.destroy
|
|
expect { run_job }.not_to change { Topic.count }
|
|
end
|
|
|
|
it "processes the archive" do
|
|
Chat::ChatChannelArchiveService.any_instance.expects(:execute)
|
|
run_job
|
|
end
|
|
end
|