-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPSH-1354 IDOX in Keycloakattributes (#761)
- Loading branch information
1 parent
37742b4
commit 8d24e28
Showing
4 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,13 @@ import { PersonID } from '../../../shared/types/aggregate-ids.types.js'; | |
import { EventService } from '../../../core/eventbus/services/event.service.js'; | ||
import { OxUserChangedEvent } from '../../../shared/events/ox-user-changed.event.js'; | ||
import { KeycloakClientError } from '../../../shared/error/keycloak-client.error.js'; | ||
import { PersonenkontextMigrationRuntype } from '../../personenkontext/domain/personenkontext.enums.js'; | ||
import { Personenkontext } from '../../personenkontext/domain/personenkontext.js'; | ||
import { Person } from '../../person/domain/person.js'; | ||
import { Rolle } from '../../rolle/domain/rolle.js'; | ||
import { Organisation } from '../../organisation/domain/organisation.js'; | ||
import { PersonenkontextCreatedMigrationEvent } from '../../../shared/events/personenkontext-created-migration.event.js'; | ||
import { RollenArt } from '../../rolle/domain/rolle.enums.js'; | ||
|
||
describe('KeycloakEventHandler', () => { | ||
let module: TestingModule; | ||
|
@@ -44,6 +51,97 @@ describe('KeycloakEventHandler', () => { | |
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('handlePersonenkontextCreatedMigrationEvent', () => { | ||
const migrationType: PersonenkontextMigrationRuntype = PersonenkontextMigrationRuntype.STANDARD; | ||
|
||
let personenkontext: Personenkontext<true>; | ||
let person: Person<true>; | ||
let rolle: Rolle<true>; | ||
let orga: Organisation<true>; | ||
|
||
beforeEach(() => { | ||
personenkontext = createMock<Personenkontext<true>>(); | ||
person = createMock<Person<true>>(); | ||
rolle = createMock<Rolle<true>>(); | ||
orga = createMock<Organisation<true>>(); | ||
}); | ||
|
||
it('should do nothing', async () => { | ||
const event: PersonenkontextCreatedMigrationEvent = new PersonenkontextCreatedMigrationEvent( | ||
migrationType, | ||
personenkontext, | ||
person, | ||
rolle, | ||
orga, | ||
'[email protected]', | ||
); | ||
|
||
await sut.handlePersonenkontextCreatedMigrationEvent(event); | ||
expect(loggerMock.info).toHaveBeenCalledWith( | ||
expect.stringContaining('UpdateOXUserAttributes criteria not fulfilled, no action taken'), | ||
); | ||
expect(keycloakUserServiceMock.updateOXUserAttributes).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should successfully call updateOXUserAttributes', async () => { | ||
person.email = faker.internet.email(); | ||
person.referrer = faker.internet.userName(); | ||
rolle.rollenart = RollenArt.LEHR; | ||
|
||
const event: PersonenkontextCreatedMigrationEvent = new PersonenkontextCreatedMigrationEvent( | ||
migrationType, | ||
personenkontext, | ||
person, | ||
rolle, | ||
orga, | ||
'[email protected]', | ||
); | ||
|
||
keycloakUserServiceMock.updateOXUserAttributes.mockResolvedValueOnce({ | ||
ok: true, | ||
value: undefined, | ||
}); | ||
|
||
await sut.handlePersonenkontextCreatedMigrationEvent(event); | ||
expect(loggerMock.info).toHaveBeenCalledWith( | ||
expect.stringContaining('UpdateOXUserAttributes criteria fulfilled, trying to updateOXUserAttributes'), | ||
); | ||
expect(loggerMock.error).not.toHaveBeenCalledWith( | ||
expect.stringContaining('Updating user in keycloak failed for OxUserChangedEvent'), | ||
); | ||
expect(keycloakUserServiceMock.updateOXUserAttributes).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should log error if updateOXUserAttributes fails', async () => { | ||
person.email = faker.internet.email(); | ||
person.referrer = faker.internet.userName(); | ||
rolle.rollenart = RollenArt.LEHR; | ||
|
||
const event: PersonenkontextCreatedMigrationEvent = new PersonenkontextCreatedMigrationEvent( | ||
migrationType, | ||
personenkontext, | ||
person, | ||
rolle, | ||
orga, | ||
'[email protected]', | ||
); | ||
|
||
keycloakUserServiceMock.updateOXUserAttributes.mockResolvedValueOnce({ | ||
ok: false, | ||
error: new KeycloakClientError('Could not update user-attributes'), | ||
}); | ||
|
||
await sut.handlePersonenkontextCreatedMigrationEvent(event); | ||
expect(loggerMock.info).toHaveBeenCalledWith( | ||
expect.stringContaining('UpdateOXUserAttributes criteria fulfilled, trying to updateOXUserAttributes'), | ||
); | ||
expect(loggerMock.error).toHaveBeenCalledWith( | ||
expect.stringContaining('Updating user in keycloak failed for OxUserChangedEvent'), | ||
); | ||
expect(keycloakUserServiceMock.updateOXUserAttributes).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('handleOxUserCreatedEvent', () => { | ||
let fakePersonID: PersonID; | ||
let fakeOXUserID: OXUserID; | ||
|
@@ -61,6 +159,10 @@ describe('KeycloakEventHandler', () => { | |
fakeEmail = faker.internet.email(); | ||
}); | ||
it('should log info and call KeycloakUserService', async () => { | ||
keycloakUserServiceMock.updateOXUserAttributes.mockResolvedValueOnce({ | ||
ok: true, | ||
value: undefined, | ||
}); | ||
await sut.handleOxUserChangedEvent( | ||
new OxUserChangedEvent( | ||
fakePersonID, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters