From 6f268f622b4415312761aa361829ea63c3afa2c2 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen <134089461+Khoa-V-Nguyen@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:26:47 -0600 Subject: [PATCH] Updated Retrievers (#16350) - Updated `Inquiries::Retriever` - Updated `Correspondences::Retriever` Co-authored-by: khoa-v-nguyen --- .../ask_va_api/correspondences/retriever.rb | 2 +- .../app/lib/ask_va_api/inquiries/retriever.rb | 3 +- .../correspondences/retriever_spec.rb | 50 +++++++++++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/modules/ask_va_api/app/lib/ask_va_api/correspondences/retriever.rb b/modules/ask_va_api/app/lib/ask_va_api/correspondences/retriever.rb index 9f152fbd90e..f62f4368663 100644 --- a/modules/ask_va_api/app/lib/ask_va_api/correspondences/retriever.rb +++ b/modules/ask_va_api/app/lib/ask_va_api/correspondences/retriever.rb @@ -22,7 +22,7 @@ def fetch_data data = JSON.parse(data, symbolize_names: true)[:Data] filter_data(data) else - endpoint = "inquiries/#{inquiry_id}/replies" + endpoint = "inquiry/#{inquiry_id}/replies" response = Crm::Service.new(icn: nil).call(endpoint:) handle_response_data(response) diff --git a/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb b/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb index eb2c9dd01b5..0951d724eb8 100644 --- a/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb +++ b/modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb @@ -29,7 +29,8 @@ def fetch_data(id = nil) filter_data(data, id) else endpoint = 'inquiries' - payload = id ? { id: } : { icn: } + id ||= icn + payload = { id: } response = Crm::Service.new(icn:).call(endpoint:, payload:) handle_response_data(response) diff --git a/modules/ask_va_api/spec/app/lib/ask_va_api/correspondences/retriever_spec.rb b/modules/ask_va_api/spec/app/lib/ask_va_api/correspondences/retriever_spec.rb index d66d4ff2219..3eed7120732 100644 --- a/modules/ask_va_api/spec/app/lib/ask_va_api/correspondences/retriever_spec.rb +++ b/modules/ask_va_api/spec/app/lib/ask_va_api/correspondences/retriever_spec.rb @@ -48,10 +48,54 @@ end context 'when successful' do - let(:user_mock_data) { true } + context 'with user_mock_data' do + let(:user_mock_data) { true } - it 'returns an array object with correct data' do - expect(retriever.call.first).to be_a(AskVAApi::Correspondences::Entity) + it 'returns an array object with correct data' do + expect(retriever.call.first).to be_a(AskVAApi::Correspondences::Entity) + end + end + + context 'with Crm::Service' do + let(:crm_response) do + { + Data: [ + { + Id: 'a5247de6-62c4-ee11-907a-001dd804eab2', + ModifiedOn: '2/5/2024 8:14:48 PM', + StatusReason: 'PendingSend', + Description: 'Dear aminul, Thank you for submitting ' \ + 'your Inquiry with the U.S.', + MessageType: 'Notification', + EnableReply: true, + AttachmentNames: nil + }, + { + Id: 'f4b12ee3-93bb-ed11-9886-001dd806a6a7', + ModifiedOn: '3/5/2023 8:25:49 PM', + StatusReason: 'Sent', + Description: 'Dear aminul, Thank you for submitting your ' \ + 'Inquiry with the U.S. Department of Veteran Affairs.', + MessageType: 'Notification', + EnableReply: true, + AttachmentNames: nil + } + ], + Message: nil, + ExceptionOccurred: false, + ExceptionMessage: nil, + MessageId: '086594d9-188b-46b0-9ce2-b8b36329506b' + } + end + + before do + allow_any_instance_of(Crm::CrmToken).to receive(:call).and_return('Token') + allow(service).to receive(:call).and_return(crm_response) + end + + it 'returns an array object with correct data' do + expect(retriever.call.first).to be_a(AskVAApi::Correspondences::Entity) + end end end end