From b86a3edd6eaf23b1461a7969022774900548287b Mon Sep 17 00:00:00 2001 From: devinleighsmith Date: Tue, 31 Oct 2023 14:09:31 -0700 Subject: [PATCH] psp-7082 ensure that primary contact logic for org teams works when there is no org primary contact available. --- .../acquisition/common/models.test.ts | 21 +++++++++++++++++++ .../mapSideBar/acquisition/common/models.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 source/frontend/src/features/mapSideBar/acquisition/common/models.test.ts 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, };