Skip to content

Commit

Permalink
Merge branch 'release-0101' into SPSH-1586
Browse files Browse the repository at this point in the history
  • Loading branch information
DPDS93CT committed Dec 12, 2024
2 parents d403d3a + 0c08543 commit d4ffab7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
18 changes: 13 additions & 5 deletions src/modules/ox/domain/ox-event-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
});

Expand Down Expand Up @@ -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}`,
);
});

Expand Down Expand Up @@ -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<GetDataForUserResponse>({
aliases: [faker.internet.email()],
aliases: currentAliases,
username: oxUserName,
id: oxUserId,
primaryEmail: email,
Expand All @@ -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}`,
);
Expand All @@ -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,
Expand Down
19 changes: 13 additions & 6 deletions src/modules/ox/domain/ox-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,13 @@ export class OxEventHandler {
const requestedEmailAddresses: Option<EmailAddress<true>[]> =
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];
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d4ffab7

Please sign in to comment.