From 0c085437b0c62e24d258a27b651c225bab8b76b4 Mon Sep 17 00:00:00 2001 From: Cornelius <144817755+DPDS93CT@users.noreply.github.com> Date: Thu, 12 Dec 2024 08:25:53 +0100 Subject: [PATCH] =?UTF-8?q?SPSH-1584:=20OX:=20E-Mail=20Adresse=20bei=20Nam?= =?UTF-8?q?ens=C3=A4nderung=20wird=20nicht=20angepasst=20(#826)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adjust OXUserChange (renaming user) to set referrer as OxUserName also adjust evnet regarding ID_OX in KC * expect more info-logging in test cases for OxEventHandler --- .../ox/domain/ox-event-handler.spec.ts | 18 +++++++++++++----- src/modules/ox/domain/ox-event-handler.ts | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/modules/ox/domain/ox-event-handler.spec.ts b/src/modules/ox/domain/ox-event-handler.spec.ts index 0513f6411..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}`, ); @@ -908,7 +916,7 @@ describe('OxEventHandler', () => { personId: personId, keycloakUsername: referrer, oxUserId: oxUserId, - oxUserName: oxUserName, + oxUserName: referrer, //this is the new OxUserName, it's changed on renaming in SPSH oxContextId: contextId, oxContextName: contextName, primaryEmail: email, diff --git a/src/modules/ox/domain/ox-event-handler.ts b/src/modules/ox/domain/ox-event-handler.ts index 5accc0054..0dd0982f2 100644 --- a/src/modules/ox/domain/ox-event-handler.ts +++ b/src/modules/ox/domain/ox-event-handler.ts @@ -303,9 +303,13 @@ 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].address)} For personId:${personId}`, + ); + return requestedEmailAddresses[0]; } @@ -615,15 +619,18 @@ export class OxEventHandler { ); } const newAliasesArray: string[] = getDataResult.value.aliases; + 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, - username: getDataResult.value.username, + userId: person.oxUserId, + username: person.referrer, givenname: person.vorname, surname: person.familienname, - displayname: person.referrer, + displayname: person.referrer, //IS EXPLICITLY NOT SET to vorname+familienname defaultSenderAddress: requestedEmailAddressString, email1: requestedEmailAddressString, aliases: newAliasesArray, @@ -653,8 +660,8 @@ export class OxEventHandler { new OxUserChangedEvent( personId, person.referrer, - getDataResult.value.id, - getDataResult.value.username, + person.oxUserId, + person.referrer, //strictEquals the new OxUsername this.contextID, this.contextName, requestedEmailAddressString,