Skip to content

Commit

Permalink
[Automated] Merged master into target preview_envs_k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 24, 2024
2 parents a9193d4 + 225805b commit 1c9f9ff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class InquiriesController < ApplicationController
around_action :handle_exceptions
before_action :get_inquiries_by_icn, only: [:index]
before_action :get_inquiry_by_id, only: [:show]
skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create]
skip_before_action :authenticate, only: %i[unauth_create upload_attachment test_create show]
skip_before_action :verify_authenticity_token, only: %i[unauth_create upload_attachment test_create]

def index
Expand Down Expand Up @@ -63,6 +63,8 @@ def create_reply
private

def get_inquiry_by_id
entity_class = AskVAApi::Inquiries::Entity
retriever = Inquiries::Retriever.new(user_mock_data: params[:mock], entity_class:)
inq = retriever.fetch_by_id(id: params[:id])
@inquiry = Result.new(payload: Inquiries::Serializer.new(inq).serializable_hash, status: :ok)
end
Expand Down
7 changes: 6 additions & 1 deletion modules/ask_va_api/app/lib/ask_va_api/inquiries/retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def filter_data(data, id = nil)
end

def handle_response_data(response)
response[:Data].presence || raise(InquiriesRetrieverError, response[:Message])
if response[:Data].nil?
error = JSON.parse(response[:body], symbolize_names: true)
raise InquiriesRetrieverError, error[:Message]
else
response[:Data]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@
describe '#call' do
context 'when Crm raise an error' do
let(:icn) { '123' }
let(:response) do
{ Data: nil,
Message: 'Data Validation: No Contact found by ICN',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: No Contact found by ICN',
MessageId: '2733ca25-7e64-4fbc-af2c-366f4bd2e3dc' }
let(:body) do
'{"Data":null,"Message":"Data Validation: No Inquiries found by ID A-20240423-30709"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: No Inquiries found by ' \
'ID A-20240423-30709","MessageId":"ca5b990a-63fe-407d-a364-46caffce12c1"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end

before do
allow_any_instance_of(Crm::CrmToken).to receive(:call).and_return('Token')
allow(service).to receive(:call).and_return(response)
allow(service).to receive(:call).and_return(failure)
end

it 'raise CorrespondenceRetrieverrError' do
Expand Down
30 changes: 14 additions & 16 deletions modules/ask_va_api/spec/requests/v0/inquiries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,25 @@
end

context 'when the id is invalid' do
let(:crm_response) do
{ Data: nil,
Message: 'Data Validation: No Inquiries found by ID A-20230305-30617',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: No Inquiries found by ID A-20230305-30617',
MessageId: 'e6024ccb-e19b-4bc6-990c-667e7ebab4ec' }
let(:body) do
'{"Data":null,"Message":"Data Validation: No Inquiries found by ID A-20240423-30709"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: No Inquiries found by ' \
'ID A-20240423-30709","MessageId":"ca5b990a-63fe-407d-a364-46caffce12c1"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end
let(:service) { instance_double(Crm::Service) }

before do
allow(Crm::Service).to receive(:new).and_return(service)
allow_any_instance_of(Crm::CrmToken).to receive(:call).and_return('Token')
allow(service).to receive(:call).and_return(crm_response)
allow(service).to receive(:call).and_return(failure)
sign_in(authorized_user)
get "#{inquiry_path}/#{invalid_id}"
end
Expand All @@ -228,17 +234,9 @@

it_behaves_like 'common error handling', :unprocessable_entity, 'service_error',
'AskVAApi::Inquiries::InquiriesRetrieverError: ' \
'Data Validation: No Inquiries found by ID A-20230305-30617'
'Data Validation: No Inquiries found by ID A-20240423-30709'
end
end

context 'when user is not signed in' do
before do
get "#{inquiry_path}/#{valid_id}"
end

it { expect(response).to have_http_status(:unauthorized) }
end
end

describe 'GET #download_attachment' do
Expand Down

0 comments on commit 1c9f9ff

Please sign in to comment.