From 6c1e4c5d8f5a313a3fa9da1dce627ee97c0371e0 Mon Sep 17 00:00:00 2001 From: MarcoGoC Date: Wed, 9 Oct 2024 12:49:01 -0400 Subject: [PATCH 1/2] saving changes --- __tests__/pages/api/benefits.test.ts | 3 + __tests__/pages/api/field-reqs.test.ts | 9 ++ __tests__/pages/api/index.test.ts | 5 + __tests__/pages/api/july2013Deferral.test.ts | 32 ++++++ __tests__/utils/expectUtils.ts | 3 + components/QuestionsPage/index.tsx | 7 ++ i18n/api/en.ts | 22 +++++ i18n/api/fr.ts | 22 +++++ i18n/api/index.ts | 1 + i18n/web/en.ts | 4 + i18n/web/fr.ts | 4 + utils/api/benefitHandler.ts | 98 +++++++++++++++++-- utils/api/benefits/oasBenefit.ts | 6 ++ utils/api/definitions/enums.ts | 2 + utils/api/definitions/fields.ts | 13 +++ utils/api/definitions/schemas.ts | 27 ++++- utils/api/definitions/types.ts | 4 + utils/api/fieldsHandler.ts | 14 +++ utils/api/futureHandler.ts | 16 ++- utils/api/helpers/utils.ts | 43 +++++++- .../scrapers/output/legalValuesJson_test.json | 54 +++++----- 21 files changed, 349 insertions(+), 40 deletions(-) diff --git a/__tests__/pages/api/benefits.test.ts b/__tests__/pages/api/benefits.test.ts index 60975dea4..683a9da0c 100644 --- a/__tests__/pages/api/benefits.test.ts +++ b/__tests__/pages/api/benefits.test.ts @@ -271,6 +271,7 @@ describe('consolidated benefit tests: ineligible', () => { partnerIncomeWork: 0, age: 50, oasDefer: false, + whenToStartOAS: true, //asap receiveOAS: false, oasDeferDuration: undefined, oasAge: undefined, @@ -791,6 +792,7 @@ describe('consolidated benefit tests: eligible: 65+', () => { partnerIncomeWork: 0, age: 75, oasDefer: false, + whenToStartOAS: true, //asap receiveOAS: false, oasDeferDuration: undefined, oasAge: undefined, @@ -973,6 +975,7 @@ describe('consolidated benefit tests: eligible: 60-64', () => { age: 64, oasDefer: false, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, oasAge: undefined, maritalStatus: MaritalStatus.PARTNERED, diff --git a/__tests__/pages/api/field-reqs.test.ts b/__tests__/pages/api/field-reqs.test.ts index 344a4c2a2..9ce84f6b9 100644 --- a/__tests__/pages/api/field-reqs.test.ts +++ b/__tests__/pages/api/field-reqs.test.ts @@ -26,6 +26,7 @@ describe('field requirement analysis', () => { oasDefer: undefined, oasAge: undefined, receiveOAS: false, + whenToStartOAS: undefined, //asap oasDeferDuration: undefined, maritalStatus: undefined, livingCountry: undefined, @@ -39,6 +40,7 @@ describe('field requirement analysis', () => { expect(res.body.summary.state).toEqual(SummaryState.MORE_INFO) expect(res.body.missingFields).toEqual([ FieldKey.AGE, + FieldKey.WHEN_TO_START, FieldKey.INCOME, //FieldKey.INCOME_WORK, FieldKey.LEGAL_STATUS, @@ -48,6 +50,7 @@ describe('field requirement analysis', () => { ]) expect(res.body.visibleFields).toEqual([ FieldKey.AGE, + FieldKey.WHEN_TO_START, FieldKey.INCOME, FieldKey.INCOME_WORK, FieldKey.LEGAL_STATUS, @@ -66,6 +69,7 @@ describe('field requirement analysis', () => { oasDefer: true, oasAge: 70, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: '{ "months": 0, "years": 5 }', maritalStatus: MaritalStatus.PARTNERED, ...canadian, @@ -87,6 +91,7 @@ describe('field requirement analysis', () => { expect(res.body.visibleFields).toEqual([ FieldKey.AGE, FieldKey.ALREADY_RECEIVE_OAS, + FieldKey.WHEN_TO_START, FieldKey.OAS_AGE, // FieldKey.INCOME_AVAILABLE, FieldKey.INCOME, @@ -119,6 +124,7 @@ describe('field requirements analysis: conditional fields', () => { partnerIncomeWork: 0, ...age65NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.SINGLE, ...canadian, @@ -140,6 +146,7 @@ describe('field requirements analysis: conditional fields', () => { partnerIncomeWork: 0, ...age65NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.SINGLE, ...canadian, @@ -161,6 +168,7 @@ describe('field requirements analysis: conditional fields', () => { partnerIncomeWork: 0, ...age65NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.SINGLE, livingCountry: LivingCountry.NO_AGREEMENT, @@ -183,6 +191,7 @@ describe('field requirements analysis: conditional fields', () => { partnerIncomeWork: 0, ...age65NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.PARTNERED, ...canadian, diff --git a/__tests__/pages/api/index.test.ts b/__tests__/pages/api/index.test.ts index 9fc42bb15..fe5577c6d 100644 --- a/__tests__/pages/api/index.test.ts +++ b/__tests__/pages/api/index.test.ts @@ -263,6 +263,7 @@ describe('basic Allowance scenarios', () => { ...income10k, ...age60NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.PARTNERED, invSeparated: false, @@ -356,6 +357,7 @@ describe('basic Allowance for Survivor scenarios', () => { ...age65NoDefer, incomeWork: 0, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.WIDOWED, ...canadian, @@ -372,6 +374,7 @@ describe('basic Allowance for Survivor scenarios', () => { ...income10k, ...age65NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.WIDOWED, invSeparated: false, @@ -394,6 +397,7 @@ describe('basic Allowance for Survivor scenarios', () => { age: 59, oasDefer: false, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, oasAge: undefined, maritalStatus: MaritalStatus.WIDOWED, @@ -438,6 +442,7 @@ describe('basic Allowance for Survivor scenarios', () => { ...income10k, ...age60NoDefer, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, maritalStatus: MaritalStatus.PARTNERED, invSeparated: false, diff --git a/__tests__/pages/api/july2013Deferral.test.ts b/__tests__/pages/api/july2013Deferral.test.ts index 5dad3a98f..5be812aad 100644 --- a/__tests__/pages/api/july2013Deferral.test.ts +++ b/__tests__/pages/api/july2013Deferral.test.ts @@ -416,4 +416,36 @@ describe('july2013Deferral', () => { expectGisEligible(res, 0, true) expectAlwTooOld(res, true) }) + + /* CALC-187 */ + it('should TEST TEST - CALC-187', async () => { + const desiredName = 'CALC-187' + const extractedPayload = getTransformedPayloadByName(filePath, desiredName) + const res = await mockGetRequest({ + ...extractedPayload, + maritalStatus: 'single', + invSeparated: 'false', + age: 55.0, + clientBirthDate: '1969;08', + yearsInCanadaSince18: '10', + income: 2000, + whenToStartOAS: false, + startDateForOAS: -10.08, + partnerBenefitStatus: undefined, + partnerIncome: 0, + partnerIncomeWork: 0, + partnerAge: undefined, + partnerBirthDate: undefined, + partnerLivingCountry: undefined, + partnerLegalStatus: undefined, + partnerLivedOnlyInCanada: undefined, + }) + + const future = res.body.futureClientResults[0][65] + console.log('#####', future) + expect(res.status).toEqual(400) + expect(res.body.summary.state).toEqual('AVAILABLE_INELIGIBLE') + expect(future.oas.eligibility.result).toEqual('eligible') + expect(future.oas.entitlement.result).toBeCloseTo(359.17, 0.01) + }) }) diff --git a/__tests__/utils/expectUtils.ts b/__tests__/utils/expectUtils.ts index ec27fe60b..dd01ef9dd 100644 --- a/__tests__/utils/expectUtils.ts +++ b/__tests__/utils/expectUtils.ts @@ -342,6 +342,7 @@ export const age65NoDefer = { oasDefer: false, oasAge: undefined, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, } @@ -350,6 +351,7 @@ export const age75NoDefer = { oasDefer: false, oasAge: undefined, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, } @@ -358,6 +360,7 @@ export const age60NoDefer = { oasDefer: false, oasAge: undefined, receiveOAS: false, + whenToStartOAS: true, //asap oasDeferDuration: undefined, } diff --git a/components/QuestionsPage/index.tsx b/components/QuestionsPage/index.tsx index a1ceccbe9..26addfeb6 100644 --- a/components/QuestionsPage/index.tsx +++ b/components/QuestionsPage/index.tsx @@ -185,6 +185,12 @@ export const QuestionsPage: React.VFC = ({}) => { setAgeDate(ageDate) } + if (key === 'startDateForOAS') { + newVal = JSON.parse(newValue).value + // const oasStartDate = JSON.parse(newValue).date + // setDateToStartOAS(oasStartDate) + } + if (key === 'partnerAge') { newVal = JSON.parse(newValue).value } @@ -228,6 +234,7 @@ export const QuestionsPage: React.VFC = ({}) => { receiveOAS, tsln ) + return (
diff --git a/i18n/api/en.ts b/i18n/api/en.ts index b39d8da30..b664e9763 100644 --- a/i18n/api/en.ts +++ b/i18n/api/en.ts @@ -47,6 +47,9 @@ const en: Translations = { [FieldKey.AGE]: 'When were you born?', [FieldKey.ALREADY_RECEIVE_OAS]: 'Do you already receive the Old Age Security pension?', + [FieldKey.WHEN_TO_START]: + 'When do you want your Old Age Security pension to start?', + [FieldKey.START_DATE_FOR_OAS]: 'Enter start date', [FieldKey.OAS_DEFER_DURATION]: 'How long did you defer your Old Age Security pension?', [FieldKey.OAS_DEFER]: @@ -85,6 +88,8 @@ const en: Translations = { questionShortText: { [FieldKey.AGE]: 'Age', [FieldKey.ALREADY_RECEIVE_OAS]: 'Already receive OAS pension', + [FieldKey.WHEN_TO_START]: 'OAS pension start date', + [FieldKey.START_DATE_FOR_OAS]: 'Start date', [FieldKey.OAS_DEFER]: 'OAS pension deferral', [FieldKey.OAS_DEFER_DURATION]: 'Deferred OAS pension', [FieldKey.OAS_AGE]: 'OAS pension deferral', @@ -116,6 +121,9 @@ const en: Translations = { [FieldKey.OAS_AGE]: 'Start at', [FieldKey.ALREADY_RECEIVE_OAS]: 'Edit if you already receive the OAS pension', + [FieldKey.WHEN_TO_START]: + 'When do you want your Old Age Security pension to start?', + [FieldKey.START_DATE_FOR_OAS]: 'Edit your start date', [FieldKey.OAS_DEFER_DURATION]: 'Edit your OAS pension deferral', [FieldKey.OAS_DEFER]: 'Edit your deferral decision', [FieldKey.INCOME_AVAILABLE]: 'Edit if you will provide your income', @@ -162,6 +170,8 @@ const en: Translations = { 'If you didn’t delay your payments, go to the next step.', [FieldKey.OAS_DEFER]: 'If you already receive the OAS pension, enter when you started receiving it. {LINK_OAS_DEFER_INLINE}', + [FieldKey.WHEN_TO_START]: + "If you're eligible, you can start as early as the month after your 65th birthday", [FieldKey.OAS_AGE]: 'This should be between 65 and 70.', [FieldKey.YEARS_IN_CANADA_SINCE_18]: 'Do not include periods when you were outside Canada for at least 6 months at a time. Some exceptions apply, such as working for a Canadian employer abroad.', @@ -207,6 +217,18 @@ const en: Translations = { shortText: 'No', }, ], + [FieldKey.WHEN_TO_START]: [ + { + key: true, + text: 'As soon as possible', + shortText: 'As soon as possible', + }, + { + key: false, + text: 'As of a specific month', + shortText: 'As of a specific month', + }, + ], [FieldKey.OAS_DEFER]: [ { key: false, diff --git a/i18n/api/fr.ts b/i18n/api/fr.ts index 10a925889..47951fb25 100644 --- a/i18n/api/fr.ts +++ b/i18n/api/fr.ts @@ -49,6 +49,9 @@ const fr: Translations = { [FieldKey.AGE]: 'Quel est votre mois de naissance?', [FieldKey.ALREADY_RECEIVE_OAS]: 'Recevez-vous la pension de la Sécurité de la vieillesse?', + [FieldKey.WHEN_TO_START]: + 'Quand voulez-vous commencer à recevoir votre pension de la Sécurité de la vieillesse?', + [FieldKey.START_DATE_FOR_OAS]: 'Entrez une date de début', [FieldKey.OAS_DEFER_DURATION]: 'Pendant combien de temps avez-vous reporté votre pension de la Sécurité de la vieillesse?', [FieldKey.OAS_DEFER]: @@ -88,6 +91,8 @@ const fr: Translations = { questionShortText: { [FieldKey.AGE]: 'Âge', [FieldKey.ALREADY_RECEIVE_OAS]: 'Reçoit la pension de la SV', + [FieldKey.WHEN_TO_START]: 'Date de début de la pension SV', + [FieldKey.START_DATE_FOR_OAS]: 'date de début', [FieldKey.OAS_DEFER]: 'Report de la pension de la SV', [FieldKey.OAS_DEFER_DURATION]: 'Report de la pension de la SV', [FieldKey.OAS_AGE]: 'Report de la pension de la\xA0SV', @@ -120,6 +125,9 @@ const fr: Translations = { [FieldKey.OAS_AGE]: 'Commencer à', [FieldKey.ALREADY_RECEIVE_OAS]: 'Modifier si vous recevez la pension de la SV', + [FieldKey.WHEN_TO_START]: + 'Modifier quand voulez-vous commencer à recevoir votre pension de la Sécurité de la vieillesse?', + [FieldKey.START_DATE_FOR_OAS]: 'Modifier votre date de début', [FieldKey.OAS_DEFER]: 'Modifier votre décision de report', [FieldKey.OAS_DEFER_DURATION]: 'Modifier le report de votre pension de la SV', @@ -170,6 +178,8 @@ const fr: Translations = { '
Si vous recevez déjà la pension de la SV, indiquez quand vous avez commencé à la recevoir. {LINK_OAS_DEFER_INLINE}
', [FieldKey.OAS_DEFER_DURATION]: "Si vous n'avez pas reporté votre pension, passez à l'étape suivante.", + [FieldKey.WHEN_TO_START]: + 'Si vous êtes admissible, vous pouvez commencer dès le mois après votre 65e anniversaire.', [FieldKey.OAS_AGE]: 'Ce nombre doit être entre 65 et 70.', [FieldKey.YEARS_IN_CANADA_SINCE_18]: "Ne comptez pas les périodes où vous étiez à l'extérieur du Canada pendant au moins 6 mois consécutifs. Certaines exceptions s'appliquent, comme travailler pour un employeur canadien à l'étranger.", @@ -215,6 +225,18 @@ const fr: Translations = { shortText: 'Non', }, ], + [FieldKey.WHEN_TO_START]: [ + { + key: true, + text: 'As soon as possible', + shortText: 'As soon as possible', + }, + { + key: false, + text: 'As of a specific month', + shortText: 'As of a specific month', + }, + ], [FieldKey.OAS_DEFER]: [ { key: false, diff --git a/i18n/api/index.ts b/i18n/api/index.ts index 26b0c3a0d..28dd0eb89 100644 --- a/i18n/api/index.ts +++ b/i18n/api/index.ts @@ -39,6 +39,7 @@ export interface Translations { questionOptions: { [FieldKey.INCOME_AVAILABLE]: TypedKeyAndText[] [FieldKey.ALREADY_RECEIVE_OAS]: TypedKeyAndText[] + [FieldKey.WHEN_TO_START]: TypedKeyAndText[] [FieldKey.OAS_DEFER]: TypedKeyAndText[] [FieldKey.LEGAL_STATUS]: TypedKeyAndText[] [FieldKey.LIVED_ONLY_IN_CANADA]: TypedKeyAndText[] diff --git a/i18n/web/en.ts b/i18n/web/en.ts index 93697b560..ae5c2e762 100644 --- a/i18n/web/en.ts +++ b/i18n/web/en.ts @@ -369,6 +369,10 @@ const en: WebTranslations = { [ValidationErrors.receiveOASEmpty]: //'Please indicate if you receive the OAS pension.', 'Please indicate if you receive the Old Age Security pension', + [ValidationErrors.whenToStartOAS]: + 'Please indicate when to start your OAS pension', + [ValidationErrors.startDateForOAS]: + 'You must be at least 65 and 1 month to start receiving the Old Age Security pension.', [ValidationErrors.providePartnerIncomeEmpty]: "Please indicate if you're able to provide your partner's income.", [ValidationErrors.partnerIncomeEmpty]: diff --git a/i18n/web/fr.ts b/i18n/web/fr.ts index 743d7fd62..b734d86c1 100644 --- a/i18n/web/fr.ts +++ b/i18n/web/fr.ts @@ -375,6 +375,10 @@ const fr: WebTranslations = { [ValidationErrors.receiveOASEmpty]: //'Veuillez indiquer si vous recevez la pension de la SV.', 'Veuillez indiquer si vous recevez la pension de la Sécurité de la vieillesse', + [ValidationErrors.whenToStartOAS]: + 'FRENCH ==> Please indicate when to start your OAS pension', + [ValidationErrors.startDateForOAS]: + 'Vous devez avoir au moins 65 ans et 1 mois pour commencer à recevoir la pension de la Sécurité de la vieillesse.', [ValidationErrors.providePartnerIncomeEmpty]: 'Veuillez indiquer si vous êtes en mesure de fournir le revenu de votre conjoint.', [ValidationErrors.incomeWorkEmpty]: diff --git a/utils/api/benefitHandler.ts b/utils/api/benefitHandler.ts index b36353830..7efa952c7 100644 --- a/utils/api/benefitHandler.ts +++ b/utils/api/benefitHandler.ts @@ -116,6 +116,22 @@ export class BenefitHandler { const initialPartnerBenefitStatus = this.input.client.partnerBenefitStatus.value + // saving the original input value for residence + if (this.formYearsInCanada === undefined) + this.formYearsInCanada = this.input.client.yearsInCanadaSince18 + + console.log( + '### curr resid=', + this.input.client.yearsInCanadaSince18, + 'future', + this.future, + 'form age', + this.formAge, + 'form resid', + this.formYearsInCanada, + '###' + ) + // Future handler takes care of cases when partner is not yet eligible by creating "age sets" of future eligible ages // If partner was already eligible in the past based on residency, we need to adjust the inputs if (!this.future) { @@ -158,6 +174,50 @@ export class BenefitHandler { ) } + consoleDev( + '>>> benefitHandler', + this.input.client.startDateForOAS, + 'NewResidYrs', + this.input.client.yearsInCanadaSince18, + 'oasDeferDuration', + this.input.client.oasDeferDuration, + 'future', + this.future + ) + + // If client selected a when to start OAS date then the client accumulates some extra months of residency + // if date to start is greater than 12 months + // full yrs are added to the residence + // partial months are added as a deferral months + if ( + this.input.client.whenToStartOAS !== undefined && + !this.input.client.whenToStartOAS && + !this.future + ) { + let futureMonths = this.input.client.startDateForOAS * 12 * -1 + + this.input.client.yearsInCanadaSince18 = + this.input.client.yearsInCanadaSince18 + + Math.floor(Math.round(futureMonths) / 12) + + this.input.client.oasDeferDuration = `{"months":${Math.round( + futureMonths % 12 + )}, "years": 0}` + + consoleDev( + '>>> MAX RESIDENCY startDateforOAS=', + this.input.client.startDateForOAS, + 'months=', + futureMonths, + 'form Resid', + this.formYearsInCanada, + 'NewResidYrs', + this.input.client.yearsInCanadaSince18, + 'oasDeferDuration', + this.input.client.oasDeferDuration + ) + } + const clientOasNoDeferral = new OasBenefit( this.input.client, this.fields.translations, @@ -168,6 +228,7 @@ export class BenefitHandler { this.formAge, this.formYearsInCanada ) + // If the client needs help, check their partner's OAS. // no defer and defer options? if (this.input.client.partnerBenefitStatus.helpMe) { @@ -191,21 +252,44 @@ export class BenefitHandler { clientOasNoDeferral.entitlement } - consoleDev('NO DEFERRAL', clientOasNoDeferral) + //consoleDev('NO DEFERRAL', clientOasNoDeferral) consoleDev( 'Client OAS amount NO deferral', clientOasNoDeferral.entitlement.result ) + // Previous calculations changes the value of yearsInCanadaSince18 + // this restores the original value when needed + if ( + this.input.client.whenToStartOAS !== undefined && + !this.input.client.whenToStartOAS + ) { + console.log('yearsInCanada before', this.input.client.yearsInCanadaSince18) + this.input.client.yearsInCanadaSince18 = this.formYearsInCanada + console.log('yearsInCanada after', this.input.client.yearsInCanadaSince18) + } + // Determines if it is possible to defer OAS and provides useful properties such as new inputs and deferral months to calculate the OAS deferred case - const clientOasHelper = evaluateOASInput(this.input.client) + const clientOasHelper = evaluateOASInput(this.input.client, this.formAge) + + consoleDev( + '>>> MAX DEFERRAL startDateforOAS=', + clientOasHelper.newInput.startDateForOAS, + 'age', + clientOasHelper.newInput.age, + 'ResidYrs', + clientOasHelper.newInput.yearsInCanadaSince18, + 'oasDeferDuration', + clientOasHelper.newInput.oasDeferDuration + ) let clientOasWithDeferral if (clientOasHelper.canDefer) { - consoleDev( - 'Modified input to calculate OAS with deferral', - clientOasHelper.newInput - ) + // consoleDev( + // 'Modified input to calculate OAS with deferral', + // clientOasHelper.newInput + // ) + clientOasWithDeferral = new OasBenefit( clientOasHelper.newInput, this.fields.translations, @@ -215,7 +299,7 @@ export class BenefitHandler { this.input.client.age ) - consoleDev('WITH DEFERRAL', clientOasWithDeferral) + //consoleDev('WITH DEFERRAL', clientOasWithDeferral) consoleDev( 'Client OAS amount WITH deferral', clientOasWithDeferral.entitlement.result diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 04348a6e3..58d3e5930 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -262,6 +262,12 @@ export class OasBenefit extends BaseBenefit { const durationStr = this.input.oasDeferDuration if (durationStr) { + console.log( + '>>> oasBenefit Resid', + this.input.yearsInCanadaSince18, + 'defer', + durationStr + ) const duration: MonthsYears = JSON.parse(durationStr) const durationFloat = duration.years + duration.months / 12 oasAge = 65 + durationFloat diff --git a/utils/api/definitions/enums.ts b/utils/api/definitions/enums.ts index c05687451..f08909047 100644 --- a/utils/api/definitions/enums.ts +++ b/utils/api/definitions/enums.ts @@ -98,6 +98,8 @@ export enum LinkIcon { export enum ValidationErrors { invalidAge = 'invalidAge', receiveOASEmpty = 'receiveOASEmpty', + whenToStartOAS = 'whenToStartOAS', + startDateForOAS = 'startDateForOAS', oasDeferEmpty = 'oasDeferEmpty', providePartnerIncomeEmpty = 'providePartnerIncomeEmpty', partnerIncomeEmpty = 'partnerIncomeEmpty', diff --git a/utils/api/definitions/fields.ts b/utils/api/definitions/fields.ts index 34fd1f2f4..d8c48383a 100644 --- a/utils/api/definitions/fields.ts +++ b/utils/api/definitions/fields.ts @@ -7,6 +7,8 @@ export enum FieldKey { INCOME_WORK = 'incomeWork', AGE = 'age', ALREADY_RECEIVE_OAS = 'receiveOAS', + WHEN_TO_START = 'whenToStartOAS', + START_DATE_FOR_OAS = 'startDateForOAS', OAS_DEFER_DURATION = 'oasDeferDuration', OAS_DEFER = 'oasDefer', OAS_AGE = 'oasAge', @@ -52,6 +54,17 @@ export const fieldDefinitions: FieldDefinitions = { category: { key: FieldCategory.AGE }, type: FieldType.RADIO, }, + [FieldKey.WHEN_TO_START]: { + key: FieldKey.WHEN_TO_START, + category: { key: FieldCategory.AGE }, + type: FieldType.RADIO, + //default: { key: 'true', text: 'Yes', shortText: 'Yes' }, + }, + [FieldKey.START_DATE_FOR_OAS]: { + key: FieldKey.START_DATE_FOR_OAS, + category: { key: FieldCategory.AGE }, + type: FieldType.DATE, + }, [FieldKey.OAS_DEFER_DURATION]: { key: FieldKey.OAS_DEFER_DURATION, category: { key: FieldCategory.AGE }, diff --git a/utils/api/definitions/schemas.ts b/utils/api/definitions/schemas.ts index 1051ccab6..4378bcb41 100644 --- a/utils/api/definitions/schemas.ts +++ b/utils/api/definitions/schemas.ts @@ -71,8 +71,6 @@ export const RequestSchema = Joi.object({ .precision(2) .min(0) .message(ValidationErrors.incomeBelowZero), - //.max(Joi.ref('income')) - //.message(ValidationErrors.incomeWorkGreaterThanNetIncome), age: Joi.number() .required() .messages({ @@ -83,6 +81,31 @@ export const RequestSchema = Joi.object({ receiveOAS: Joi.boolean() .required() .messages({ 'any.required': ValidationErrors.receiveOASEmpty }), + whenToStartOAS: Joi.boolean() + .required() + .messages({ 'any.required': ValidationErrors.whenToStartOAS }), + startDateForOAS: Joi.number() + .required() + .messages({ 'any.required': ValidationErrors.startDateForOAS }) + .custom((value, helpers) => { + const { age } = helpers.state.ancestors[0] + + if (value === 0) { + return helpers.message({ + custom: ValidationErrors.startDateForOAS, + }) + } + + // hack. control returns a negative value for dates in the future + const startDate: number = value > 0 ? value : value * -1 + + if (startDate + age < 65.08) { + return helpers.message({ + custom: ValidationErrors.startDateForOAS, + }) + } + return value + }, 'custom validation for the "yearsInCanadaSince18" question'), oasDeferDuration: Joi.string(), oasDefer: Joi.boolean() .required() diff --git a/utils/api/definitions/types.ts b/utils/api/definitions/types.ts index 6bdd93c5a..c042bcfe3 100644 --- a/utils/api/definitions/types.ts +++ b/utils/api/definitions/types.ts @@ -33,6 +33,8 @@ export interface RequestInput { receiveOAS: boolean oasDeferDuration: string oasDefer: boolean + whenToStartOAS?: boolean + startDateForOAS?: number oasAge: number maritalStatus: MaritalStatus invSeparated: boolean @@ -65,6 +67,8 @@ export interface ProcessedInput { receiveOAS: boolean oasDeferDuration: string oasDefer: boolean + whenToStartOAS?: boolean + startDateForOAS?: number oasAge: number maritalStatus: MaritalStatusHelper livingCountry: LivingCountryHelper diff --git a/utils/api/fieldsHandler.ts b/utils/api/fieldsHandler.ts index 5d6d6e1c6..1c1f6dbe2 100644 --- a/utils/api/fieldsHandler.ts +++ b/utils/api/fieldsHandler.ts @@ -110,6 +110,12 @@ export class FieldsHandler { this.rawInput.oasDeferDuration || JSON.stringify({ months: 0, years: 0 }), oasDefer: this.rawInput.oasDefer, + // Start Date to OAS changes + whenToStartOAS: this.rawInput.whenToStartOAS, + // If start asap then start date = 65 yrs 1 month. + startDateForOAS: this.rawInput.whenToStartOAS + ? 65.08 + : this.rawInput.startDateForOAS, oasAge: this.rawInput.oasDefer ? this.rawInput.oasAge : 65, maritalStatus: maritalStatusHelper, livingCountry: new LivingCountryHelper(this.rawInput.livingCountry), @@ -189,6 +195,14 @@ export class FieldsHandler { requiredFields.push(FieldKey.OAS_DEFER_DURATION) } + if (clientAge <= 65 || this.input.client.receiveOAS === false) { + requiredFields.push(FieldKey.WHEN_TO_START) + } + + if (this.input.client.whenToStartOAS == false) { + requiredFields.push(FieldKey.START_DATE_FOR_OAS) + } + // default value = undefined if (this.input.client.livedOnlyInCanada === false) { if (this.input.client.receiveOAS == true) { diff --git a/utils/api/futureHandler.ts b/utils/api/futureHandler.ts index 2d96efb89..726d7fc6c 100644 --- a/utils/api/futureHandler.ts +++ b/utils/api/futureHandler.ts @@ -38,7 +38,9 @@ export class FutureHandler { private getSingleResults() { let result = this.futureResultsObj + console.log('@@ FutureHandler yearsInCanada', this.query.yearsInCanadaSince18) const yearsInCanada = Number(this.query.yearsInCanadaSince18) + const age = Number(this.query.age) // TODO: take into consideration whether in Canada or not? (could be 10 or 20) const residencyReq = 10 @@ -57,15 +59,18 @@ export class FutureHandler { this.newQuery['receiveOAS'] = 'false' if ( - this.query.livedOnlyInCanada === 'false' && + (this.query.livedOnlyInCanada === 'false' || + !this.query.livedOnlyInCanada) && this.query.yearsInCanadaSince18 ) { this.newQuery['yearsInCanadaSince18'] = String( Math.min(40, eliObj.yearsOfResAtEligibility) ) + console.log('@@ FutureHandler #2 yearsInCanada', this.newQuery.yearsInCanadaSince18, eliObj.yearsOfResAtEligibility) } const { value } = schema.validate(this.newQuery, { abortEarly: false }) + console.log('@@ FutureHandler #3 yearsInCanada', value.yearsInCanadaSince18) const handler = new BenefitHandler( value, true, @@ -163,7 +168,7 @@ export class FutureHandler { Number(this.query.yearsInCanadaSinceOAS) const partnerRes = Number(this.query.partnerYearsInCanadaSince18) const partnerOnlyCanada = this.query.partnerLivedOnlyInCanada - + console.log('@@ Future Married yearsInCanada', clientRes) const clientDeferralMeta = this.currentHandler.benefitResults?.client?.oas?.entitlement?.deferral const partnerDeferralMeta = @@ -206,7 +211,11 @@ export class FutureHandler { }, } - const futureAges = getAgeArray(agesInputObj) + // TODO when there is a StartFromDate the years need to be added to the array below + const futureAges = [...getAgeArray(agesInputObj), [76, 91]] + // TODO this.query is missing the residence years, and months delayed + + console.log('futureAges', futureAges) let result = this.futureResultsObj if (futureAges.length !== 0) { @@ -229,6 +238,7 @@ export class FutureHandler { partnerLockResidence ) const { value } = schema.validate(newQuery, { abortEarly: false }) + console.log('>>>> TEST Age', userAge, partnerAge, 'Res', value) const handler = new BenefitHandler( value, true, diff --git a/utils/api/helpers/utils.ts b/utils/api/helpers/utils.ts index 460d74fd2..dc61de79d 100644 --- a/utils/api/helpers/utils.ts +++ b/utils/api/helpers/utils.ts @@ -266,12 +266,14 @@ export function AlwsEligibility(age, yearsInCanada) { } } -export function evaluateOASInput(input) { +export function evaluateOASInput(input, formAge) { let canDefer = false let justBecameEligible = false const age = input.age // 66.42 const ageJuly2013 = calculate2013Age(age, input.clientBirthDate) + const yearsInCanada = input.yearsInCanadaSince18 + let eliObj = OasEligibility( age, yearsInCanada, @@ -302,6 +304,45 @@ export function evaluateOASInput(input) { } else { // They became eligible after July 2013 -> use age and residency as is (at the time they became eligible for OAS) deferralMonths = (Math.min(70, age) - eliObj.ageOfEligibility) * 12 + + // If the client selected an Start_Date_for_OAS then + // IF Client age >= 65 add ALL futureMonths to the deferral months + // If Client age < 65 futureMonths will be converted into years and months discarting any months after 65 + // Example: client age is 45.6 wants oas as of 65.6 => 240 months However at 65 he only have 234 montsh or 19 yrs and 6 months + // + if (!input.whenToStartOAS) { + let futureMonths = input.startDateForOAS * 12 * -1 + + if (formAge >= 65) { + deferralMonths = deferralMonths + futureMonths + } else { + console.log("before ", eliObj.yearsOfResAtEligibility) + eliObj.yearsOfResAtEligibility = + eliObj.yearsOfResAtEligibility + Math.floor(65 - formAge) + console.log("after ", eliObj.yearsOfResAtEligibility) + deferralMonths = ((65 - formAge) * 12) % 12 + } + + consoleDev( + '### EvaluateOASInput startDateOAS', + input.startDateForOAS, + 'deferral', + Math.round((Math.min(70, age) - eliObj.ageOfEligibility) * 12), + 'startDate', + Math.round(futureMonths), + 'NEW deferral', + Math.round(deferralMonths), + 'age', + age, + 'ageJuly2013', + ageJuly2013, + 'formAge', + formAge, + 'elig Age,Resid', + eliObj.ageOfEligibility, + eliObj.yearsOfResAtEligibility + ) + } } } diff --git a/utils/api/scrapers/output/legalValuesJson_test.json b/utils/api/scrapers/output/legalValuesJson_test.json index 244518fdd..e77bfc818 100644 --- a/utils/api/scrapers/output/legalValuesJson_test.json +++ b/utils/api/scrapers/output/legalValuesJson_test.json @@ -1,39 +1,39 @@ { - "lastUpdatedYear": 2022, - "lastUpdatedQuarter": "July to September 2023", - "renewalYearGIS": 2023, + "lastUpdatedYear": 2023, + "lastUpdatedQuarter": "July to September 2024", + "renewalYearGIS": 2024, "oas": { - "amount": 698.6, - "amount75": 768.46, - "incomeLimit": 134626, - "incomeLimit75": 137331, - "clawbackIncomeLimit": 81761 + "amount": 718.33, + "amount75": 790.16, + "incomeLimit": 142609, + "incomeLimit75": 148179, + "clawbackIncomeLimit": 86912 }, "gis": { - "singleAmount": 1043.45, - "singleIncomeLimit": 21168, - "spouseOasAmount": 628.09, - "spouseOasIncomeLimit": 27984, - "spouseNoOasAmount": 1043.45, - "spouseNoOasIncomeLimit": 50736, - "spouseAlwAmount": 628.09, - "spouseAlwIncomeLimit": 39168 + "singleAmount": 1072.93, + "singleIncomeLimit": 21768, + "spouseOasAmount": 645.84, + "spouseOasIncomeLimit": 28752, + "spouseNoOasAmount": 1072.93, + "spouseNoOasIncomeLimit": 52176, + "spouseAlwAmount": 645.84, + "spouseAlwIncomeLimit": 40272 }, "alw": { - "alwAmount": 1326.69, - "alwIncomeLimit": 39168, - "afsAmount": 1581.51, - "afsIncomeLimit": 28512 + "alwAmount": 1364.17, + "alwIncomeLimit": 40272, + "afsAmount": 1626.2, + "afsIncomeLimit": 29328 }, "topUp": { - "single": 161.63, - "married": 45.79 + "single": 166.2, + "married": 47.09 }, "delay": { - "oas66": 748.9, - "oas67": 799.2, - "oas68": 849.5, - "oas69": 899.8, - "oas70": 950.1 + "oas66": 770.05, + "oas67": 821.77, + "oas68": 873.49, + "oas69": 925.21, + "oas70": 976.93 } } From 12a81cdc0df12a5166785e3e477e7773a2b5d804 Mon Sep 17 00:00:00 2001 From: Alex Soloviev Date: Fri, 1 Nov 2024 10:36:51 -0700 Subject: [PATCH 2/2] delete comments i dont want --- __tests__/pages/api/smokeTests.test.ts | 199 ++++++++++++++++++ utils/api/benefitHandler.ts | 54 +---- utils/api/benefits/oasBenefit.ts | 6 - utils/api/futureHandler.ts | 12 +- utils/api/helpers/utils.ts | 52 ++--- .../api/scrapers/output/legalValuesJson.json | 50 ++--- 6 files changed, 248 insertions(+), 125 deletions(-) create mode 100644 __tests__/pages/api/smokeTests.test.ts diff --git a/__tests__/pages/api/smokeTests.test.ts b/__tests__/pages/api/smokeTests.test.ts new file mode 100644 index 000000000..f9896475c --- /dev/null +++ b/__tests__/pages/api/smokeTests.test.ts @@ -0,0 +1,199 @@ +import { + LegalStatus, + LivingCountry, + MaritalStatus, + PartnerBenefitStatus, + ResultKey, + ResultReason, + ValidationErrors, + EntitlementResultType, + SummaryState, +} from '../../../utils/api/definitions/enums' +import { FieldKey } from '../../../utils/api/definitions/fields' +import roundToTwo from '../../../utils/api/helpers/roundToTwo' +import legalValues from '../../../utils/api/scrapers/output' +import { + age60NoDefer, + age65NoDefer, + canadaWholeLife, + canadian, + expectAlwsMarital, + expectAllIneligible, + expectAlwTooOld, + expectOasGisTooYoung, + income10k, + partnerIncomeZero, + partnerNoHelpNeeded, + partnerUndefined, + getErrorDetails, + expectOasEligible, +} from '../../utils/expectUtils' +import { mockGetRequest } from '../../utils/factory' + +const obsolete = { + incomeWork: 0, + oasDefer: false, + oasAge: 0, + livedOnlyInCanada: false, + everLivedSocialCountry: false, + partnerIncomeWork: 0, +} + +describe('Smoke tests', () => { + it('SMKTST-17', async () => { + const res = await mockGetRequest({ + age: 55.0, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -10.08, + incomeAvailable: undefined, + income: 2000, + yearsInCanadaSince18: 10, + maritalStatus: MaritalStatus.SINGLE, + invSeparated: false, + ...canadian, + ...partnerUndefined, + ...obsolete, + clientBirthDate: '1969;08', + }) + + const future = res.body.futureClientResults[0][65] + + expect(res.status).toEqual(400) + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_INELIGIBLE) + expect(future.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(future.oas.entitlement.result).toBeCloseTo(359.17, 0.01) + }) + + it('SMKTST-18', async () => { + const res = await mockGetRequest({ + age: 45.5, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -20.08, + incomeAvailable: undefined, + income: 15000, + yearsInCanadaSince18: 15, + maritalStatus: MaritalStatus.SINGLE, + invSeparated: undefined, + ...partnerUndefined, + ...canadian, + ...obsolete, + }) + + const future = res.body.futureClientResults[0][65] + + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_INELIGIBLE) + expect(future.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(future.oas.entitlement.result).toBeCloseTo(632.56, 0.01) + }) + + it('SMKTST-19', async () => { + const res = await mockGetRequest({ + age: 50, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -26.0, + incomeAvailable: undefined, + income: 5000, + yearsInCanadaSince18: 20, + maritalStatus: MaritalStatus.PARTNERED, + invSeparated: false, + partnerBenefitStatus: PartnerBenefitStatus.OAS_GIS, + partnerIncomeAvailable: undefined, + partnerIncome: 25000, + partnerAge: 65.0, + partnerLivingCountry: LivingCountry.CANADA, + partnerLegalStatus: LegalStatus.YES, + partnerLivedOnlyInCanada: false, + partnerYearsInCanadaSince18: 20, + ...canadian, + ...obsolete, + }) + + const future = res.body.futureClientResults[0][65] + + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_INELIGIBLE) + expect(future.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(future.oas.entitlement.result).toBeCloseTo(359.17, 0.01) + }) + + it('SMKTST-25C', async () => { + const res = await mockGetRequest({ + age: 66.32, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -0.669, // 67yrs + incomeAvailable: undefined, + income: 0, + yearsInCanadaSince18: 20, + maritalStatus: MaritalStatus.SINGLE, + invSeparated: undefined, + ...partnerUndefined, + ...canadian, + ...obsolete, + clientBirthDate: '1958;04', + }) + + const result = res.body.results + + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_ELIGIBLE) + expect(result.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(result.oas.entitlement.result).toBeCloseTo(376.4, 0.01) + }) + + it('SMKTST-25D', async () => { + const res = await mockGetRequest({ + age: 66.32, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -1.58, // 67yrs 11 months + incomeAvailable: undefined, + income: 0, + yearsInCanadaSince18: 20, + maritalStatus: MaritalStatus.SINGLE, + invSeparated: undefined, + ...partnerUndefined, + ...canadian, + ...obsolete, + clientBirthDate: '1958;04', + }) + + const result = res.body.results + + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_ELIGIBLE) + expect(result.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(result.oas.entitlement.result).toBeCloseTo(392.96, 0.01) + }) + + it('SMKTST-20B', async () => { + const res = await mockGetRequest({ + age: 68.75, + receiveOAS: false, + oasDeferDuration: undefined, + whenToStartOAS: false, + startDateForOAS: -0.58, // 69yrs 4 months + incomeAvailable: undefined, + income: 0, + yearsInCanadaSince18: 15, + maritalStatus: MaritalStatus.SINGLE, + invSeparated: undefined, + ...partnerUndefined, + ...canadian, + ...obsolete, + clientBirthDate: '1955;11', + }) + + const result = res.body.results + + expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_ELIGIBLE) + expect(result.oas.eligibility.result).toEqual(ResultKey.ELIGIBLE) + expect(result.oas.entitlement.result).toBeCloseTo(280.69, 0.01) + }) + // +}) diff --git a/utils/api/benefitHandler.ts b/utils/api/benefitHandler.ts index 7efa952c7..18f99b582 100644 --- a/utils/api/benefitHandler.ts +++ b/utils/api/benefitHandler.ts @@ -120,18 +120,6 @@ export class BenefitHandler { if (this.formYearsInCanada === undefined) this.formYearsInCanada = this.input.client.yearsInCanadaSince18 - console.log( - '### curr resid=', - this.input.client.yearsInCanadaSince18, - 'future', - this.future, - 'form age', - this.formAge, - 'form resid', - this.formYearsInCanada, - '###' - ) - // Future handler takes care of cases when partner is not yet eligible by creating "age sets" of future eligible ages // If partner was already eligible in the past based on residency, we need to adjust the inputs if (!this.future) { @@ -174,17 +162,6 @@ export class BenefitHandler { ) } - consoleDev( - '>>> benefitHandler', - this.input.client.startDateForOAS, - 'NewResidYrs', - this.input.client.yearsInCanadaSince18, - 'oasDeferDuration', - this.input.client.oasDeferDuration, - 'future', - this.future - ) - // If client selected a when to start OAS date then the client accumulates some extra months of residency // if date to start is greater than 12 months // full yrs are added to the residence @@ -203,19 +180,6 @@ export class BenefitHandler { this.input.client.oasDeferDuration = `{"months":${Math.round( futureMonths % 12 )}, "years": 0}` - - consoleDev( - '>>> MAX RESIDENCY startDateforOAS=', - this.input.client.startDateForOAS, - 'months=', - futureMonths, - 'form Resid', - this.formYearsInCanada, - 'NewResidYrs', - this.input.client.yearsInCanadaSince18, - 'oasDeferDuration', - this.input.client.oasDeferDuration - ) } const clientOasNoDeferral = new OasBenefit( @@ -252,7 +216,7 @@ export class BenefitHandler { clientOasNoDeferral.entitlement } - //consoleDev('NO DEFERRAL', clientOasNoDeferral) + consoleDev('NO DEFERRAL', clientOasNoDeferral) consoleDev( 'Client OAS amount NO deferral', clientOasNoDeferral.entitlement.result @@ -264,24 +228,12 @@ export class BenefitHandler { this.input.client.whenToStartOAS !== undefined && !this.input.client.whenToStartOAS ) { - console.log('yearsInCanada before', this.input.client.yearsInCanadaSince18) this.input.client.yearsInCanadaSince18 = this.formYearsInCanada - console.log('yearsInCanada after', this.input.client.yearsInCanadaSince18) } // Determines if it is possible to defer OAS and provides useful properties such as new inputs and deferral months to calculate the OAS deferred case const clientOasHelper = evaluateOASInput(this.input.client, this.formAge) - - consoleDev( - '>>> MAX DEFERRAL startDateforOAS=', - clientOasHelper.newInput.startDateForOAS, - 'age', - clientOasHelper.newInput.age, - 'ResidYrs', - clientOasHelper.newInput.yearsInCanadaSince18, - 'oasDeferDuration', - clientOasHelper.newInput.oasDeferDuration - ) + console.log('clientOasHelper', clientOasHelper) let clientOasWithDeferral if (clientOasHelper.canDefer) { @@ -299,7 +251,7 @@ export class BenefitHandler { this.input.client.age ) - //consoleDev('WITH DEFERRAL', clientOasWithDeferral) + consoleDev('WITH DEFERRAL', clientOasWithDeferral) consoleDev( 'Client OAS amount WITH deferral', clientOasWithDeferral.entitlement.result diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 58d3e5930..04348a6e3 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -262,12 +262,6 @@ export class OasBenefit extends BaseBenefit { const durationStr = this.input.oasDeferDuration if (durationStr) { - console.log( - '>>> oasBenefit Resid', - this.input.yearsInCanadaSince18, - 'defer', - durationStr - ) const duration: MonthsYears = JSON.parse(durationStr) const durationFloat = duration.years + duration.months / 12 oasAge = 65 + durationFloat diff --git a/utils/api/futureHandler.ts b/utils/api/futureHandler.ts index 726d7fc6c..75771b9a1 100644 --- a/utils/api/futureHandler.ts +++ b/utils/api/futureHandler.ts @@ -38,7 +38,6 @@ export class FutureHandler { private getSingleResults() { let result = this.futureResultsObj - console.log('@@ FutureHandler yearsInCanada', this.query.yearsInCanadaSince18) const yearsInCanada = Number(this.query.yearsInCanadaSince18) const age = Number(this.query.age) @@ -66,11 +65,9 @@ export class FutureHandler { this.newQuery['yearsInCanadaSince18'] = String( Math.min(40, eliObj.yearsOfResAtEligibility) ) - console.log('@@ FutureHandler #2 yearsInCanada', this.newQuery.yearsInCanadaSince18, eliObj.yearsOfResAtEligibility) } const { value } = schema.validate(this.newQuery, { abortEarly: false }) - console.log('@@ FutureHandler #3 yearsInCanada', value.yearsInCanadaSince18) const handler = new BenefitHandler( value, true, @@ -168,7 +165,6 @@ export class FutureHandler { Number(this.query.yearsInCanadaSinceOAS) const partnerRes = Number(this.query.partnerYearsInCanadaSince18) const partnerOnlyCanada = this.query.partnerLivedOnlyInCanada - console.log('@@ Future Married yearsInCanada', clientRes) const clientDeferralMeta = this.currentHandler.benefitResults?.client?.oas?.entitlement?.deferral const partnerDeferralMeta = @@ -212,7 +208,12 @@ export class FutureHandler { } // TODO when there is a StartFromDate the years need to be added to the array below - const futureAges = [...getAgeArray(agesInputObj), [76, 91]] + const futureAges = getAgeArray(agesInputObj) + + // const futureAges = [[68, 65]] + + // probably in the results, we should suppress any oas results for an age less than the desired start date + // TODO this.query is missing the residence years, and months delayed console.log('futureAges', futureAges) @@ -238,7 +239,6 @@ export class FutureHandler { partnerLockResidence ) const { value } = schema.validate(newQuery, { abortEarly: false }) - console.log('>>>> TEST Age', userAge, partnerAge, 'Res', value) const handler = new BenefitHandler( value, true, diff --git a/utils/api/helpers/utils.ts b/utils/api/helpers/utils.ts index dc61de79d..e8d90ca4b 100644 --- a/utils/api/helpers/utils.ts +++ b/utils/api/helpers/utils.ts @@ -272,6 +272,8 @@ export function evaluateOASInput(input, formAge) { const age = input.age // 66.42 const ageJuly2013 = calculate2013Age(age, input.clientBirthDate) + console.log('ageJuly2013', ageJuly2013) + const yearsInCanada = input.yearsInCanadaSince18 let eliObj = OasEligibility( @@ -281,6 +283,8 @@ export function evaluateOASInput(input, formAge) { input.livingCountry.value ) + console.log('eliObj', eliObj) // calculates age of eligibility as well as years of residence at eligibility + let newInput = { ...input } let deferralMonths @@ -310,39 +314,17 @@ export function evaluateOASInput(input, formAge) { // If Client age < 65 futureMonths will be converted into years and months discarting any months after 65 // Example: client age is 45.6 wants oas as of 65.6 => 240 months However at 65 he only have 234 montsh or 19 yrs and 6 months // - if (!input.whenToStartOAS) { - let futureMonths = input.startDateForOAS * 12 * -1 - - if (formAge >= 65) { - deferralMonths = deferralMonths + futureMonths - } else { - console.log("before ", eliObj.yearsOfResAtEligibility) - eliObj.yearsOfResAtEligibility = - eliObj.yearsOfResAtEligibility + Math.floor(65 - formAge) - console.log("after ", eliObj.yearsOfResAtEligibility) - deferralMonths = ((65 - formAge) * 12) % 12 - } - - consoleDev( - '### EvaluateOASInput startDateOAS', - input.startDateForOAS, - 'deferral', - Math.round((Math.min(70, age) - eliObj.ageOfEligibility) * 12), - 'startDate', - Math.round(futureMonths), - 'NEW deferral', - Math.round(deferralMonths), - 'age', - age, - 'ageJuly2013', - ageJuly2013, - 'formAge', - formAge, - 'elig Age,Resid', - eliObj.ageOfEligibility, - eliObj.yearsOfResAtEligibility - ) - } + // if (!input.whenToStartOAS) { + // let futureMonths = input.startDateForOAS * 12 * -1 + + // if (formAge >= 65) { + // deferralMonths = deferralMonths + futureMonths + // } else { + // eliObj.yearsOfResAtEligibility = + // eliObj.yearsOfResAtEligibility + Math.floor(65 - formAge) + // deferralMonths = ((65 - formAge) * 12) % 12 + // } + // } } } @@ -350,10 +332,6 @@ export function evaluateOASInput(input, formAge) { justBecameEligible = true } - if (age === eliObj.ageOfEligibility && age < 70) { - justBecameEligible = true - } - if (deferralMonths !== 0 && !input.receiveOAS) { canDefer = true newInput['inputAge'] = input.age diff --git a/utils/api/scrapers/output/legalValuesJson.json b/utils/api/scrapers/output/legalValuesJson.json index e77bfc818..18153c745 100644 --- a/utils/api/scrapers/output/legalValuesJson.json +++ b/utils/api/scrapers/output/legalValuesJson.json @@ -1,39 +1,39 @@ { "lastUpdatedYear": 2023, - "lastUpdatedQuarter": "July to September 2024", + "lastUpdatedQuarter": "October to December 2024", "renewalYearGIS": 2024, "oas": { - "amount": 718.33, - "amount75": 790.16, - "incomeLimit": 142609, - "incomeLimit75": 148179, - "clawbackIncomeLimit": 86912 + "amount": 727.67, + "amount75": 800.44, + "incomeLimit": 148451, + "incomeLimit75": 154196, + "clawbackIncomeLimit": 90997 }, "gis": { - "singleAmount": 1072.93, - "singleIncomeLimit": 21768, - "spouseOasAmount": 645.84, - "spouseOasIncomeLimit": 28752, - "spouseNoOasAmount": 1072.93, - "spouseNoOasIncomeLimit": 52176, - "spouseAlwAmount": 645.84, - "spouseAlwIncomeLimit": 40272 + "singleAmount": 1086.88, + "singleIncomeLimit": 22056, + "spouseOasAmount": 654.23, + "spouseOasIncomeLimit": 29136, + "spouseNoOasAmount": 1086.88, + "spouseNoOasIncomeLimit": 52848, + "spouseAlwAmount": 654.23, + "spouseAlwIncomeLimit": 40800 }, "alw": { - "alwAmount": 1364.17, - "alwIncomeLimit": 40272, - "afsAmount": 1626.2, - "afsIncomeLimit": 29328 + "alwAmount": 1381.9, + "alwIncomeLimit": 40800, + "afsAmount": 1647.34, + "afsIncomeLimit": 29712 }, "topUp": { - "single": 166.2, - "married": 47.09 + "single": 168.36, + "married": 47.7 }, "delay": { - "oas66": 770.05, - "oas67": 821.77, - "oas68": 873.49, - "oas69": 925.21, - "oas70": 976.93 + "oas66": 780.06, + "oas67": 832.45, + "oas68": 884.85, + "oas69": 937.24, + "oas70": 989.63 } }