2019-05-13 10:37:49 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
require "rails_helper"
|
2017-06-30 11:10:11 +01:00
|
|
|
|
|
|
|
RSpec.describe PostCreator do
|
2018-06-08 08:57:43 +08:00
|
|
|
let(:topic) { Fabricate(:post).topic }
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
before { Jobs::NotifyChats.jobs.clear }
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
describe "when a post is created" do
|
|
|
|
describe "when plugin is enabled" do
|
|
|
|
before { SiteSetting.chat_integration_enabled = true }
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
it "should schedule a chat notification job" do
|
2019-06-24 14:08:04 +03:00
|
|
|
freeze_time Time.now.beginning_of_day
|
2017-08-01 20:53:39 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
post = PostCreator.new(topic.user, raw: "Some post content", topic_id: topic.id).create!
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2017-07-25 22:14:32 +01:00
|
|
|
job = Jobs::NotifyChats.jobs.last
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
expect(job["at"]).to eq(
|
|
|
|
Time.now.to_f + SiteSetting.chat_integration_delay_seconds.seconds.to_f,
|
|
|
|
)
|
2017-08-01 20:53:39 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
expect(job["args"].first["post_id"]).to eq(post.id)
|
2017-06-30 11:10:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
describe "when plugin is not enabled" do
|
|
|
|
before { SiteSetting.chat_integration_enabled = false }
|
2017-06-30 11:10:11 +01:00
|
|
|
|
2022-12-29 12:31:05 +00:00
|
|
|
it "should not schedule a job for chat notifications" do
|
|
|
|
PostCreator.new(topic.user, raw: "Some post content", topic_id: topic.id).create!
|
2017-06-30 11:10:11 +01:00
|
|
|
|
|
|
|
expect(Jobs::NotifyChats.jobs).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|