Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

97958 Debt team - connect digital disupte endpoint to model #19658

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Loading