Skip to content

Commit

Permalink
Update Inquiries::Creator and InquiriesController (#16466)
Browse files Browse the repository at this point in the history
- Updated `inquiry_params`
- Fix argumet in `Inquiries::Creator`

Co-authored-by: khoa-v-nguyen <khoa.nguyen@oddball.io>
  • Loading branch information
Khoa-V-Nguyen and khoa-v-nguyen committed Apr 23, 2024
1 parent 373a339 commit 116d8c7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
Expand Up @@ -26,12 +26,12 @@ def test_create
end

def create
response = Inquiries::Creator.new(icn: current_user.icn).call(params: inquiry_params)
response = Inquiries::Creator.new(icn: current_user.icn).call(payload: inquiry_params)
render json: response.to_json, status: :created
end

def unauth_create
response = Inquiries::Creator.new(icn: nil).call(params: inquiry_params)
response = Inquiries::Creator.new(icn: nil).call(payload: inquiry_params)
render json: response.to_json, status: :created
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def inquiry_params
*dependant_parameters,
*submitter_parameters,
*veteran_parameters,
school_obj: school_parameters
SchoolObj: school_parameters
).to_h
end

Expand All @@ -112,7 +112,7 @@ def base_parameters
InquiryCategory InquirySource InquirySubtopic InquirySummary InquiryTopic
InquiryType IsVAEmployee IsVeteran IsVeteranAnEmployee IsVeteranDeceased
LevelOfAuthentication MedicalCenter MiddleName PreferredName Pronouns
StreetAddress2 SupervisorFlag VaEmployeeTimeStamp ZipCode
StreetAddress2 SupervisorFlag VaEmployeeTimeStamp ZipCode Suffix
]
end

Expand All @@ -130,7 +130,7 @@ def submitter_parameters
Submitter SubmitterDependent SubmitterDOB SubmitterGender SubmitterProvince
SubmitterSSN SubmitterState SubmitterStateOfResidency SubmitterStateOfSchool
SubmitterStateProperty SubmitterStreetAddress SubmitterVetCenter
SubmitterZipCodeOfResidency SubmitterQuestion
SubmitterZipCodeOfResidency SubmitterQuestion SubmittersDodIdEdipiNumber
]
end

Expand All @@ -143,7 +143,7 @@ def veteran_parameters
VeteranRelationship VeteranServiceEndDate VeteranServiceNumber
VeteranServiceStartDate VeteranSSN VeteransState VeteranStreetAddress
VeteranSuffix VeteranSuiteAptOther VeteranZipCode WhoWasTheirCounselor
YourLastName
YourLastName VeteranDodIdEdipiNumber
]
end

Expand Down
4 changes: 2 additions & 2 deletions modules/ask_va_api/app/lib/ask_va_api/inquiries/creator.rb
Expand Up @@ -13,8 +13,8 @@ def initialize(icn:, service: nil)
@service = service || default_service
end

def call(params:)
post_data(payload: { params: })
def call(payload:)
post_data(payload:)
rescue => e
ErrorHandler.handle_service_error(e)
end
Expand Down
Expand Up @@ -6,7 +6,7 @@
let(:icn) { '123456' }
let(:service) { instance_double(Crm::Service) }
let(:creator) { described_class.new(icn:, service:) }
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

before do
Expand All @@ -17,21 +17,21 @@
context 'when the API call is successful' do
before do
allow(service).to receive(:call).with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
InquiryNumber: '530d56a8-affd-ee11' \
'-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5' \
'-aff0-99503e50ee27'
})
payload:).and_return({
Data: {
InquiryNumber: '530d56a8-affd-ee11' \
'-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5' \
'-aff0-99503e50ee27'
})
end

it 'posts data to the service and returns the response' do
expect(creator.call(params:)).to eq({ InquiryNumber: '530d56a8-affd-ee11-a1fe-001dd8094ff1' })
expect(creator.call(payload:)).to eq({ InquiryNumber: '530d56a8-affd-ee11-a1fe-001dd8094ff1' })
end
end

Expand All @@ -45,7 +45,7 @@
end

it 'raise InquiriesCreatorError' do
expect { creator.call(params:) }.to raise_error(ErrorHandler::ServiceError)
expect { creator.call(payload:) }.to raise_error(ErrorHandler::ServiceError)
end
end
end
Expand Down
68 changes: 34 additions & 34 deletions modules/ask_va_api/spec/requests/v0/inquiries_spec.rb
Expand Up @@ -332,24 +332,24 @@
end

describe 'POST #create' do
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

context 'when successful' do
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
payload:).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/auth', params:
post '/ask_va_api/v0/inquiries/auth', params: payload
end

it { expect(response).to have_http_status(:created) }
Expand All @@ -360,13 +360,13 @@
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).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({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
sign_in(authorized_user)
post '/ask_va_api/v0/inquiries/auth', params:
post '/ask_va_api/v0/inquiries/auth', params: payload
end

it 'raise InquiriesCreatorError' do
Expand All @@ -380,23 +380,23 @@
end

describe 'POST #unauth_create' do
let(:params) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:payload) { { FirstName: 'Fake', YourLastName: 'Smith' } }
let(:endpoint) { AskVAApi::Inquiries::Creator::ENDPOINT }

context 'when successful' do
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
post inquiry_path, params:
payload:).and_return({
Data: {
Id: '530d56a8-affd-ee11-a1fe-001dd8094ff1'
},
Message: '',
ExceptionOccurred: false,
ExceptionMessage: '',
MessageId: 'b8ebd8e7-3bbf-49c5-aff0-99503e50ee27'
})
post inquiry_path, params: payload
end

it { expect(response).to have_http_status(:created) }
Expand All @@ -407,12 +407,12 @@
before do
allow_any_instance_of(Crm::Service).to receive(:call)
.with(endpoint:, method: :put,
payload: { params: }).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
post '/ask_va_api/v0/inquiries', params:
payload:).and_return({ Data: nil,
Message: 'Data Validation: missing InquiryCategory',
ExceptionOccurred: true,
ExceptionMessage: 'Data Validation: missing InquiryCategory',
MessageId: '13bc59ea-c90a-4d48-8979-fe71e0f7ddeb' })
post '/ask_va_api/v0/inquiries', params: payload
end

it 'raise InquiriesCreatorError' do
Expand Down

0 comments on commit 116d8c7

Please sign in to comment.