Skip to content

Commit

Permalink
Fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RachalCassity committed Apr 24, 2024
2 parents b5db4c0 + c06991e commit bd3a4fd
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def post_data(payload: {})

def handle_response_data(response)
if response[:Data].nil?
raise CorrespondencesCreatorError, response[:Message]
error = JSON.parse(response[:body], symbolize_names: true)
raise CorrespondencesCreatorError, error[:Message]
else
response[:Data]
end
Expand Down
3 changes: 2 additions & 1 deletion modules/ask_va_api/app/lib/ask_va_api/inquiries/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def post_data(payload: {})

def handle_response_data(response)
if response[:Data].nil?
raise InquiriesCreatorError, response[:Message]
error = JSON.parse(response[:body], symbolize_names: true)
raise InquiriesCreatorError, error[:Message]
else
response[:Data]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,23 @@ module Correspondences
end

context 'when not successful' do
let(:body) do
'{"Data":null,"Message":"Data Validation: Missing Reply"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: ' \
'Missing Reply","MessageId":"e2cbe041-df91-41f4-8bd2-8b6d9dbb2e38"}'
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_any_instance_of(Crm::Service).to receive(:call).and_return({ Data: nil, Message: 'Error has occur' })
allow_any_instance_of(Crm::Service).to receive(:call).and_return(failure)
end

it 'raise CorrespondenceCreatorError' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@
end

context 'when the API call fails' do
let(:body) do
'{"Data":null,"Message":"Data Validation: missing InquiryCategory"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: missing' \
'InquiryCategory","MessageId":"cb0dd954-ef25-4e56-b0d9-41925e5a190c"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end

before do
allow(service).to receive(:call).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
allow(service).to receive(:call).and_return(failure)
end

it 'raise InquiriesCreatorError' do
Expand Down
90 changes: 73 additions & 17 deletions modules/ask_va_api/spec/requests/v0/inquiries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,24 @@

context 'when crm api fail' do
context 'when the API call fails' do
let(:body) do
'{"Data":null,"Message":"Data Validation: missing InquiryCategory"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: missing' \
'InquiryCategory","MessageId":"cb0dd954-ef25-4e56-b0d9-41925e5a190c"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end

before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload:).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
payload:).and_return(failure)
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/auth', params: payload
end
Expand Down Expand Up @@ -404,14 +414,24 @@

context 'when crm api fail' do
context 'when the API call fails' do
let(:body) do
'{"Data":null,"Message":"Data Validation: missing InquiryCategory"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: missing' \
'InquiryCategory","MessageId":"cb0dd954-ef25-4e56-b0d9-41925e5a190c"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end

before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload:).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
payload:).and_return(failure)
post '/ask_va_api/v0/inquiries', params: payload
end

Expand Down Expand Up @@ -472,7 +492,7 @@ def json_response

describe 'POST #test_create' do
before do
allow_any_instance_of(Crm::Service).to receive(:call).and_return({ message: 'success' })
allow_any_instance_of(Crm::Service).to receive(:call).and_return({ body: { message: 'success' } })
post '/ask_va_api/v0/test_create',
params: { 'reply' => 'test', 'endpoint' => 'inquiries/id/reply/new' },
as: :json
Expand All @@ -486,14 +506,50 @@ def json_response
describe 'POST #create_reply' do
let(:payload) { { 'reply' => 'this is my reply' } }

before do
allow_any_instance_of(Crm::Service).to receive(:call).and_return({ Data: { Id: '123' } })
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/123/reply/new', params: payload
context 'when successful' do
before do
allow_any_instance_of(Crm::Service).to receive(:call).and_return({ Data: { Id: '123' } })
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/123/reply/new', params: payload
end

it 'returns status 200' do
expect(response).to have_http_status(:ok)
end
end

it 'returns status 200' do
expect(response).to have_http_status(:ok)
context 'when crm api fail' do
context 'when the API call fails' do
let(:endpoint) { 'inquiries/123/reply/new' }
let(:body) do
'{"Data":null,"Message":"Data Validation: Missing Reply"' \
',"ExceptionOccurred":true,"ExceptionMessage":"Data Validation: ' \
'Missing Reply","MessageId":"e2cbe041-df91-41f4-8bd2-8b6d9dbb2e38"}'
end
let(:failure) do
{
status: 400,
body:,
response_headers: nil,
url: nil
}
end

before do
sign_in(authorized_user)
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { Reply: 'this is my reply' }).and_return(failure)
post '/ask_va_api/v0/inquiries/123/reply/new', params: payload
end

it 'raise InquiriesCreatorError' do
expect(response).to have_http_status(:unprocessable_entity)
end

it_behaves_like 'common error handling', :unprocessable_entity, 'service_error',
'AskVAApi::Correspondences::CorrespondencesCreatorError: Data Validation: Missing Reply'
end
end
end
end

0 comments on commit bd3a4fd

Please sign in to comment.