-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trigger ic user agency right changed when adding user
- Loading branch information
1 parent
e825420
commit 58a09f9
Showing
3 changed files
with
89 additions
and
39 deletions.
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { | ||
AgencyDtoBuilder, | ||
InclusionConnectedUserBuilder, | ||
UserCreateParamsForAgency, | ||
errors, | ||
expectPromiseToFailWithError, | ||
expectToEqual, | ||
} from "shared"; | ||
import { InMemoryAgencyRepository } from "../../agency/adapters/InMemoryAgencyRepository"; | ||
import { InMemoryUserRepository } from "../../core/authentication/inclusion-connect/adapters/InMemoryUserRepository"; | ||
import { InMemoryOutboxRepository } from "../../core/events/adapters/InMemoryOutboxRepository"; | ||
import { | ||
CreateNewEvent, | ||
makeCreateNewEvent, | ||
} from "../../core/events/ports/EventBus"; | ||
import { CustomTimeGateway } from "../../core/time-gateway/adapters/CustomTimeGateway"; | ||
import { TimeGateway } from "../../core/time-gateway/ports/TimeGateway"; | ||
import { InMemoryUowPerformer } from "../../core/unit-of-work/adapters/InMemoryUowPerformer"; | ||
|
@@ -39,22 +45,29 @@ describe("CreateUserForAgency", () => { | |
let agencyRepository: InMemoryAgencyRepository; | ||
let timeGateway: TimeGateway; | ||
let uuidGenerator: UuidGenerator; | ||
let outboxRepository: InMemoryOutboxRepository; | ||
let createNewEvent: CreateNewEvent; | ||
|
||
beforeEach(() => { | ||
const uow = createInMemoryUow(); | ||
|
||
userRepository = uow.userRepository; | ||
agencyRepository = uow.agencyRepository; | ||
outboxRepository = uow.outboxRepository; | ||
uowPerformer = new InMemoryUowPerformer(uow); | ||
userRepository.setInclusionConnectedUsers([ | ||
backofficeAdminUser, | ||
notAdminUser, | ||
]); | ||
timeGateway = new CustomTimeGateway(); | ||
uuidGenerator = new TestUuidGenerator(); | ||
createNewEvent = makeCreateNewEvent({ | ||
uuidGenerator, | ||
timeGateway, | ||
}); | ||
createUserForAgency = makeCreateUserForAgency({ | ||
uowPerformer, | ||
deps: { timeGateway, uuidGenerator }, | ||
deps: { timeGateway, createNewEvent }, | ||
}); | ||
agencyRepository.setAgencies([agency]); | ||
}); | ||
|
@@ -141,16 +154,15 @@ describe("CreateUserForAgency", () => { | |
const newUserId = uuidGenerator.new(); | ||
userRepository.users = []; | ||
|
||
await createUserForAgency.execute( | ||
{ | ||
userId: newUserId, | ||
agencyId: agency.id, | ||
roles: ["counsellor"], | ||
isNotifiedByEmail: false, | ||
email: "[email protected]", | ||
}, | ||
backofficeAdminUser, | ||
); | ||
const icUserForAgency: UserCreateParamsForAgency = { | ||
userId: newUserId, | ||
agencyId: agency.id, | ||
roles: ["counsellor"], | ||
isNotifiedByEmail: false, | ||
email: "[email protected]", | ||
}; | ||
|
||
await createUserForAgency.execute(icUserForAgency, backofficeAdminUser); | ||
|
||
expect(userRepository.users.length).toBe(1); | ||
expectToEqual(await userRepository.getById(newUserId), { | ||
|
@@ -168,6 +180,19 @@ describe("CreateUserForAgency", () => { | |
establishments: {}, | ||
}, | ||
}); | ||
|
||
expectToEqual(outboxRepository.events, [ | ||
createNewEvent({ | ||
topic: "IcUserAgencyRightChanged", | ||
payload: { | ||
...icUserForAgency, | ||
triggeredBy: { | ||
kind: "inclusion-connected", | ||
userId: backofficeAdminUser.id, | ||
}, | ||
}, | ||
}), | ||
]); | ||
}); | ||
|
||
it("add agency rights to an existing user", async () => { | ||
|
@@ -195,16 +220,15 @@ describe("CreateUserForAgency", () => { | |
], | ||
}); | ||
|
||
await createUserForAgency.execute( | ||
{ | ||
userId, | ||
agencyId: anotherAgency.id, | ||
roles: ["counsellor"], | ||
isNotifiedByEmail: false, | ||
email: "[email protected]", | ||
}, | ||
backofficeAdminUser, | ||
); | ||
const icUserForAgency: UserCreateParamsForAgency = { | ||
userId, | ||
agencyId: anotherAgency.id, | ||
roles: ["counsellor"], | ||
isNotifiedByEmail: false, | ||
email: "[email protected]", | ||
}; | ||
|
||
await createUserForAgency.execute(icUserForAgency, backofficeAdminUser); | ||
|
||
expectToEqual(await userRepository.getById(userId), { | ||
createdAt: timeGateway.now().toISOString(), | ||
|
@@ -230,5 +254,17 @@ describe("CreateUserForAgency", () => { | |
establishments: {}, | ||
}, | ||
}); | ||
expectToEqual(outboxRepository.events, [ | ||
createNewEvent({ | ||
topic: "IcUserAgencyRightChanged", | ||
payload: { | ||
...icUserForAgency, | ||
triggeredBy: { | ||
kind: "inclusion-connected", | ||
userId: backofficeAdminUser.id, | ||
}, | ||
}, | ||
}), | ||
]); | ||
}); | ||
}); |