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

Sync develop with Main for release candidate v1.5.0 #1117

Merged
merged 9 commits into from
Nov 20, 2024
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
7 changes: 2 additions & 5 deletions __tests__/pages/api/benefits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,7 @@ describe('consolidated benefit tests: eligible: 60-64', () => {
})

expect(res.body.summary.state).toEqual('MORE_INFO')
expect(res.body.missingFields).toEqual([
'everLivedSocialCountry',
'partnerLegalStatus',
])
expect(res.body.missingFields).toEqual(['everLivedSocialCountry'])
})

it('returns "ALW eligible" - married, living in No Agreement, 10 years in Canada', async () => {
Expand Down Expand Up @@ -988,6 +985,6 @@ describe('consolidated benefit tests: eligible: 60-64', () => {
})

expect(res.status).toEqual(400)
expect(res.body.missingFields).toEqual(['partnerLegalStatus'])
expect(res.body.missingFields).toEqual([])
})
})
34 changes: 18 additions & 16 deletions __tests__/pages/api/field-reqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ describe('field requirement analysis', () => {
})
expect(res.body.summary.state).toEqual(SummaryState.MORE_INFO)
expect(res.body.missingFields).toEqual([
FieldKey.MARITAL_STATUS,
FieldKey.AGE,
FieldKey.INCOME,
//FieldKey.INCOME_WORK,
FieldKey.LEGAL_STATUS,
FieldKey.INCOME_WORK,
// FieldKey.LEGAL_STATUS,
FieldKey.LIVING_COUNTRY,
FieldKey.LIVED_ONLY_IN_CANADA,
FieldKey.MARITAL_STATUS,
])
expect(res.body.visibleFields).toEqual([
FieldKey.MARITAL_STATUS,
FieldKey.AGE,
FieldKey.INCOME,
FieldKey.INCOME_WORK,
FieldKey.LEGAL_STATUS,
// FieldKey.LEGAL_STATUS,
FieldKey.LIVING_COUNTRY,
FieldKey.LIVED_ONLY_IN_CANADA,
FieldKey.MARITAL_STATUS,
])
})

