Skip to content

Commit

Permalink
Direct deposit swagger docs (#12345)
Browse files Browse the repository at this point in the history
* Add swagger docs and specs and update routes

* Fix failing specs for lighthouse direct deposit error_spec

* Fixed request body for updates
  • Loading branch information
tpharrison authored Apr 6, 2023
1 parent e04e1bd commit 5bfe017
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def show
end

def update
response = client.update payment_account_params
response = client.update_payment_information(payment_account_params)
if response.ok?
send_confirmation_email
render status: response.status,
json: response.body,
serializer: DisabilityCompensationsSerializer
Expand Down Expand Up @@ -57,6 +58,10 @@ def validate_payment_account
raise Common::Exceptions::ValidationErrors, payment_account
end
end

def send_confirmation_email
VANotifyDdEmailJob.send_to_emails(current_user.all_emails, :comp_and_pen)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/swagger/swagger/requests/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class Profile
end
end

response 201 do
response 200 do
key :description, 'Direct deposit information for a users compensation and pension benefits.'
schema do
key :type, :object
Expand Down
24 changes: 23 additions & 1 deletion lib/lighthouse/direct_deposit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,35 @@ def get_payment_information
parse_response(response)
end

def update(body)
def update_payment_information(params)
body = request_body(params)
save_sanitized_body(body)

response = config.put("?icn=#{@icn}", body)
parse_response(response)
end

private

def request_body(params)
params.delete('financial_institution_name') if params['financial_institution_name'].blank?
{
'paymentAccount' =>
{
'accountNumber' => params[:account_number],
'accountType' => params[:account_type],
'financialInstitutionRoutingNumber' => params[:routing_number]
}
}.to_json
end

def save_sanitized_body(body)
json = JSON.parse(body)
json['paymentAccount']['accountNumber'] = '****'

@sanitized_req_body = json
end

def valid_response?(response)
ok?(response) || control_info?(response)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@

describe '#update' do
context 'when successful' do
it 'returns a status of 201' do
it 'returns a status of 200' do
params = {
account_number: '1234567890',
account_type: 'CHECKING',
routing_number: '031000503'
}

VCR.use_cassette('lighthouse/direct_deposit/update/201_response') do
VCR.use_cassette('lighthouse/direct_deposit/update/200_response') do
put(:update, params:)
end

expect(response).to have_http_status(:created)
expect(response).to have_http_status(:ok)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2264,13 +2264,13 @@
end

context 'PUT' do
it 'returns a 201' do
it 'returns a 200' do
headers = { '_headers' => { 'Cookie' => sign_in(user, nil, true) } }
params = { account_number: '1234567890', account_type: 'CHECKING', routing_number: '031000503' }
VCR.use_cassette('lighthouse/direct_deposit/update/201_response') do
VCR.use_cassette('lighthouse/direct_deposit/update/200_response') do
expect(subject).to validate(:put,
'/v0/profile/direct_deposits/disability_compensations',
201,
200,
headers.merge('_data' => params))
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5bfe017

Please sign in to comment.