Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,19 @@ export function buildEntryUpdateDtoFromForm(
respondentOrgValue,
) as unknown as Partial<EntryUpdateDto>;

// Merge server snapshot with patch from form
return {
const dto: EntryUpdateDto = {
...base,
...patch,
};

if (formValue.applicantType === 'standard') {
dto.standardApplicantCode = (formValue.standardApplicantCode ?? '').trim();
delete dto.applicant;
} else {
delete dto.standardApplicantCode;
}

return dto;
}

export function buildContactDetailsFromRaw(v: ContactFormRaw): ContactDetails {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { FormBuilder } from '@angular/forms';

import {
buildEntryUpdateDtoFromForm,
buildOrganisationForm,
buildPersonForm,
buildPersonOrgSharedControls,
buildStandardApplicationForm,
getRespondentEntryType,
} from '@components/applications-list-entry-detail/util/entry-detail.form';
import type { Organisation, Person, Respondent } from '@openapi';
import type {
EntryGetDetailDto,
Organisation,
Person,
Respondent,
} from '@openapi';

describe('applications-list entry form builders', () => {
const fb = new FormBuilder().nonNullable;
Expand Down Expand Up @@ -192,4 +198,114 @@ describe('applications-list entry form builders', () => {
expect(getRespondentEntryType(r)).toBeNull();
});
});

describe('buildEntryUpdateDtoFromForm', () => {
const personApplicant = {
person: {
name: {
firstForename: 'Jane',
surname: 'Doe',
},
contactDetails: {
addressLine1: '1 Street',
},
},
};

const baseDetail: EntryGetDetailDto = {
applicationCode: 'APP-100',
standardApplicantCode: 'STD-OLD',
applicant: personApplicant,
respondent: undefined,
numberOfRespondents: undefined,
feeStatuses: undefined,
hasOffsiteFee: undefined,
caseReference: undefined,
accountNumber: undefined,
notes: undefined,
lodgementDate: '2025-01-01',
} as unknown as EntryGetDetailDto;

const blankPerson = {
title: null,
firstName: '',
middleNames: '',
surname: null,
addressLine1: '',
addressLine2: '',
addressLine3: '',
addressLine4: '',
addressLine5: '',
postcode: null,
phoneNumber: null,
mobileNumber: null,
emailAddress: null,
};

const blankOrg = {
name: '',
addressLine1: '',
addressLine2: '',
addressLine3: '',
addressLine4: '',
addressLine5: '',
postcode: null,
phoneNumber: null,
mobileNumber: null,
emailAddress: null,
};

it('clears applicant when applicantType is standard', () => {
const dto = buildEntryUpdateDtoFromForm(
baseDetail,
{
applicantType: 'standard',
standardApplicantCode: ' STD-123 ',
applicationCode: 'APP-100',
respondentEntryType: 'person',
applicationNotes: {
notes: null,
caseReference: null,
accountReference: null,
},
} as never,
blankPerson as never,
blankOrg as never,
blankPerson as never,
blankOrg as never,
);

expect(dto.standardApplicantCode).toBe('STD-123');
expect('applicant' in dto).toBe(false);
});

it('clears stale standardApplicantCode when applicantType is person', () => {
const dto = buildEntryUpdateDtoFromForm(
baseDetail,
{
applicantType: 'person',
standardApplicantCode: 'STD-OLD',
applicationCode: 'APP-100',
respondentEntryType: 'person',
applicationNotes: {
notes: null,
caseReference: null,
accountReference: null,
},
} as never,
{
...blankPerson,
firstName: 'John',
surname: 'Smith',
addressLine1: '1 Street',
} as never,
blankOrg as never,
blankPerson as never,
blankOrg as never,
);

expect(dto.applicant?.person?.name?.firstForename).toBe('John');
expect('standardApplicantCode' in dto).toBe(false);
});
});
});
Loading