From 1a7a1b1fa1a5fc0579cb0fcbd99820c8e50e18a8 Mon Sep 17 00:00:00 2001 From: DPDS93CT Date: Sun, 8 Dec 2024 12:07:35 +0100 Subject: [PATCH] expect more info-logging in test cases for OxEventHandler --- src/modules/ox/domain/ox-event-handler.spec.ts | 16 ++++++++++++---- src/modules/ox/domain/ox-event-handler.ts | 12 ++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/modules/ox/domain/ox-event-handler.spec.ts b/src/modules/ox/domain/ox-event-handler.spec.ts index fdba12c90..58cdd885e 100644 --- a/src/modules/ox/domain/ox-event-handler.spec.ts +++ b/src/modules/ox/domain/ox-event-handler.spec.ts @@ -546,7 +546,7 @@ describe('OxEventHandler', () => { expect(oxServiceMock.send).toHaveBeenCalledTimes(0); expect(loggerMock.error).toHaveBeenLastCalledWith( - `No requested email-address found for personId:${personId}`, + `No REQUESTED email-address found for personId:${personId}`, ); }); @@ -828,7 +828,7 @@ describe('OxEventHandler', () => { expect(oxServiceMock.send).toHaveBeenCalledTimes(0); expect(loggerMock.error).toHaveBeenLastCalledWith( - `No requested email-address found for personId:${personId}`, + `No REQUESTED email-address found for personId:${personId}`, ); }); @@ -878,12 +878,12 @@ describe('OxEventHandler', () => { it('should publish OxUserChangedEvent on success', async () => { personRepositoryMock.findById.mockResolvedValueOnce(person); emailRepoMock.findByPersonSortedByUpdatedAtDesc.mockResolvedValueOnce(getRequestedEmailAddresses(email)); - + const currentAliases: string[] = [faker.internet.email()]; //mock getData oxServiceMock.send.mockResolvedValueOnce({ ok: true, value: createMock({ - aliases: [faker.internet.email()], + aliases: currentAliases, username: oxUserName, id: oxUserId, primaryEmail: email, @@ -900,6 +900,14 @@ describe('OxEventHandler', () => { expect(oxServiceMock.send).toHaveBeenCalledTimes(2); expect(loggerMock.error).toHaveBeenCalledTimes(0); + expect(loggerMock.info).toHaveBeenCalledWith( + `Found mostRecentRequested Email-Address:${JSON.stringify(email)} For personId:${personId}`, + ); + //use regex, because strict comparison fails, local test-var currentAliases has changed by the implemented function when expect is checked here + expect(loggerMock.info).toHaveBeenCalledWith( + expect.stringMatching(/Found Current aliases:.* For personId:/), + ); + expect(loggerMock.info).toHaveBeenCalledWith(`Added New alias:${email} For personId:${personId}`); expect(loggerMock.info).toHaveBeenLastCalledWith( `Changed primary email-address in OX for user, username:${person.referrer}, new email-address:${email}`, ); diff --git a/src/modules/ox/domain/ox-event-handler.ts b/src/modules/ox/domain/ox-event-handler.ts index 917a2e713..0dd0982f2 100644 --- a/src/modules/ox/domain/ox-event-handler.ts +++ b/src/modules/ox/domain/ox-event-handler.ts @@ -303,11 +303,11 @@ export class OxEventHandler { const requestedEmailAddresses: Option[]> = await this.emailRepo.findByPersonSortedByUpdatedAtDesc(personId, EmailAddressStatus.REQUESTED); if (!requestedEmailAddresses || !requestedEmailAddresses[0]) { - this.logger.error(`No requested email-address found for personId:${personId}`); + this.logger.error(`No REQUESTED email-address found for personId:${personId}`); return undefined; } this.logger.info( - `Found mostRecentRequested Email-Address:${JSON.stringify(requestedEmailAddresses[0])} For personId:${personId}`, + `Found mostRecentRequested Email-Address:${JSON.stringify(requestedEmailAddresses[0].address)} For personId:${personId}`, ); return requestedEmailAddresses[0]; @@ -619,18 +619,18 @@ export class OxEventHandler { ); } const newAliasesArray: string[] = getDataResult.value.aliases; - this.logger.info(`Current aliases:${JSON.stringify(newAliasesArray)} For personId:${personId}`); + this.logger.info(`Found Current aliases:${JSON.stringify(newAliasesArray)} For personId:${personId}`); newAliasesArray.push(requestedEmailAddressString); this.logger.info(`Added New alias:${requestedEmailAddressString} For personId:${personId}`); const params: ChangeUserParams = { contextId: this.contextID, - userId: getDataResult.value.id, + userId: person.oxUserId, username: person.referrer, givenname: person.vorname, surname: person.familienname, - displayname: person.referrer, //may should be changed in future + displayname: person.referrer, //IS EXPLICITLY NOT SET to vorname+familienname defaultSenderAddress: requestedEmailAddressString, email1: requestedEmailAddressString, aliases: newAliasesArray, @@ -660,7 +660,7 @@ export class OxEventHandler { new OxUserChangedEvent( personId, person.referrer, - getDataResult.value.id, //is the OxUserId + person.oxUserId, person.referrer, //strictEquals the new OxUsername this.contextID, this.contextName,