Skip to content

Commit

Permalink
Remove metadata from API exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mo Seedat committed Oct 24, 2024
1 parent 08d86cd commit eebfde5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 86 deletions.
1 change: 0 additions & 1 deletion app/api/datastore/entities/v1/maat/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Payment < Grape::Entity

expose :amount
expose :frequency
expose :metadata
expose :payment_type
expose :ownership_type
expose :metadata_details, as: :details, if: ->(instance) { instance.dig('metadata', 'details') }
Expand Down
5 changes: 5 additions & 0 deletions app/services/utils/maat/other_income_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def other_payment?(ownership_type)
end
end

# rubocop:disable Metrics/AbcSize
def update_other_payment(ownership_type)
other_payment = payments.find { |p| p['ownership_type'] == ownership_type && p['payment_type'] == OTHER }
return unless other_payment
Expand All @@ -45,11 +46,15 @@ def update_other_payment(ownership_type)

other_payment['amount'] = total_other_payments_by_ownership(ownership_type)
other_payment['frequency'] = Utils::AnnualizedAmountCalculator::PAYMENT_FREQUENCY_TYPE[:annual]

return unless other_payment.key?('metadata')

other_payment['metadata']['details'] = [
income_payment_notes,
other_payment['metadata']['details']
].compact.join("\n")
end
# rubocop:enable Metrics/AbcSize

