fix: Add a check for 24 hour window before sending a message (#1084)
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
parent
12ee7e5d82
commit
0f2d3418f9
26 changed files with 292 additions and 9 deletions
|
@ -315,6 +315,7 @@ RSpec.describe Conversation, type: :model do
|
|||
inbox_id: conversation.inbox_id,
|
||||
status: conversation.status,
|
||||
timestamp: conversation.created_at.to_i,
|
||||
can_reply: true,
|
||||
channel: 'Channel::WebWidget',
|
||||
user_last_seen_at: conversation.user_last_seen_at.to_i,
|
||||
agent_last_seen_at: conversation.agent_last_seen_at.to_i,
|
||||
|
@ -347,4 +348,45 @@ RSpec.describe Conversation, type: :model do
|
|||
expect(conversation.status).to eq('bot')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#can_reply?' do
|
||||
describe 'on channels without 24 hour restriction' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(conversation.can_reply?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'on channels with 24 hour restriction' do
|
||||
let!(:facebook_channel) { create(:channel_facebook_page) }
|
||||
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: facebook_channel.account) }
|
||||
let!(:conversation) { create(:conversation, inbox: facebook_inbox, account: facebook_channel.account) }
|
||||
|
||||
it 'returns false if there are no incoming messages' do
|
||||
expect(conversation.can_reply?).to eq false
|
||||
end
|
||||
|
||||
it 'return false if last incoming message is outside of 24 hour window' do
|
||||
create(
|
||||
:message,
|
||||
account: conversation.account,
|
||||
inbox: facebook_inbox,
|
||||
conversation: conversation,
|
||||
created_at: Time.now - 25.hours
|
||||
)
|
||||
expect(conversation.can_reply?).to eq false
|
||||
end
|
||||
|
||||
it 'return true if last incoming message is inside 24 hour window' do
|
||||
create(
|
||||
:message,
|
||||
account: conversation.account,
|
||||
inbox: facebook_inbox,
|
||||
conversation: conversation
|
||||
)
|
||||
expect(conversation.can_reply?).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue