diff --git a/modules/mobile/app/models/mobile/v0/debt.rb b/modules/mobile/app/models/mobile/v0/debt.rb new file mode 100644 index 00000000000..bf25937eb4b --- /dev/null +++ b/modules/mobile/app/models/mobile/v0/debt.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'common/models/resource' + +module Mobile + module V0 + class Debt < Common::Resource + attribute :id, Types::String + attribute :file_number, Types::String + attribute :payee_number, Types::String + attribute :person_entitled, Types::String + attribute :deduction_code, Types::String + attribute :benefit_type, Types::String + attribute :diary_code, Types::String + attribute :diary_code_description, Types::String + attribute :amount_overpaid, Types::Float + attribute :amount_withheld, Types::Float + attribute :original_ar, Types::Float + attribute :current_ar, Types::Float + attribute :debt_history, Types::Array do + attribute :date, Types::Date + attribute :letter_code, Types::String + attribute :description, Types::String + end + end + end +end diff --git a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb index 493a1ec904b..3005c884406 100644 --- a/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb +++ b/modules/mobile/app/serializers/mobile/v0/debts_serializer.rb @@ -7,18 +7,19 @@ class DebtsSerializer set_type :debts - attributes :fileNumber, - :payeeNumber, - :personEntitled, - :deductionCode, - :benefitType, - :diaryCode, - :diaryCodeDescription, - :amountOverpaid, - :amountWithheld, - :originalAR, - :currentAR, - :debtHistory + attributes :file_number, + :payee_number, + :person_entitled, + :deduction_code, + :benefit_type, + :diary_code, + :diary_code_description, + :amount_overpaid, + :amount_withheld, + :original_ar, + :current_ar, + :debt_history + def initialize(debts, id = nil) resource = if debts.is_a? Array debts.map { |debt| serialize_debt(debt, id) } @@ -36,34 +37,28 @@ def dependent_debts?(debts) end def serialize_debt(debt, id = nil) - DebtStruct.new(id: id || debt['id'], - fileNumber: debt['fileNumber'], - payeeNumber: debt['payeeNumber'], - personEntitled: debt['personEntitled'], - deductionCode: debt['deductionCode'], - benefitType: debt['benefitType'], - diaryCode: debt['diaryCode'], - diaryCodeDescription: debt['diaryCodeDescription'], - amountOverpaid: debt['amountOverpaid'], - amountWithheld: debt['amountWithheld'], - originalAR: debt['originalAR'], - currentAR: debt['currentAR'], - debtHistory: debt['debtHistory']) + debt_history = Array.wrap(debt['debtHistory']).map do |history| + { + date: history['date'], + letter_code: history['letterCode'], + description: history['description'] + } + end + + Debt.new(id: id || debt['id'], + file_number: debt['fileNumber'], + payee_number: debt['payeeNumber'], + person_entitled: debt['personEntitled'], + deduction_code: debt['deductionCode'], + benefit_type: debt['benefitType'], + diary_code: debt['diaryCode'], + diary_code_description: debt['diaryCodeDescription'], + amount_overpaid: debt['amountOverpaid'], + amount_withheld: debt['amountWithheld'], + original_ar: debt['originalAR'], + current_ar: debt['currentAR'], + debt_history:) end end - - DebtStruct = Struct.new(:id, - :fileNumber, - :payeeNumber, - :personEntitled, - :deductionCode, - :benefitType, - :diaryCode, - :diaryCodeDescription, - :amountOverpaid, - :amountWithheld, - :originalAR, - :currentAR, - :debtHistory) end end diff --git a/modules/mobile/spec/requests/mobile/v0/debts_spec.rb b/modules/mobile/spec/requests/mobile/v0/debts_spec.rb index 5492ae25426..f168595b7bc 100644 --- a/modules/mobile/spec/requests/mobile/v0/debts_spec.rb +++ b/modules/mobile/spec/requests/mobile/v0/debts_spec.rb @@ -8,6 +8,136 @@ include JsonSchemaMatchers let!(:user) { sis_user } + let(:debt1) do + { 'type' => 'debts', + 'attributes' => + { 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '30', + 'benefitType' => 'Comp & Pen', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 123.34, + 'amountWithheld' => 50.0, + 'originalAr' => 1177.0, + 'currentAr' => 123.34, + 'debtHistory' => + [{ 'date' => '09/12/1998', 'letterCode' => '123', 'description' => + 'Third Demand Letter - Potential Treasury Referral' }, + { 'date' => '09/13/1997', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }, + { 'date' => '04/01/1997', 'letterCode' => '122', + 'description' => 'Referall To Credit Reporting Agencies (CRA)' }, + { 'date' => '09/14/1996', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }, + { 'date' => '09/16/1995', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }, + { 'date' => '04/04/1995', 'letterCode' => '145', + 'description' => + 'Referall To Credit Alert Interactive Verification Reporting System (CAIVRS) In 30 Days' }, + { 'date' => '02/14/1995', 'letterCode' => '117', + 'description' => 'Second Demand Letter - Potential Negative Referral' }, + { 'date' => '11/15/1994', 'letterCode' => '603', 'description' => 'Late Or Missed Payment Notification' }, + { 'date' => '09/10/1994', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }] } } + end + + let(:debt2) do + { + 'type' => 'debts', + 'attributes' => + { 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '30', + 'benefitType' => 'Comp & Pen', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 123.34, + 'amountWithheld' => 0.0, + 'originalAr' => 136.24, + 'currentAr' => 123.34, + 'debtHistory' => + [{ 'date' => '02/12/2009', + 'letterCode' => '487', + 'description' => 'Death Case Pending Action' }] } + } + end + + let(:debt3) do + { + 'type' => 'debts', + 'attributes' => { + 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '71', + 'benefitType' => 'CH33 Books, Supplies/MISC EDU', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 0.0, + 'amountWithheld' => 0.0, + 'originalAr' => 166.67, + 'currentAr' => 0.0, + 'debtHistory' => [] + } + } + end + + let(:debt4) do + { + 'type' => 'debts', + 'attributes' => + { + 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '74', + 'benefitType' => 'CH33 Student Tuition EDU', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 123.34, + 'amountWithheld' => 475.0, + 'originalAr' => 2210.9, + 'currentAr' => 123.34, + 'debtHistory' => + [{ 'date' => '04/01/2017', 'letterCode' => '608', 'description' => 'Full C&P Benefit Offset Notification' }, + { 'date' => '11/18/2015', 'letterCode' => '130', 'description' => 'Debt Increase - Due Process' }, + { 'date' => '04/08/2015', 'letterCode' => '608', 'description' => 'Full C&P Benefit Offset Notification' }, + { 'date' => '03/26/2015', 'letterCode' => '100', + 'description' => 'First Demand Letter - Inactive Benefits - Due Process' }] + } + } + end + + let(:debt5) do + { 'type' => 'debts', + 'attributes' => + { + 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '72', + 'benefitType' => 'CH33 Housing EDU', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 123.34, + 'amountWithheld' => 321.76, + 'originalAr' => 321.76, + 'currentAr' => 123.34, + 'debtHistory' => + [{ 'date' => '08/08/2018', 'letterCode' => '608', 'description' => 'Full C&P Benefit Offset Notification' }, + { 'date' => '07/19/2018', 'letterCode' => '100', + 'description' => 'First Demand Letter - Inactive Benefits - Due Process' }] + } } + end + + let(:meta) do + { + 'meta' => { 'hasDependentDebts' => false } + } + end describe 'GET /mobile/v0/debts' do context 'with a valid file number' do @@ -17,6 +147,12 @@ get '/mobile/v0/debts', headers: sis_headers expect(response).to have_http_status(:ok) expect(response.body).to match_json_schema('debts', strict: true) + debt_data = response.parsed_body['data'].map { |d| d.except('id') } + expect(debt_data).to include(debt1) + expect(debt_data).to include(debt2) + expect(debt_data).to include(debt3) + expect(debt_data).to include(debt4) + expect(debt_data).to include(debt5) end end end @@ -53,6 +189,26 @@ describe 'GET /mobile/v0/debts/:id' do let(:debt_id) { '2b41479f-2181-4016-9f77-3359c3ecee74' } + let(:debt) do + { + 'type' => 'debts', + 'attributes' => + { 'fileNumber' => '796043735', + 'payeeNumber' => '00', + 'personEntitled' => nil, + 'deductionCode' => '30', + 'benefitType' => 'Comp & Pen', + 'diaryCode' => '914', + 'diaryCodeDescription' => 'Paid In Full', + 'amountOverpaid' => 123.34, + 'amountWithheld' => 50.0, + 'originalAr' => 1177.0, + 'currentAr' => 123.34, + 'debtHistory' => + [{ 'date' => '09/12/1998', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }] } + } + end let(:load_debt_store) do debts = [{ 'fileNumber' => '796043735', @@ -67,8 +223,8 @@ 'originalAR' => 1177.0, 'currentAR' => 123.34, 'debtHistory' => - [{ 'date' => '09/12/1998', 'letterCode' => '123', - 'description' => 'Third Demand Letter - Potential Treasury Referral' }] }] + [{ 'date' => '09/12/1998', 'letterCode' => '123', + 'description' => 'Third Demand Letter - Potential Treasury Referral' }] }] debts[0]['id'] = debt_id debt_store = DebtManagementCenter::DebtStore.find_or_build(user.uuid) debt_store.update(debts:, uuid: user.uuid) @@ -83,6 +239,8 @@ expect(response).to have_http_status(:ok) expect(response.body).to match_json_schema('debt', strict: true) + debt_data = response.parsed_body['data'].except('id') + expect(debt_data).to include(debt) end end end