def create_other_payment(ownership_type)
payments.push(
Expand Down
108 changes: 23 additions & 85 deletions spec/api/datastore/entities/v1/maat/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -481,43 +481,34 @@
expect(income_payments).to contain_exactly(
{
'payment_type' => 'state_pension',
'amount' => 10_000,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
'amount' => 10_000,
'frequency' => 'week',
'ownership_type' => 'applicant',
},
{
'payment_type' => 'maintenance',
'amount' => 30_000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
'amount' => 30_000,
'frequency' => 'month',
'ownership_type' => 'applicant',
},
{
'payment_type' => 'maintenance',
'amount' => 15_000,
'frequency' => 'month',
'ownership_type' => 'partner',
'metadata' => {}
},
{
'payment_type' => 'other',
'amount' => 145_000, # other(10_000 * 12) + student_loan_grant(25_000)
'frequency' => 'annual',
'ownership_type' => 'partner',
'metadata' => {
'details' => "Partner: Student loan grant:£250.00/annual, Other:£100.00/month\nDetails of the other partner payment",
},
'details' => "Partner: Student loan grant:£250.00/annual, Other:£100.00/month\nDetails of the other partner payment",
},
{
'payment_type' => 'other',
'amount' => 603_000, # other(250 * 12) + student_loan_grant(50_000 * 12)
'frequency' => 'annual',
'ownership_type' => 'applicant',
'metadata' => {
'details' => "Applicant: Student loan grant:£500.00/month, Other:£2.50/month\nDetails of the other payment",
},
'details' => "Applicant: Student loan grant:£500.00/month, Other:£2.50/month\nDetails of the other payment",
}
)
Expand Down Expand Up @@ -598,43 +589,34 @@
expect(income_payments).to contain_exactly(
{
'payment_type' => 'state_pension',
'amount' => 10_000,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
'amount' => 10_000,
'frequency' => 'week',
'ownership_type' => 'applicant',
},
{
'payment_type' => 'maintenance',
'amount' => 30_000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
'amount' => 30_000,
'frequency' => 'month',
'ownership_type' => 'applicant',
},
{
'payment_type' => 'maintenance',
'amount' => 15_000,
'frequency' => 'month',
'ownership_type' => 'partner',
'metadata' => {}
},
{
'payment_type' => 'other',
'amount' => 631_200, # rent(600 * 52) + student_loan_grant(50000 * 12)
'frequency' => 'annual',
'ownership_type' => 'applicant',
'metadata' => {
'details' => 'Applicant: Rent:£6.00/week, Student loan grant:£500.00/month'
},
'details' => 'Applicant: Rent:£6.00/week, Student loan grant:£500.00/month'
'amount' => 631_200, # rent(600 * 52) + student_loan_grant(50000 * 12)
'frequency' => 'annual',
'ownership_type' => 'applicant',
'details' => 'Applicant: Rent:£6.00/week, Student loan grant:£500.00/month'
},
{
'payment_type' => 'other',
'amount' => 25_000, # student_loan_grant(25_000)
'frequency' => 'annual',
'ownership_type' => 'partner',
'metadata' => {
'details' => 'Partner: Student loan grant:£250.00/annual'
},
'details' => 'Partner: Student loan grant:£250.00/annual'
},
)
Expand Down Expand Up @@ -696,21 +678,18 @@
'amount' => 10_000,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'maintenance',
'amount' => 30_000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'maintenance',
'amount' => 15_000,
'frequency' => 'month',
'ownership_type' => 'partner',
'metadata' => {}
}
)
end
Expand Down Expand Up @@ -824,40 +803,31 @@
'amount' => 500,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'incapacity',
'amount' => 1000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'industrial_injuries_disablement',
'amount' => 1500,
'frequency' => 'month',
'ownership_type' => 'partner',
'metadata' => {}
},
{
'payment_type' => 'other',
'amount' => 8100, # other(550 * 12) + jsa(1500)
'frequency' => 'annual',
'ownership_type' => 'partner',
'metadata' => {
'details' => "Partner: Jsa:£15.00/annual, Other:£5.50/month\nDetails of the other partner benefit",
},
'details' => "Partner: Jsa:£15.00/annual, Other:£5.50/month\nDetails of the other partner benefit",
},
{
'payment_type' => 'other',
'amount' => 17_400, # other(750 * 12) + jsa(700 * 12)
'frequency' => 'annual',
'ownership_type' => 'applicant',
'metadata' => {
'details' => "Applicant: Jsa:£7.00/month, Other:£7.50/month\nDetails of the other benefit"
},
'details' => "Applicant: Jsa:£7.00/month, Other:£7.50/month\nDetails of the other benefit"
}
)
Expand Down Expand Up @@ -926,40 +896,31 @@
'amount' => 500,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'incapacity',
'amount' => 1000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'industrial_injuries_disablement',
'amount' => 1500,
'frequency' => 'month',
'ownership_type' => 'partner',
'metadata' => {}
},
{
'payment_type' => 'other',
'amount' => 8400, # jsa(700 * 12)
'frequency' => 'annual',
'ownership_type' => 'applicant',
'metadata' => {
'details' => 'Applicant: Jsa:£7.00/month'
},
'details' => 'Applicant: Jsa:£7.00/month'
},
{
'payment_type' => 'other',
'amount' => 1500, # jsa(1500)
'frequency' => 'annual',
'ownership_type' => 'partner',
'metadata' => {
'details' => 'Partner: Jsa:£15.00/annual'
},
'details' => 'Partner: Jsa:£15.00/annual'
}
)
Expand Down Expand Up @@ -1007,14 +968,12 @@
'amount' => 500,
'frequency' => 'week',
'ownership_type' => 'applicant',
'metadata' => {}
},
{
'payment_type' => 'incapacity',
'amount' => 1000,
'frequency' => 'month',
'ownership_type' => 'applicant',
'metadata' => {}
}
)
end
Expand Down Expand Up @@ -1169,41 +1128,31 @@
expect(income_payments).to contain_exactly(
{
'amount' => 100_000,
'metadata' => {},
'frequency' => 'annual',
'payment_type' => 'state_pension',
'ownership_type' => 'applicant'
},
{
'amount' => 662_550,
'metadata' =>
{
'details' => "Applicant: Student loan grant:£100.00/fortnight, Board from family:£100.00/four_weeks, Other:£50.00/week, Trust fund dividend:£125.50/annual\nDetails of the other applicant payment",
},
'frequency' => 'annual',
'payment_type' => 'other',
'ownership_type' => 'applicant',
'details' => "Applicant: Student loan grant:£100.00/fortnight, Board from family:£100.00/four_weeks, Other:£50.00/week, Trust fund dividend:£125.50/annual\nDetails of the other applicant payment",
},
{
'amount' => 40_000,
'metadata' => {},
'frequency' => 'fortnight',
'payment_type' => 'state_pension',
'ownership_type' => 'partner'
},
{
'amount' => 10_000,
'metadata' => {},
'frequency' => 'week',
'payment_type' => 'interest_investment',
'ownership_type' => 'partner'
},
{
'amount' => 322_000,
'metadata' => {
'details' => 'Partner: From friends relatives:£60.00/week, Trust fund dividend:£100.00/annual'
},
'frequency' => 'annual',
'payment_type' => 'other',
'ownership_type' => 'partner',
Expand All @@ -1213,43 +1162,32 @@
end
# rubocop:enable Layout/LineLength

# rubocop:disable Layout/LineLength
it 'return updated income_benefits' do
income_benefits = representation.dig('means_details', 'income_details', 'income_benefits')

expect(income_benefits).to contain_exactly(
{
'amount' => 2_140_000,
'metadata' =>
{
'details' => "Applicant: Jsa:£500.00/fortnight, Other:£700.00/month\nDetails of the other income benefit",
},
'frequency' => 'annual',
'payment_type' => 'other',
'ownership_type' => 'applicant',
'details' => "Applicant: Jsa:£500.00/fortnight, Other:£700.00/month\nDetails of the other income benefit",
},
{
'amount' => 5000,
'metadata' => {},
'frequency' => 'fortnight',
'payment_type' => 'child',
'ownership_type' => 'partner'
},
{
'amount' => 960_000,
'metadata' =>
{
'details' => "Partner: Other:£800.00/month\nDetails of the other income benefit",
},
'frequency' => 'annual',
'payment_type' => 'other',
'ownership_type' => 'partner',
'details' => "Partner: Other:£800.00/month\nDetails of the other income benefit",
}
)
end
# rubocop:enable Layout/LineLength
end
end
# rubocop:enable RSpec/ExampleLength
Expand Down Expand Up @@ -1322,7 +1260,7 @@
it 'exposes details not metadata for income_benefits' do
expected_income_benefits = maat_means_schema.dig(
'properties', 'income_details', 'properties', 'income_benefits', 'items', 'properties'
).keys
).keys - ['metadata']

income_benefits = representation.dig('means_details', 'income_details', 'income_benefits')
other_income_benefit = income_benefits.find { |income_benefit| income_benefit['payment_type'] == 'other' }
Expand Down Expand Up @@ -1517,18 +1455,18 @@
'metadata' => {
'details' => 'Details of the other income benefit' * 50
},
'frequency' => 'month',
'payment_type' => 'other',
'ownership_type' => 'applicant'
'frequency' => 'month',
'payment_type' => 'other',
'ownership_type' => 'applicant'
},
{
'amount' => 1000,
'metadata' => {
'details' => 'PARTNER METADATA DETAILS' * 50
},
'frequency' => 'month',
'payment_type' => 'other',
'ownership_type' => 'partner'
'frequency' => 'month',
'payment_type' => 'other',
'ownership_type' => 'partner'
},
],
}
Expand Down

0 comments on commit eebfde5

Please sign in to comment.