Skip to content

Commit

Permalink
expect more info-logging in test cases for OxEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
DPDS93CT committed Dec 8, 2024
1 parent 21eff96 commit 1a7a1b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
16 changes: 12 additions & 4 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 Down
12 changes: 6 additions & 6 deletions src/modules/ox/domain/ox-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ 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])} For personId:${personId}`,
`Found mostRecentRequested Email-Address:${JSON.stringify(requestedEmailAddresses[0].address)} For personId:${personId}`,
);

return requestedEmailAddresses[0];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1a7a1b1

Please sign in to comment.