Skip to content

Commit

Permalink
RST-4674 Fixing typo in report parser (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaparka authored Sep 26, 2022
1 parent e050279 commit f3ba01f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/models/views/reports/hmrc_ocmc_data_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def hmrc_income(value)

def tax_credit(value, date_range)
return 0 if value.blank?
date_formatted = date_range
date = date_formatted(date_range)
tax_credit_hash = YAML.parse(value).to_ruby
work = HmrcIncomeParser.tax_credit(tax_credit_hash.try(:[], :work), date_formatted)
child = HmrcIncomeParser.tax_credit(tax_credit_hash.try(:[], :child), date_formatted)
work = HmrcIncomeParser.tax_credit(tax_credit_hash.try(:[], :work), date)
child = HmrcIncomeParser.tax_credit(tax_credit_hash.try(:[], :child), date)
work + child
end

def date_formatted(date_range)
return nil if value.blank?
return nil if date_range.blank?
request_params_hash = YAML.parse(date_range).to_ruby
request_params_hash[:date_range]
end
Expand Down
39 changes: 29 additions & 10 deletions spec/models/views/reports/hmrc_ocmc_data_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
let(:income_kind) { {} }
let(:tax_credit) { {} }
let(:paye_income) { {} }
let(:date_range) { { date_range: { from: "1/2/2021", to: "1/3/2021" } } }
let(:date_range) { { date_range: { from: "1/7/2022", to: "31/7/2022" } } }

before { hmrc_check }

Expand All @@ -64,18 +64,37 @@
context 'paye and tax credit income' do
let(:paye_income) { [{ "taxablePay" => 120.04 }] }
let(:tax_credit) {
{ child: [{ "payProfCalcDate" => "2020-08-18",
"totalEntitlement" => 18765.23,
"childTaxCredit" => { "childCareAmount" => 930.98, "ctcChildAmount" => 730.49, "familyAmount" => 100.49, "babyAmount" => 100, "paidYTD" => 8976.34 },
"payments" => [{ "startDate" => "2021-06-24", "endDate" => "2022-03-31", "frequency" => 1, "amount" => 7634 }] }],
work: [{ "payProfCalcDate" => "2020-08-18",
"totalEntitlement" => 18765.23,
"workingTaxCredit" => { "amount" => 930.98, "paidYTD" => 8976.34 },
"payments" => [{ "startDate" => "2021-06-24", "endDate" => "2022-03-31", "frequency" => 1, "amount" => 634 }] }] }
{
child:
[
{ "payProfCalcDate" => "2022-07-30",
"totalEntitlement" => 7432.23,
"childTaxCredit" => { "childCareAmount" => 1310.41, "ctcChildAmount" => 5321.05, "familyAmount" => 547.5, "babyAmount" => 0, "paidYTD" => 2634.71 },
"payments" =>
[{ "startDate" => "2022-07-05", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 165.26 },
{ "startDate" => "2022-04-19", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 165.26 },
{ "startDate" => "2022-04-19", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 147.74 },
{ "startDate" => "2022-04-26", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 155.17 },
{ "startDate" => "2022-05-10", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 155.2 }] }
],
work:
[
{ "payProfCalcDate" => "2022-07-30",
"totalEntitlement" => 7432.23,
"childTaxCredit" => { "childCareAmount" => 1310.41, "ctcChildAmount" => 5321.05, "familyAmount" => 547.5, "babyAmount" => 0, "paidYTD" => 2634.71 },
"payments" =>
[{ "startDate" => "2022-07-05", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 165.26 },
{ "startDate" => "2022-04-19", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 165.26 },
{ "startDate" => "2022-04-19", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 147.74 },
{ "startDate" => "2022-04-26", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 155.17 },
{ "startDate" => "2022-05-10", "endDate" => "2022-08-30", "frequency" => 7, "tcType" => "ICC", "amount" => 155.2 }] }
]
}
}

it "calculates correct value" do
data_row = data[3]
expect(data_row).to include('202.72')
expect(data_row).to include('6098.56')
end

context 'no fail from tax_credit' do
Expand Down

0 comments on commit f3ba01f

Please sign in to comment.