Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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: 2 additions & 0 deletions src/main/app/case/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const formFieldsToCaseMapping: Partial<Record<keyof Case, keyof CaseData>
certifiedTranslation: 'marriageCertifiedTranslation',
ceremonyCountry: 'marriageCountryOfMarriage',
ceremonyPlace: 'marriagePlaceOfMarriage',
applicant1InRefuge: 'applicant1InRefuge',
applicant2InRefuge: 'applicant2InRefuge',
applicant1LifeBasedInEnglandAndWales: 'jurisdictionApplicant1Residence',
applicant2LifeBasedInEnglandAndWales: 'jurisdictionApplicant2Residence',
applicant1DomicileInEnglandWales: 'jurisdictionApplicant1Domicile',
Expand Down
39 changes: 4 additions & 35 deletions src/main/app/case/from-api-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,6 @@ describe('from-api-format', () => {
expect(fromApiFormat(formData as unknown as CaseData)).toMatchObject(expected);
});
describe('fromApiFormat - applicant2InRefuge transformation', () => {
test('defaults applicant2InRefuge to NO if undefined', () => {
const nfdivFormat = fromApiFormat({
applicant2InRefuge: undefined, // Simulate missing value
} as unknown as CaseData);

expect(nfdivFormat).toMatchObject({
applicant2InRefuge: YesOrNo.NO,
});
});

test('retains applicant2InRefuge value if set to YES', () => {
const nfdivFormat = fromApiFormat({
applicant2InRefuge: YesOrNo.YES, // Explicit value set
Expand All @@ -540,35 +530,15 @@ describe('from-api-format', () => {
});

test.each([
{ applicant2InRefuge: undefined, expected: YesOrNo.NO },
{ applicant2InRefuge: undefined, expected: undefined },
{ applicant2InRefuge: YesOrNo.YES, expected: YesOrNo.YES },
{ applicant2InRefuge: YesOrNo.NO, expected: YesOrNo.NO },
])('correctly handles applicant2InRefuge with value %p', ({ applicant2InRefuge, expected }) => {
const nfdivFormat = fromApiFormat({ applicant2InRefuge } as unknown as CaseData);
expect(nfdivFormat).toMatchObject({ applicant2InRefuge: expected });
});

test('handles null applicant2InRefuge gracefully', () => {
const nfdivFormat = fromApiFormat({
applicant2InRefuge: null, // Explicit null value
} as unknown as CaseData);

expect(nfdivFormat).toMatchObject({
applicant2InRefuge: YesOrNo.NO, // Defaults to NO
});
});
});
describe('fromApiFormat - applicant1InRefuge transformation', () => {
test('defaults applicant1InRefuge to NO if undefined', () => {
const nfdivFormat = fromApiFormat({
applicant1InRefuge: undefined, // Simulate missing value
} as unknown as CaseData);

expect(nfdivFormat).toMatchObject({
applicant1InRefuge: YesOrNo.NO,
});
});

test('retains applicant1InRefuge value if set to YES', () => {
const nfdivFormat = fromApiFormat({
applicant1InRefuge: YesOrNo.YES, // Explicit value set
Expand All @@ -578,7 +548,6 @@ describe('from-api-format', () => {
applicant1InRefuge: YesOrNo.YES,
});
});

test('retains applicant1InRefuge value if set to NO', () => {
const nfdivFormat = fromApiFormat({
applicant1InRefuge: YesOrNo.NO, // Explicit value set
Expand All @@ -590,7 +559,7 @@ describe('from-api-format', () => {
});

test.each([
{ applicant1InRefuge: undefined, expected: YesOrNo.NO },
{ applicant1InRefuge: undefined, expected: undefined },
{ applicant1InRefuge: YesOrNo.YES, expected: YesOrNo.YES },
{ applicant1InRefuge: YesOrNo.NO, expected: YesOrNo.NO },
])('correctly handles applicant1InRefuge with value %p', ({ applicant1InRefuge, expected }) => {
Expand All @@ -600,11 +569,11 @@ describe('from-api-format', () => {

test('handles null applicant1InRefuge gracefully', () => {
const nfdivFormat = fromApiFormat({
applicant1InRefuge: null, // Explicit null value
applicant1InRefuge: null,
} as unknown as CaseData);

expect(nfdivFormat).toMatchObject({
applicant1InRefuge: YesOrNo.NO, // Defaults to NO
applicant1InRefuge: null,
});
});
});
Expand Down
6 changes: 0 additions & 6 deletions src/main/app/case/from-api-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,12 @@ const fields: FromApiConverters = {
applicant1ContactDetailsType: ({ applicant1ContactDetailsType }) => ({
applicant1AddressPrivate: applicant1ContactDetailsType === ContactDetailsType.PRIVATE ? YesOrNo.YES : YesOrNo.NO,
}),
applicant1InRefuge: ({ applicant1InRefuge }) => ({
applicant1InRefuge: applicant1InRefuge ?? YesOrNo.NO,
}),
applicant1WantsToHavePapersServedAnotherWay: data => ({
iWantToHavePapersServedAnotherWay: checkboxConverter(data.applicant1WantsToHavePapersServedAnotherWay),
}),
applicant2ContactDetailsType: ({ applicant2ContactDetailsType }) => ({
applicant2AddressPrivate: applicant2ContactDetailsType === ContactDetailsType.PRIVATE ? YesOrNo.YES : YesOrNo.NO,
}),
applicant2InRefuge: ({ applicant2InRefuge }) => ({
applicant2InRefuge: applicant2InRefuge ?? YesOrNo.NO,
}),
applicant2Address: data => formatAddress(data, 'applicant2'),
applicant2AddressOverseas: ({ applicant2AddressOverseas }) => ({
applicant2AddressOverseas: applicant2AddressOverseas ?? YesOrNo.NO,
Expand Down
16 changes: 4 additions & 12 deletions src/main/app/case/to-api-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ describe('to-api-format', () => {

expect(apiFormat).toStrictEqual({
applicant1ContactDetailsType: ContactDetailsType.PUBLIC,
applicant1InRefuge: null,
applicant2InRefuge: null,
applicant1KnowsApplicant2EmailAddress: YesOrNo.YES,
applicant2ContactDetailsType: ContactDetailsType.PUBLIC,
applicant1PrayerDissolveDivorce: [],
Expand Down Expand Up @@ -296,7 +298,7 @@ describe('to-api-format', () => {
applicant2HWFReferenceNumber: '',
applicant1InterimAppsHwfRefNumber: '',
marriageDate: undefined,
applicant1InRefuge: YesOrNo.NO,
applicant1InRefuge: undefined,
applicant1AddressOverseas: YesOrNo.NO,
applicant2AddressOverseas: YesOrNo.NO,
applicant2SolicitorAddressOverseas: YesOrNo.NO,
Expand Down Expand Up @@ -810,16 +812,6 @@ describe('to-api-format', () => {
});

describe('applicant2InRefuge transformation', () => {
test('defaults applicant2InRefuge to NO if undefined', () => {
const apiFormat = toApiFormat({
applicant2InRefuge: undefined, // Simulate missing value
} as Partial<Case>);

expect(apiFormat).toMatchObject({
applicant2InRefuge: YesOrNo.NO,
});
});

test('retains applicant2InRefuge value if set', () => {
const apiFormatYes = toApiFormat({
applicant2InRefuge: YesOrNo.YES, // Simulate value is already set
Expand All @@ -839,7 +831,7 @@ describe('to-api-format', () => {
});

test.each([
{ applicant2InRefuge: undefined, expected: YesOrNo.NO },
{ applicant2InRefuge: undefined, expected: undefined },
{ applicant2InRefuge: YesOrNo.YES, expected: YesOrNo.YES },
{ applicant2InRefuge: YesOrNo.NO, expected: YesOrNo.NO },
])('correctly handles applicant2InRefuge with value %p', ({ applicant2InRefuge, expected }) => {
Expand Down
16 changes: 6 additions & 10 deletions src/main/app/case/to-api-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,18 @@ const fields: ToApiConverters = {
applicant2AgreeToReceiveEmails: data => ({
applicant2AgreedToReceiveEmails: checkboxConverter(data.applicant2AgreeToReceiveEmails),
}),
applicant1AddressPrivate: ({ applicant1AddressPrivate }) => ({
applicant1AddressPrivate: data => ({
applicant1ContactDetailsType:
applicant1AddressPrivate === YesOrNo.YES ? ContactDetailsType.PRIVATE : ContactDetailsType.PUBLIC,
}),
applicant1InRefuge: ({ applicant1InRefuge }) => ({
applicant1InRefuge: applicant1InRefuge ?? YesOrNo.NO, // Default to YesOrNo.NO if undefined
data.applicant1AddressPrivate === YesOrNo.YES ? ContactDetailsType.PRIVATE : ContactDetailsType.PUBLIC,
...(data.applicant1AddressPrivate === YesOrNo.NO ? setUnreachableAnswersToNull(['applicant1InRefuge']) : {}),
}),
applicant1AddressOverseas: ({ applicant1AddressOverseas }) => ({
applicant1AddressOverseas: applicant1AddressOverseas ?? YesOrNo.NO,
}),
applicant2AddressPrivate: ({ applicant2AddressPrivate }) => ({
applicant2AddressPrivate: data => ({
applicant2ContactDetailsType:
applicant2AddressPrivate === YesOrNo.YES ? ContactDetailsType.PRIVATE : ContactDetailsType.PUBLIC,
}),
applicant2InRefuge: ({ applicant2InRefuge }) => ({
applicant2InRefuge: applicant2InRefuge ?? YesOrNo.NO, // Default to YesOrNo.NO if undefined
data.applicant2AddressPrivate === YesOrNo.YES ? ContactDetailsType.PRIVATE : ContactDetailsType.PUBLIC,
...(data.applicant2AddressPrivate === YesOrNo.NO ? setUnreachableAnswersToNull(['applicant2InRefuge']) : {}),
}),
applicant2AddressPostcode: applicant2AddressToApi,
applicant1DoesNotKnowApplicant2EmailAddress: data => ({
Expand Down
30 changes: 1 addition & 29 deletions src/main/steps/applicant1/address-private/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,22 @@ import { TranslationFn } from '../../../app/controller/GetController';
import { FormContent } from '../../../app/form/Form';
import { isFieldFilledIn } from '../../../app/form/validation';
import { CommonContent } from '../../common/common.content';
import { InputLabelsByLanguage, ydwOrNacYdwRadioAnswers } from '../../common/input-labels.content';
import { InputLabelsByLanguage } from '../../common/input-labels.content';

const en = ({ partner, required }: CommonContent) => ({
title: `Do you need your contact details kept private from your ${partner}?`,
line1: `The court can keep your address, email address and phone number private from your ${partner}.`,
detailsPrivateMoreDetails: 'If you think you might be experiencing domestic abuse or you feel unsafe, then',
supportAvailable: 'support is available',
errors: {
applicant1AddressPrivate: { required },
applicant1InRefuge: { required },
},
inRefugeLabel: 'Are you currently in a refuge?', // Label for the 'inRefuge' question
});

const cy: typeof en = ({ partner, required }: CommonContent) => ({
title: `A oes arnoch angen cadw eich manylion cyswllt yn breifat oddi wrth eich ${partner}?`,
line1: `Gall y llys gadw eich cyfeiriad, eich cyfeiriad e-bost a'ch rhif ffôn yn breifat oddi wrth eich ${partner}.`,
detailsPrivateMoreDetails:
"Os credwch eich bod efallai'n profi cam-drin domestig neu os nad ydych yn teimlo'n ddiogel, yna",
supportAvailable: 'mae cymorth ar gael',
errors: {
applicant1AddressPrivate: { required },
applicant1InRefuge: { required },
},
inRefugeLabel: 'Ydych chi’n preswylio mewn lloches ar hyn o bryd?',
});

export const form: FormContent = {
Expand All @@ -41,21 +32,6 @@ export const form: FormContent = {
{
label: l => l.detailsPrivate,
value: YesOrNo.YES,
conditionalText: l =>
`<p class="govuk-label">${l.detailsPrivateMoreDetails} <a class="govuk-link" href="https://www.gov.uk/guidance/domestic-abuse-how-to-get-help">${l.supportAvailable}</a></p>`,
subFields: {
applicant1InRefuge: {
id: 'inRefuge',
type: 'radios',
classes: 'govuk-radios--inline',
label: l => l.inRefugeLabel,
values: [
{ label: l => l[YesOrNo.YES], value: YesOrNo.YES },
{ label: l => l[YesOrNo.NO], value: YesOrNo.NO },
],
validator: value => isFieldFilledIn(value), // Only validate if this field is shown
},
},
Comment thread
IswaryaPepakayala marked this conversation as resolved.
},
{
label: l => l.detailsNotPrivate,
Expand All @@ -75,8 +51,6 @@ const languages = {
cy,
};

export const radioButtonAnswersRefuge = ydwOrNacYdwRadioAnswers;

export const radioButtonAnswersPrivate: InputLabelsByLanguage<YesOrNo> = {
en: {
[YesOrNo.YES]: 'Keep my contact details private',
Expand All @@ -90,11 +64,9 @@ export const radioButtonAnswersPrivate: InputLabelsByLanguage<YesOrNo> = {

export const generateContent: TranslationFn = (content: CommonContent) => {
const translations = languages[content.language](content);
const radioAnswersRefuge = radioButtonAnswersRefuge[content.language];
const radioAnswersPrivate = radioButtonAnswersPrivate[content.language];
return {
...translations,
...radioAnswersRefuge,
detailsPrivate: radioAnswersPrivate[YesOrNo.YES],
detailsNotPrivate: radioAnswersPrivate[YesOrNo.NO],
form,
Expand Down
121 changes: 0 additions & 121 deletions src/main/steps/applicant1/address-private/post.test.ts

This file was deleted.

Loading