diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/models.test.ts b/source/frontend/src/features/mapSideBar/acquisition/common/models.test.ts new file mode 100644 index 0000000000..2d32f31b9b --- /dev/null +++ b/source/frontend/src/features/mapSideBar/acquisition/common/models.test.ts @@ -0,0 +1,21 @@ +import { AcquisitionTeamFormModel } from './models'; + +describe('acquisition model tests', () => { + it('omits the primary contact if unset', () => { + let model = new AcquisitionTeamFormModel('testType'); + model.primaryContactId = ''; + expect(model.toApi(1)?.primaryContactId).toBeUndefined(); + }); + + it('omits the primary contact if null', () => { + let model = new AcquisitionTeamFormModel('testType'); + model.primaryContactId = null as any; + expect(model.toApi(1)?.primaryContactId).toBeUndefined(); + }); + + it('omits the primary contact if undefined', () => { + let model = new AcquisitionTeamFormModel('testType'); + model.primaryContactId = undefined as any; + expect(model.toApi(1)?.primaryContactId).toBeUndefined(); + }); +}); diff --git a/source/frontend/src/features/mapSideBar/acquisition/common/models.ts b/source/frontend/src/features/mapSideBar/acquisition/common/models.ts index ecd7f2cecf..658f5d7c0b 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/common/models.ts +++ b/source/frontend/src/features/mapSideBar/acquisition/common/models.ts @@ -42,7 +42,7 @@ export class AcquisitionTeamFormModel { person: undefined, organizationId: organizationId ?? undefined, organization: undefined, - primaryContactId: this.primaryContactId !== '' ? Number(this.primaryContactId) : undefined, + primaryContactId: !isNaN(+this.primaryContactId) ? Number(this.primaryContactId) : undefined, teamProfileType: toTypeCode(this.contactTypeCode), teamProfileTypeCode: this.contactTypeCode, };