diff --git a/spec/requests/whats_app/webhook_spec.rb b/spec/requests/whats_app/webhook_spec.rb index b965cd344..8cbfda1c1 100644 --- a/spec/requests/whats_app/webhook_spec.rb +++ b/spec/requests/whats_app/webhook_spec.rb @@ -258,21 +258,6 @@ describe 'given a known contributor' do let!(:contributor) { create(:contributor, whats_app_phone_number: whats_app_phone_number) } - let!(:request) do - create(:request, title: 'I failed to send', text: 'Hey {{FIRST_NAME}}, because it was sent outside the allowed window') - end - let(:valid_account_sid) { 'VALID_ACCOUNT_SID' } - let(:valid_api_key_sid) { 'VALID_API_KEY_SID' } - let(:valid_api_key_secret) { 'VALID_API_KEY_SECRET' } - let(:mock_twilio_rest_client) { instance_double(Twilio::REST::Client) } - let(:messages_double) { double(Twilio::REST::Api::V2010::AccountContext::MessageInstance, body: body_text) } - let(:body_text) { 'no message with this text saved' } - - before do - allow(Twilio::REST::Client).to receive(:new).and_return(mock_twilio_rest_client) - allow(mock_twilio_rest_client).to receive(:messages).with('someSid').and_return(messages_double) - allow(messages_double).to receive(:fetch).and_return(messages_double) - end describe 'given a failed message delivery' do it 'reports the error with the error message' do @@ -301,11 +286,23 @@ end context 'due to a freeform message not allowed error' do + let!(:request) do + create(:request, title: 'I failed to send', text: 'Hey {{FIRST_NAME}}, because it was sent outside the allowed window') + end + let(:valid_account_sid) { 'VALID_ACCOUNT_SID' } + let(:valid_api_key_sid) { 'VALID_API_KEY_SID' } + let(:valid_api_key_secret) { 'VALID_API_KEY_SECRET' } + let(:mock_twilio_rest_client) { instance_double(Twilio::REST::Client) } + let(:messages_double) { double(Twilio::REST::Api::V2010::AccountContext::MessageInstance, body: body_text) } + let(:body_text) { 'no message with this text saved' } let(:freeform_message_not_allowed_error_message) do 'Twilio Error: Failed to send freeform message because you are outside the allowed window.' end before do + allow(Twilio::REST::Client).to receive(:new).and_return(mock_twilio_rest_client) + allow(mock_twilio_rest_client).to receive(:messages).with('someSid').and_return(messages_double) + allow(messages_double).to receive(:fetch).and_return(messages_double) params['ErrorCode'] = '63016' params['ErrorMessage'] = freeform_message_not_allowed_error_message end