From cfc20e1b9e7d24862a78316aa5f2360158cedaa1 Mon Sep 17 00:00:00 2001 From: Morgan Ludtke <42942267+ludtkemorgan@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:56:10 -0600 Subject: [PATCH] fix: update to correct juris on change requested (#3934) --- api/src/services/email.service.ts | 14 +++++++++++--- api/src/services/listing.service.ts | 6 +++++- api/test/integration/listing.e2e-spec.ts | 2 +- api/test/unit/services/email.service.spec.ts | 2 +- api/test/unit/services/listing.service.spec.ts | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api/src/services/email.service.ts b/api/src/services/email.service.ts index 740a704f25..86e62194cb 100644 --- a/api/src/services/email.service.ts +++ b/api/src/services/email.service.ts @@ -28,6 +28,12 @@ type EmailAttachmentData = { type: string; }; +type listingInfo = { + id: string; + name: string; + juris: string; +}; + @Injectable() export class EmailService { polyglot: Polyglot; @@ -429,13 +435,15 @@ export class EmailService { } public async changesRequested( - jurisdictionId: IdDTO, - listingInfo: IdDTO, + user: User, + listingInfo: listingInfo, emails: string[], appUrl: string, ) { try { - const jurisdiction = await this.getJurisdiction([jurisdictionId]); + const jurisdiction = listingInfo.juris + ? await this.getJurisdiction([{ id: listingInfo.juris }]) + : user.jurisdictions[0]; void (await this.loadTranslations(jurisdiction)); await this.send( emails, diff --git a/api/src/services/listing.service.ts b/api/src/services/listing.service.ts index c8d20bb426..e3575a744c 100644 --- a/api/src/services/listing.service.ts +++ b/api/src/services/listing.service.ts @@ -313,7 +313,11 @@ export class ListingService implements OnModuleInit { ); await this.emailService.changesRequested( params.user, - { id: params.listingInfo.id, name: params.listingInfo.name }, + { + id: params.listingInfo.id, + name: params.listingInfo.name, + juris: params.jurisId, + }, userInfo.emails, this.configService.get('PARTNERS_PORTAL_URL'), ); diff --git a/api/test/integration/listing.e2e-spec.ts b/api/test/integration/listing.e2e-spec.ts index ba48509277..c7314e3baa 100644 --- a/api/test/integration/listing.e2e-spec.ts +++ b/api/test/integration/listing.e2e-spec.ts @@ -886,7 +886,7 @@ describe('Listing Controller Tests', () => { expect.objectContaining({ id: adminUser.id, }), - { id: listing.id, name: val.name }, + { id: listing.id, name: val.name, juris: expect.anything() }, expect.arrayContaining([partnerUser.email]), process.env.PARTNERS_PORTAL_URL, ); diff --git a/api/test/unit/services/email.service.spec.ts b/api/test/unit/services/email.service.spec.ts index 767a3d04ba..a8320e8d49 100644 --- a/api/test/unit/services/email.service.spec.ts +++ b/api/test/unit/services/email.service.spec.ts @@ -363,7 +363,7 @@ describe('Testing email service', () => { const service = await module.resolve(EmailService); await service.changesRequested( { name: 'test', id: '1234' }, - { name: 'listing name', id: 'listingId' }, + { name: 'listing name', id: 'listingId', juris: 'jurisId' }, emailArr, 'http://localhost:3001', ); diff --git a/api/test/unit/services/listing.service.spec.ts b/api/test/unit/services/listing.service.spec.ts index 13de89f842..3c470cab39 100644 --- a/api/test/unit/services/listing.service.spec.ts +++ b/api/test/unit/services/listing.service.spec.ts @@ -2569,7 +2569,7 @@ describe('Testing listing service', () => { ); expect(changesRequestedMock).toBeCalledWith( user, - { id: 'id', name: 'name' }, + { id: 'id', name: 'name', juris: 'jurisId' }, ['jurisAdmin@email.com', 'partner@email.com'], config.get('PARTNERS_PORTAL_URL'), );