From d49989ace1b7031ca29319002af15c4bebe8e5d3 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Mon, 10 Apr 2023 20:44:43 +0530 Subject: [PATCH] chore: Specs for Whatsapp template pagination (#6870) Spec for https://github.com/chatwoot/chatwoot/pull/6835 --- .../providers/whatsapp_cloud_service_spec.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb index ce0c7ae34..69527487e 100644 --- a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb @@ -112,9 +112,20 @@ describe Whatsapp::Providers::WhatsappCloudService do context 'when called' do it 'updated the message templates' do stub_request(:get, 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key') - .to_return(status: 200, headers: response_headers, body: { data: [{ id: '123456789', name: 'test_template' }] }.to_json) + .to_return( + { status: 200, headers: response_headers, + body: { data: [ + { id: '123456789', name: 'test_template' } + ], paging: { next: 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key' } }.to_json }, + { status: 200, headers: response_headers, + body: { data: [ + { id: '123456789', name: 'next_template' } + ], paging: { prev: 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key' } }.to_json } + ) + expect(subject.sync_templates).to be(true) - expect(whatsapp_channel.reload.message_templates).to eq([{ id: '123456789', name: 'test_template' }.stringify_keys]) + expect(whatsapp_channel.reload.message_templates.first).to eq({ id: '123456789', name: 'test_template' }.stringify_keys) + expect(whatsapp_channel.reload.message_templates.last).to eq([{ id: '123456789', name: 'next_template' }.stringify_keys]) end end end