Expand Down Expand Up @@ -83,30 +83,30 @@ describe('field requirement analysis', () => {
partnerYearsInCanadaSince18: 5,
})
// expect(res.body.summary.state).toEqual(SummaryState.AVAILABLE_ELIGIBLE)
expect(res.body.missingFields).toEqual([])
expect(res.body.missingFields).toEqual(['partnerYearsInCanadaSinceOAS'])
expect(res.body.visibleFields).toEqual([
FieldKey.MARITAL_STATUS,
FieldKey.INV_SEPARATED,
FieldKey.AGE,
FieldKey.ALREADY_RECEIVE_OAS,
FieldKey.OAS_AGE,
// FieldKey.INCOME_AVAILABLE,
FieldKey.PARTNER_AGE,
FieldKey.PARTNER_BENEFIT_STATUS,
FieldKey.INCOME,
FieldKey.INCOME_WORK,
FieldKey.LEGAL_STATUS,
FieldKey.PARTNER_INCOME,
FieldKey.PARTNER_INCOME_WORK,
// FieldKey.LEGAL_STATUS,
FieldKey.LIVING_COUNTRY,
FieldKey.LIVED_ONLY_IN_CANADA,
FieldKey.YEARS_IN_CANADA_SINCE_18,
// FieldKey.EVER_LIVED_SOCIAL_COUNTRY, // this field is odd because when visible, no matter what is selected it will return an error
FieldKey.MARITAL_STATUS,
FieldKey.INV_SEPARATED,
FieldKey.PARTNER_AGE,
// FieldKey.PARTNER_INCOME_AVAILABLE,
FieldKey.PARTNER_INCOME,
FieldKey.PARTNER_INCOME_WORK,
// FieldKey.PARTNER_BENEFIT_STATUS,
FieldKey.PARTNER_LEGAL_STATUS,
// FieldKey.PARTNER_LEGAL_STATUS,
FieldKey.PARTNER_LIVING_COUNTRY,
FieldKey.PARTNER_LIVED_ONLY_IN_CANADA,
FieldKey.PARTNER_YEARS_IN_CANADA_SINCE_18,
FieldKey.PARTNER_YEARS_IN_CANADA_SINCE_OAS,
FieldKey.OAS_AGE,
])
})
})
Expand Down Expand Up @@ -196,6 +196,8 @@ describe('field requirements analysis: conditional fields', () => {
FieldKey.INV_SEPARATED,
FieldKey.PARTNER_AGE,
FieldKey.PARTNER_INCOME,
FieldKey.PARTNER_LIVING_COUNTRY,
FieldKey.PARTNER_LIVED_ONLY_IN_CANADA,
])
// expect(res.body.visibleFields).toContain(FieldKey.PARTNER_INCOME_AVAILABLE)
expect(res.body.visibleFields).toContain(FieldKey.PARTNER_AGE)
Expand Down
94 changes: 1 addition & 93 deletions __tests__/pages/api/gisCoupleOnePenBenefit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('gisCoupleOnePenBenefit', () => {
const res = await mockGetRequest(extractedPayload)

//client results
expectOasEligible(res, EntitlementResultType.FULL, 1045.11)
// expectOasEligible(res, EntitlementResultType.FULL, 1045.11)
expectGisEligible(res, 651.45)
expectAlwTooOld(res)
expectAlwsMarital(res)
Expand All @@ -104,50 +104,6 @@ describe('gisCoupleOnePenBenefit', () => {
expectAllIneligible(res, true)
})

/* CALC-51 */
it('should pass 51 test - CALC-51', async () => {
const desiredName = 'CALC-51' // Replace with the desired name
const extractedPayload = getTransformedPayloadByName(filePath, desiredName)

const res = await mockGetRequest(extractedPayload)

//client results
expectOasEligible(res, EntitlementResultType.FULL, 768.46)
expectGisEligible(res, 0.82)
expectAlwTooOld(res)
expectAlwsMarital(res)

//Future Benefit
expectFutureOasGisBenefitEligible(res, 82, 768.46, 0.82, 0)
expectFutureOasGisBenefitEligible(res, 87, 768.46, 0.0, 1)

//partner results
expectAllIneligible(res, true)

//Future Benefit
expectFutureAwlBenefitEligible(res, 60, 0.0, true)
expectFutureOasGisBenefitEligible(res, 65, 698.6, 0.0, 1, true)
})

/* CALC-52 */
it('should pass 52 test - CALC-52', async () => {
const desiredName = 'CALC-52' // Replace with the desired name
const extractedPayload = getTransformedPayloadByName(filePath, desiredName)
const res = await mockGetRequest(extractedPayload)

//client results
expectOasEligible(res, EntitlementResultType.PARTIAL, 882.19)
expectGisEligible(res, 0)
expect(res.body.results.gis.eligibility.reason).toEqual(ResultReason.INCOME)
expectAlwTooOld(res)
expectAlwsMarital(res)

//partner results
expectOasNotEligible(res, true)
expectGisNotEligible(res, ResultReason.OAS, true)
expectAlwTooOld(res, true)
})

/* CALC-53 */
it('should pass 53 test - CALC-53', async () => {
const desiredName = 'CALC-53' // Replace with the desired name
Expand Down Expand Up @@ -475,35 +431,6 @@ describe('gisCoupleOnePenBenefit', () => {
expectFutureOasGisBenefitEligible(res, 71, 174.65, 1297.4, 0, true)
})

/* CALC-68 */
it('should pass 68 test - CALC-68', async () => {
const desiredName = 'CALC-68' // Replace with the desired name
const extractedPayload = getTransformedPayloadByName(filePath, desiredName)
const res = await mockGetRequest(extractedPayload)
const deferralTable = [
{ age: 69, amount: 472.39 },
{ age: 70, amount: 498.8 },
]

//client results
expectOasEligible(res, EntitlementResultType.PARTIAL, 461.39)
expectDeferralTable(res, deferralTable)
expectGisEligible(res, 983.28)
expectAlwTooOld(res)
expectAlwsMarital(res)

//Future Benefit
expectFutureOasGisBenefitEligible(res, 69.58, 461.39, 400.65, 0)
expectFutureOasGisBenefitEligible(res, 74.58, 461.39, 400.65, 1)

//partner results
expectAllIneligible(res, true)

//Future Benefit
expectFutureAwlBenefitEligible(res, 60, 1326.69, true)
expectFutureOasGisBenefitEligible(res, 65, 698.6, 1043.45, 1, true)
})

/* CALC-69 */
it('should pass 69 test - CALC-69', async () => {
const desiredName = 'CALC-69' // Replace with the desired name
Expand All @@ -528,23 +455,4 @@ describe('gisCoupleOnePenBenefit', () => {
expectGisEligible(res, 0.0, true)
expectAlwTooOld(res, true)
})

/* CALC-70 */
it('should pass 70 test - CALC-70', async () => {
const desiredName = 'CALC-70' // Replace with the desired name
const extractedPayload = getTransformedPayloadByName(filePath, desiredName)
const res = await mockGetRequest(extractedPayload)

//client results
expectOasEligible(res, EntitlementResultType.PARTIAL, 458.28)
expectGisEligible(res, 0)
expect(res.body.results.gis.eligibility.reason).toEqual(ResultReason.INCOME)
expectAlwTooOld(res)
expectAlwsMarital(res)

//partner results
expectOasNotEligible(res, true)
expectGisNotEligible(res, ResultReason.OAS, true)
expectAlwTooOld(res, true)
})
})
2 changes: 2 additions & 0 deletions __tests__/pages/api/oasBenefit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ it('should pass the second test - OAS-CALC-02', async () => {
expectGisNotEligible(res, ResultReason.OAS, true)
expectAlwTooOld(res, true)
})

/* CALC-06 */
it('should pass the 06 test - OAS-CALC-06', async () => {
const desiredName = 'CALC-6' // Replace with the desired name
Expand Down Expand Up @@ -245,6 +246,7 @@ it('should pass the second test - OAS-CALC-02', async () => {
expectGisNotEligible(res, ResultReason.OAS, true)
expectAlwTooOld(res, true)
})

/* CALC-15 */
it('should pass the 15 test - OAS-CALC-15', async () => {
const desiredName = 'CALC-15' // Replace with the desired name
Expand Down
4 changes: 2 additions & 2 deletions __tests__/pages/questions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('index page', () => {
useRouter = jest.spyOn(nextRouter, 'useRouter')
useRouter.mockImplementation(() => ({
route: '/questions',
pathname: '/questions?income=20000',
query: { income: '20000' },
pathname: '/questions',
query: { income: '20000', step: 'marital' },
asPath: '',
locale: 'en',
locales: ['en', 'fr'],
Expand Down
Binary file modified __tests__/utils/ScenariosWith2023Q3RatesAndThresholds.xlsx
Binary file not shown.
22 changes: 20 additions & 2 deletions __tests__/utils/excelReaderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export function getTransformedPayloadByName(
const data = readExcelData(filePath)
const rowToTransform = data.find((row) => row['Scenario'] === testName) // Assuming "testName" column is represented by "Column1"

//console.log('Extracted rowToTransform:', rowToTransform)

if (rowToTransform) {
const transformedPayload = createTransformedPayload(rowToTransform)
return transformedPayload
Expand Down Expand Up @@ -152,6 +150,24 @@ function createTransformedPayload(rowToTransform: string): Record<string, any> {
],
rowToTransform['Partner Birth Year and Month']
),
partnerYearsInCanadaSinceOAS:
transformLiveOnlyCanadaValue(
rowToTransform[
'Partner: # of years resided in Canada after age 18 (Full, 40, 10, etc.)'
]
) !== 'true'
? transformValue(
rowToTransform["Partner Rec'ing OAS (Yes / No / IDK)"]
) === 'true'
? transformYearsInCanadaSinceOAS18Value(
rowToTransform['Partner Age'],
rowToTransform[
'Partner: # of years resided in Canada after age 18 (Full, 40, 10, etc.)'
],
rowToTransform['Partner Birth Year and Month']
)
: undefined
: undefined,
}
payload = Object.fromEntries(
Object.entries(payload).filter(
Expand Down Expand Up @@ -244,6 +260,8 @@ function transformPartnerBenefitStatusValue(value: string): String {
return PartnerBenefitStatus.HELP_ME
} else if (value.toUpperCase() === 'NO') {
return PartnerBenefitStatus.NONE
} else if (value.toUpperCase() === 'N/A') {
return PartnerBenefitStatus.HELP_ME
}
return undefined
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/expectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ export const partnerUndefined = {
}

export const partnerNoHelpNeeded = {
partnerLivingCountry: undefined,
partnerLivingCountry: 'CAN',
partnerLegalStatus: undefined,
partnerLivedOnlyInCanada: undefined,
partnerLivedOnlyInCanada: true,
partnerYearsInCanadaSince18: undefined,
}

Expand Down
28 changes: 26 additions & 2 deletions client-state/Form.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import Joi from 'joi'
import { getWebTranslations, WebTranslations } from '../i18n/web'
import { BenefitHandler } from '../utils/api/benefitHandler'
import { FieldsHandler } from '../utils/api/fieldsHandler'
import { Language, ValidationErrors } from '../utils/api/definitions/enums'
import {
FieldConfig,
FieldKey,
FieldType,
} from '../utils/api/definitions/fields'
import { VisibleFieldsObject } from '../utils/web/types'
import { ResponseError, ResponseSuccess } from '../utils/api/definitions/types'
import { FieldsHandler } from '../utils/api/fieldsHandler'
import MainHandler from '../utils/api/mainHandler'
import { VisibleFieldsObject } from '../utils/web/types'
import { FormField } from './FormField'
import { InputHelper } from './InputHelper'

export class Form {
public readonly allFieldConfigs: FieldConfig[]
public readonly fields: FormField[]

private results: ResponseSuccess | ResponseError
private localInputs: InputHelper

constructor(
private readonly language: Language,
inputHelper: InputHelper,
Expand All @@ -30,6 +34,9 @@ export class Form {

update(inputs: InputHelper) {
const data = new MainHandler(inputs.asObjectWithLanguage).results
this.results = data
this.localInputs = inputs

this.clearAllErrors()

// set visibility of fields
Expand Down Expand Up @@ -85,6 +92,23 @@ export class Form {
}
}

writeToSessionStorage(): void {
try {
if (this.results && this.localInputs) {
sessionStorage.setItem(
'calculationResults',
JSON.stringify(this.results)
)
sessionStorage.setItem(
'resultPageInputs',
JSON.stringify(this.localInputs)
)
}
} catch (error) {
console.error('Error writing to sessionStorage:', error)
}
}

get visibleFields(): FormField[] {
return this.fields.filter((value) => value.visible)
}
Expand Down
Loading
Loading