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

Updated how Age gets passed from Excel to util. #921

Merged
merged 1 commit into from
Oct 5, 2023
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
2 changes: 1 addition & 1 deletion __tests__/pages/api/alwsBenefit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('AlwsBenefit', () => {
expectAlwMarital(res)
expectAlwsEligible(res, 811.51)
//Future Benefit
expectFutureOasGisBenefitEligible(res, 65, 698.6, 476.45,0)
expectFutureOasGisBenefitEligible(res, 65, 698.6, 476.45, 0)
expectFutureDeferralTable(res, 65, 0, futureDeferralTable)
})

Expand Down
2 changes: 0 additions & 2 deletions __tests__/pages/api/gisCoupleTwoPensBenefit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('gisCoupleTwoPensBenefit', () => {
expectOasEligible(res, EntitlementResultType.FULL, 768.46, true)
expectGisEligible(res, 452.09, true)
expectAlwTooOld(res, true)

})
/* CALC-26 */
it('should pass 26 test - CALC-26', async () => {
Expand Down Expand Up @@ -306,7 +305,6 @@ describe('gisCoupleTwoPensBenefit', () => {
expectOasEligible(res, EntitlementResultType.FULL, 698.6, true)
expectGisEligible(res, 898.45, true)
expectAlwTooOld(res, true)

})

/* CALC-38 */
Expand Down
Binary file modified __tests__/utils/ScenariosWith2023Q3RatesAndThresholds.xlsx
Binary file not shown.
37 changes: 16 additions & 21 deletions __tests__/utils/excelReaderUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { calculateAge } from '../../utils/api/helpers/utils'
import * as XLSX from 'xlsx'
import {
LegalStatus,
Expand Down Expand Up @@ -34,19 +35,20 @@ function readExcelData(filePath: string): string[] {
function createTransformedPayload(rowToTransform: string): Record<string, any> {
let payload: Record<string, any> = {
income: roundedIncome(rowToTransform["User's Net Worldwide Income"]),
age: rowToTransform['Age '],
age: rowToTransform['Age '].toString().includes(';')
? calculateAge(
extractValue(rowToTransform['Age '], 1),
extractValue(rowToTransform['Age '], 0)
)
: rowToTransform['Age '],
receiveOAS: transformValue(rowToTransform["Rec'ing OAS (Yes / No)"]),
oasDeferDuration:
rowToTransform['Delay (# of Years and Months)'] === 'N/A'
? undefined
: '{"years":' +
extractValueBeforeSemicolon(
rowToTransform['Delay (# of Years and Months)']
) +
extractValue(rowToTransform['Delay (# of Years and Months)'], 0) +
',"months":' +
extractFirstCharacterAfterSemicolon(
rowToTransform['Delay (# of Years and Months)']
) +
extractValue(rowToTransform['Delay (# of Years and Months)'], 1) +
'}',
//oasDefer: false, // no longer used.
//oasAge: 0,
Expand Down Expand Up @@ -160,7 +162,7 @@ function transformYearsInCanadaSinceOAS18Value(
partner?: boolean
): string | undefined {
if (value.toString().toUpperCase() === 'FULL') {
return '40'
return undefined
} else if (value.toString().toUpperCase() === 'N/A') {
return undefined
}
Expand Down Expand Up @@ -217,22 +219,15 @@ function transformPartnerBenefitStatusValue(value: string): String {
return undefined
}

function extractValueBeforeSemicolon(value: string): string {
if (value) {
const parts = value.split(';')
if (parts.length > 1 && parts[1].trim().length > 0) {
return parts[0].trim()
}
}
return value
}

function extractFirstCharacterAfterSemicolon(value: string): string {
function extractValue(value: string, pos: number): number {
if (value) {
const parts = value.split(';')
if (parts.length > 1 && parts[1].trim().length > 0) {
return parts[1].trim()[0]
if (pos > 0) {
return +parts[pos].trim()[0]
}
return +parts[pos].trim()
}
return +value
}
return value
}