Skip to content
Open
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 @@ -201,5 +201,43 @@ describe('Create acquisition model tests', () => {
} as ApiGen_Concepts_AcquisitionFileTeam),
);
});

it('omits notice of claim when date and comment are empty strings', () => {
const model = new AcquisitionForm();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: '',
receivedDate: '',
rowVersion: null,
};

const apiAcquisitionFile = model.toApi();

expect(apiAcquisitionFile.noticeOfClaim).toEqual([]);
});

it('normalizes notice of claim values before sending to api', () => {
const model = new AcquisitionForm();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: ' Test comment ',
receivedDate: '',
rowVersion: null,
};

const apiAcquisitionFile = model.toApi();

expect(apiAcquisitionFile.noticeOfClaim).toHaveLength(1);
expect(apiAcquisitionFile.noticeOfClaim?.[0]).toEqual(
expect.objectContaining({
comment: 'Test comment',
receivedDate: null,
}),
);
});
});
});
17 changes: 15 additions & 2 deletions source/frontend/src/features/mapSideBar/acquisition/add/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
stringToNumberOrNull,
toTypeCodeNullable,
} from '@/utils/formUtils';
import { exists, isValidId, isValidIsoDateTime } from '@/utils/utils';
import { exists, isValidId, isValidIsoDateTime, isValidString } from '@/utils/utils';

import { PropertyForm } from '../../shared/models';
import { ChecklistItemFormModel } from '../../shared/tabs/checklist/update/models';
Expand Down Expand Up @@ -81,6 +81,19 @@ export class AcquisitionForm implements WithAcquisitionTeam, WithAcquisitionOwne
toApi(): ApiGen_Concepts_AcquisitionFile {
const fileProperties = this.properties.map(x => this.toPropertyApi(x));
const sortedProperties = applyDisplayOrder(fileProperties);
const noticeOfClaim: ApiGen_Concepts_NoticeOfClaim | null = this.noticeOfClaim
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use exists()

? {
...this.noticeOfClaim,
receivedDate: isValidString(this.noticeOfClaim?.receivedDate)
? this.noticeOfClaim.receivedDate
: null,
comment: isValidString(this.noticeOfClaim?.comment?.trim())
? this.noticeOfClaim.comment.trim()
: null,
}
: null;
const hasNoticeOfClaim =
isValidString(noticeOfClaim?.receivedDate) || isValidString(noticeOfClaim?.comment);

return {
id: this.id ?? 0,
Expand Down Expand Up @@ -136,7 +149,7 @@ export class AcquisitionForm implements WithAcquisitionTeam, WithAcquisitionOwne
legacyStakeholders: null,
product: null,
project: null,
noticeOfClaim: exists(this.noticeOfClaim) ? [this.noticeOfClaim] : [],
noticeOfClaim: hasNoticeOfClaim && noticeOfClaim ? [noticeOfClaim] : [],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
noticeOfClaim: hasNoticeOfClaim && noticeOfClaim ? [noticeOfClaim] : [],
noticeOfClaim: hasNoticeOfClaim && exists(noticeOfClaim) ? [noticeOfClaim] : [],

...getEmptyBaseAudit(this.rowVersion),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const UpdateAcquisitionFileYupSchema = yup
.nullable()
.max(2000, 'Physical file details must be at most ${max} characters'),
noticeOfClaim: yup.object().shape({
comment: yup.string().max(4000, 'Notice of claim comment must be at most ${max} characters'),
comment: yup
.string()
.nullable()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this nullable validation should be added to AddAcquisitionFileYupSchema.ts as well - right?

.max(4000, 'Notice of claim comment must be at most ${max} characters'),
}),
})
.concat(UpdateAcquisitionTeamYupSchema)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { UpdateAcquisitionSummaryFormModel } from './models';

