feat: Add agent_reply_time_window in API channels (#4857)
This commit is contained in:
@@ -7,7 +7,7 @@ RSpec.describe Channel::TwilioSms do
|
||||
let!(:whatsapp_channel) { create(:channel_twilio_sms, medium: :whatsapp) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(whatsapp_channel.has_24_hour_messaging_window?).to eq true
|
||||
expect(whatsapp_channel.messaging_window_enabled?).to eq true
|
||||
expect(whatsapp_channel.name).to eq 'Whatsapp'
|
||||
expect(whatsapp_channel.medium).to eq 'whatsapp'
|
||||
end
|
||||
@@ -17,7 +17,7 @@ RSpec.describe Channel::TwilioSms do
|
||||
let!(:sms_channel) { create(:channel_twilio_sms, medium: :sms) }
|
||||
|
||||
it 'returns false' do
|
||||
expect(sms_channel.has_24_hour_messaging_window?).to eq false
|
||||
expect(sms_channel.messaging_window_enabled?).to eq false
|
||||
expect(sms_channel.name).to eq 'Twilio SMS'
|
||||
expect(sms_channel.medium).to eq 'sms'
|
||||
end
|
||||
|
||||
@@ -545,6 +545,54 @@ RSpec.describe Conversation, type: :model do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'on API channels' do
|
||||
let!(:api_channel) { create(:channel_api, additional_attributes: {}) }
|
||||
let!(:api_channel_with_limit) { create(:channel_api, additional_attributes: { agent_reply_time_window: '12' }) }
|
||||
|
||||
context 'when agent_reply_time_window is not configured' do
|
||||
it 'return true irrespective of the last message time' do
|
||||
conversation = create(:conversation, inbox: api_channel.inbox)
|
||||
create(
|
||||
:message,
|
||||
account: conversation.account,
|
||||
inbox: api_channel.inbox,
|
||||
conversation: conversation,
|
||||
created_at: Time.now - 13.hours
|
||||
)
|
||||
|
||||
expect(api_channel.additional_attributes['agent_reply_time_window']).to eq nil
|
||||
expect(conversation.can_reply?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when agent_reply_time_window is configured' do
|
||||
it 'return false if it is outside of agent_reply_time_window' do
|
||||
conversation = create(:conversation, inbox: api_channel_with_limit.inbox)
|
||||
create(
|
||||
:message,
|
||||
account: conversation.account,
|
||||
inbox: api_channel_with_limit.inbox,
|
||||
conversation: conversation,
|
||||
created_at: Time.now - 13.hours
|
||||
)
|
||||
|
||||
expect(api_channel_with_limit.additional_attributes['agent_reply_time_window']).to eq '12'
|
||||
expect(conversation.can_reply?).to eq false
|
||||
end
|
||||
|
||||
it 'return true if it is inside of agent_reply_time_window' do
|
||||
conversation = create(:conversation, inbox: api_channel_with_limit.inbox)
|
||||
create(
|
||||
:message,
|
||||
account: conversation.account,
|
||||
inbox: api_channel_with_limit.inbox,
|
||||
conversation: conversation
|
||||
)
|
||||
expect(conversation.can_reply?).to eq true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete conversation' do
|
||||
|
||||
Reference in New Issue
Block a user