Skip to content

Commit

Permalink
validation and error messages on partner residency if they lived in c…
Browse files Browse the repository at this point in the history
…anada or outside
  • Loading branch information
alex-solo committed Sep 19, 2024
1 parent dbd6f09 commit 8c450de
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions i18n/web/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ const en: WebTranslations = {
'This number must be at least 10 at the time you deferred your pension.',
[ValidationErrors.yearsNotInCanadaMinusDeferred]:
'This number must be at least 20 at the time you deferred your pension.',
[ValidationErrors.partnerResCanadaNotEnough10]:
'This number must be at least 10 because your partner receives the Old Age Security pension.',
[ValidationErrors.partnerResCanadaNotEnough20]:
'This number must be at least 20 because your partner receives the Old Age Security pension outside Canada.',
[ValidationErrors.legalStatusNotSelected]:
'Please indicate if you have legal status in Canada.',
[ValidationErrors.partnerLegalStatusNotSelected]:
Expand Down
4 changes: 4 additions & 0 deletions i18n/web/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ const fr: WebTranslations = {
'Ce nombre doit être au moins 10 au moment où vous avez reporté votre pension.',
[ValidationErrors.yearsNotInCanadaMinusDeferred]:
'Ce nombre doit être au moins 20 au moment où vous avez reporté votre pension.',
[ValidationErrors.partnerResCanadaNotEnough10]:
'Ce nombre doit être au moins 10 puisque votre conjoint reçoit la pension de la Sécurité de la vieillesse.',
[ValidationErrors.partnerResCanadaNotEnough20]:
'Ce nombre doit être au moins 20 puisque votre conjoint reçoit la pension de la Sécurité de la vieillesse à l’extérieur du Canada.',
[ValidationErrors.legalStatusNotSelected]:
'Veuillez indiquer si vous avez un statut légal au Canada.',
[ValidationErrors.partnerLegalStatusNotSelected]:
Expand Down
2 changes: 2 additions & 0 deletions utils/api/definitions/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export enum ValidationErrors {
yearsInCanadaMinusDeferred = 'yearsInCanadaMinusDeferred',
yearsNotInCanadaMinusDeferred = 'yearsNotInCanadaMinusDeferred',
partnerYearsInCanadaMinusAge = 'partnerYearsInCanadaMinusAge',
partnerResCanadaNotEnough10 = 'partnerResCanadaNotEnough10',
partnerResCanadaNotEnough20 = 'partnerResCanadaNotEnough20',
maritalUnavailable = 'maritalUnavailable',
legalUnavailable = 'legalUnavailable',
socialCountryUnavailable10 = 'socialCountryUnavailable10',
Expand Down
48 changes: 48 additions & 0 deletions utils/api/definitions/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,54 @@ export const RequestSchema = Joi.object({
.integer()
.max(Joi.ref('partnerAge', { adjust: (age) => age - 18 }))
.message(ValidationErrors.partnerYearsSince18Empty),
partnerYearsInCanadaSinceOAS: Joi.number()
.required()
.messages({ 'any.required': ValidationErrors.partnerYearsSince18Empty })
.custom((value, helpers) => {
const { partnerAge, partnerLivingCountry, partnerYearsInCanadaSinceOAS } =
helpers.state.ancestors[0]

if (value === 0) {
return helpers.message({
custom: ValidationErrors.partnerYearsSince18Empty,
})
}

if (partnerLivingCountry === LivingCountry.CANADA) {
if (partnerYearsInCanadaSinceOAS !== undefined) {
if (partnerYearsInCanadaSinceOAS < 10) {
return helpers.message({
custom: ValidationErrors.partnerResCanadaNotEnough10,
})
} else {
if (partnerAge > 0 && partnerYearsInCanadaSinceOAS !== undefined) {
if (partnerAge - 18 < partnerYearsInCanadaSinceOAS) {
return helpers.message({
custom: ValidationErrors.partnerYearsSince18Empty,
})
}
}
}
}
} else {
if (partnerYearsInCanadaSinceOAS !== undefined) {
if (partnerYearsInCanadaSinceOAS < 20) {
return helpers.message({
custom: ValidationErrors.partnerResCanadaNotEnough20,
})
} else {
if (partnerAge > 0 && partnerYearsInCanadaSinceOAS !== undefined) {
if (partnerAge - 18 < partnerYearsInCanadaSinceOAS) {
return helpers.message({
custom: ValidationErrors.partnerYearsSince18Empty,
})
}
}
}
}
}
return value
}, 'custom validation for the "partnerYearsInCanadaSinceOAS" question'),
_language: Joi.string()
.valid(...Object.values(Language))
.default(Language.EN),
Expand Down
4 changes: 3 additions & 1 deletion utils/api/futureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export class FutureHandler {
const clientRes =
Number(this.query.yearsInCanadaSince18) ||
Number(this.query.yearsInCanadaSinceOAS)
const partnerRes = Number(this.query.partnerYearsInCanadaSince18)
const partnerRes =
Number(this.query.partnerYearsInCanadaSince18) ||
Number(this.query.partnerYearsInCanadaSinceOAS)
const partnerOnlyCanada = this.query.partnerLivedOnlyInCanada

const clientDeferralMeta =
Expand Down

0 comments on commit 8c450de

Please sign in to comment.