Skip to content

Commit

Permalink
97958 Debt team - connect digital disupte endpoint to model
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldrk committed Nov 28, 2024
1 parent 6deb4e8 commit 87433ad
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ class DigitalDisputesController < ApplicationController
service_tag 'financial-report'

def create
# Just returning data back for now while we wait on our integration partner
render json: digital_disputes_params
digital_dispute = V0::DigitalDispute.new(digital_disputes_params, current_user)
if digital_dispute.valid?
# Just returning data back for now while we wait on our integration partner
render json: digital_dispute.sanitized_json
else
render json: { errors: digital_dispute.errors }, status: :unprocessable_entity
end
end

private
Expand Down
4 changes: 4 additions & 0 deletions modules/debts_api/app/models/debts_api/v0/digital_dispute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def initialize(attributes, user)
self.attributes = attributes.to_h.merge(user_icn: user.icn)
end

def sanitized_json
as_json(except: [:user_icn])
end

private

def validate_contact_information
Expand Down
15 changes: 15 additions & 0 deletions modules/debts_api/spec/models/debt_api/v0/digital_dispute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@
end
end
end

describe '#sanitized_json' do
let(:user) { build(:user, :loa3) }
let(:raw_params) do
get_fixture_absolute('modules/debts_api/spec/fixtures/digital_disputes/standard_submission')
end

let(:params) { ActionController::Parameters.new(raw_params) }

it 'returns a sanitized json' do
digital_dispute = described_class.new(params.permit!.to_h, user)

expect(digital_dispute.sanitized_json).to eq(raw_params)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,52 @@
)

expect(response).to have_http_status(:ok)
expect(JSON.parse(response.body)).to eq(params)
end

context 'when invalid contact_information' do
let(:params) do
get_fixture_absolute('modules/debts_api/spec/fixtures/digital_disputes/standard_submission')
end

it 'returns an error when there is no contact information provided' do
params.delete('contact_information')

post(
'/debts_api/v0/digital_disputes',
params: params,
as: :json
)

expect(response).to have_http_status(:unprocessable_entity)
expect(JSON.parse(response.body)).to eq(
'errors' => {
'contact_information' => [
'is missing required information: email, phone_number, address_line1, city'
]
}
)
end

it 'returns an error when invalid email is submitted' do
params = get_fixture_absolute('modules/debts_api/spec/fixtures/digital_disputes/standard_submission')
params['contact_information']['email'] = 'invalid_email'

post(
'/debts_api/v0/digital_disputes',
params: params,
as: :json
)

expect(response).to have_http_status(:unprocessable_entity)
expect(JSON.parse(response.body)).to eq(
'errors' => {
'contact_information' => [
'must include a valid email address'
]
}
)
end
end
end
end

0 comments on commit 87433ad

Please sign in to comment.