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