describe('UpdateAcquisitionSummaryFormModel', () => {
describe('toApi noticeOfClaim handling', () => {
it('omits noticeOfClaim when date and comment are empty', () => {
const model = new UpdateAcquisitionSummaryFormModel();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: '',
receivedDate: '',
rowVersion: null,
};

const apiModel = model.toApi();

expect(apiModel.noticeOfClaim).toEqual([]);
});

it('normalizes empty date to null and trims comment', () => {
const model = new UpdateAcquisitionSummaryFormModel();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: ' file update comment ',
receivedDate: '',
rowVersion: null,
};

const apiModel = model.toApi();

expect(apiModel.noticeOfClaim).toHaveLength(1);
expect(apiModel.noticeOfClaim?.[0]).toEqual(
expect.objectContaining({
comment: 'file update comment',
receivedDate: null,
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ApiGen_Concepts_InterestHolder } from '@/models/api/generated/ApiGen_Co
import { ApiGen_Concepts_NoticeOfClaim } from '@/models/api/generated/ApiGen_Concepts_NoticeOfClaim';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { fromTypeCode, fromTypeCodeNullable, toTypeCodeNullable } from '@/utils/formUtils';
import { exists, isValidId, isValidIsoDateTime } from '@/utils/utils';
import { exists, isValidId, isValidIsoDateTime, isValidString } from '@/utils/utils';

import {
AcquisitionOwnerFormModel,
Expand Down Expand Up @@ -79,6 +79,20 @@ export class UpdateAcquisitionSummaryFormModel
noticeOfClaim: ApiGen_Concepts_NoticeOfClaim;

toApi(): ApiGen_Concepts_AcquisitionFile {
const noticeOfClaim: ApiGen_Concepts_NoticeOfClaim | null = this.noticeOfClaim
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: same comments regarding exists()

? {
...this.noticeOfClaim,
receivedDate: isValidString(this.noticeOfClaim?.receivedDate)
? this.noticeOfClaim.receivedDate
: null,
comment: isValidString(this.noticeOfClaim?.comment?.trim())
? this.noticeOfClaim.comment.trim()
: null,
}
: null;
const hasNoticeOfClaim =
isValidString(noticeOfClaim?.receivedDate) || isValidString(noticeOfClaim?.comment);

return {
id: this.id || 0,
parentAcquisitionFileId: isValidId(this.parentAcquisitionFileId)
Expand Down Expand Up @@ -143,7 +157,7 @@ export class UpdateAcquisitionSummaryFormModel
product: null,
project: null,
totalAllowableCompensation: null,
noticeOfClaim: exists(this.noticeOfClaim) ? [this.noticeOfClaim] : [],
noticeOfClaim: hasNoticeOfClaim && noticeOfClaim ? [noticeOfClaim] : [],
...getEmptyBaseAudit(this.rowVersion),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ManagementFormModel } from './ManagementFormModel';

describe('ManagementFormModel', () => {
describe('toApi noticeOfClaim handling', () => {
it('omits noticeOfClaim when date and comment are empty', () => {
const model = new ManagementFormModel();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: '',
receivedDate: '',
rowVersion: null,
};

const apiModel = model.toApi();

expect(apiModel.noticeOfClaim).toEqual([]);
});

it('normalizes empty date to null and trims comment', () => {
const model = new ManagementFormModel();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: ' comment from formik ',
receivedDate: '',
rowVersion: null,
};

const apiModel = model.toApi();

expect(apiModel.noticeOfClaim).toHaveLength(1);
expect(apiModel.noticeOfClaim?.[0]).toEqual(
expect.objectContaining({
comment: 'comment from formik',
receivedDate: null,
}),
);
});

it('keeps receivedDate when provided and normalizes empty comment', () => {
const model = new ManagementFormModel();
model.noticeOfClaim = {
id: null,
acquisitionFileId: null,
managementFileId: null,
comment: ' ',
receivedDate: '2026-04-17',
rowVersion: null,
};

const apiModel = model.toApi();

expect(apiModel.noticeOfClaim).toHaveLength(1);
expect(apiModel.noticeOfClaim?.[0]).toEqual(
expect.objectContaining({
comment: null,
receivedDate: '2026-04-17',
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ApiGen_Concepts_NoticeOfClaim } from '@/models/api/generated/ApiGen_Con
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { applyDisplayOrder } from '@/utils';
import { fromTypeCode, toNullableId, toTypeCodeNullable } from '@/utils/formUtils';
import { exists, isValidId } from '@/utils/utils';
import { exists, isValidId, isValidString } from '@/utils/utils';

import { PropertyForm } from '../../shared/models';
import { ManagementTeamSubFormModel, WithManagementTeam } from './ManagementTeamSubFormModel';
Expand Down Expand Up @@ -50,6 +50,19 @@ export class ManagementFormModel implements WithManagementTeam {
const sortedProperties = applyDisplayOrder(fileProperties);
const personId = this.responsiblePayer?.personId ?? null;
const organizationId = !personId ? this.responsiblePayer?.organizationId ?? null : null;
const noticeOfClaim: ApiGen_Concepts_NoticeOfClaim | null = this.noticeOfClaim
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments re: exists()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also AddManagementFormYupSchema needs to be updated with nullable comment field

? {
...this.noticeOfClaim,
receivedDate: isValidString(this.noticeOfClaim?.receivedDate)
? this.noticeOfClaim.receivedDate
: null,
comment: isValidString(this.noticeOfClaim?.comment?.trim())
? this.noticeOfClaim.comment.trim()
: null,
}
: null;
const hasNoticeOfClaim =
isValidString(noticeOfClaim?.receivedDate) || isValidString(noticeOfClaim?.comment);

return {
id: this.id ?? 0,
Expand Down Expand Up @@ -81,7 +94,8 @@ export class ManagementFormModel implements WithManagementTeam {
.filter(exists),
fileProperties: sortedProperties ?? [],
...getEmptyBaseAudit(this.rowVersion),
noticeOfClaim: exists(this.noticeOfClaim) ? [this.noticeOfClaim] : [],
noticeOfClaim: hasNoticeOfClaim && noticeOfClaim ? [noticeOfClaim] : [],
...getEmptyBaseAudit(this.rowVersion),
};
}

Expand Down
Loading