From 646746aa108ce90127367c2c439ef25b98ec68c9 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 17 Sep 2020 23:32:19 +0530 Subject: [PATCH] fix: Check medium to decide 24 hour window (#1245) --- app/models/channel/twilio_sms.rb | 4 ++-- spec/models/channel/twilio_sms_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 spec/models/channel/twilio_sms_spec.rb diff --git a/app/models/channel/twilio_sms.rb b/app/models/channel/twilio_sms.rb index 3174409f9..8f25fec2e 100644 --- a/app/models/channel/twilio_sms.rb +++ b/app/models/channel/twilio_sms.rb @@ -31,10 +31,10 @@ class Channel::TwilioSms < ApplicationRecord has_one :inbox, as: :channel, dependent: :destroy def name - medium == :sms ? 'Twilio SMS' : 'Whatsapp' + medium == 'sms' ? 'Twilio SMS' : 'Whatsapp' end def has_24_hour_messaging_window? - true + medium == 'whatsapp' end end diff --git a/spec/models/channel/twilio_sms_spec.rb b/spec/models/channel/twilio_sms_spec.rb new file mode 100644 index 000000000..8aab34a7a --- /dev/null +++ b/spec/models/channel/twilio_sms_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Channel::TwilioSms do + context 'with medium whatsapp' 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.name).to eq 'Whatsapp' + expect(whatsapp_channel.medium).to eq 'whatsapp' + end + end + + context 'with medium sms' 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.name).to eq 'Twilio SMS' + expect(sms_channel.medium).to eq 'sms' + end + end +end