-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15d2d34
commit 435969b
Showing
5 changed files
with
123 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ describe("UserService", async () => { | |
let user: User; | ||
let user2: User; | ||
let nonOrgUser: User; | ||
let orgOwner: User; | ||
|
||
beforeEach(async () => { | ||
container = createTestContainer(); | ||
|
@@ -69,6 +70,18 @@ describe("UserService", async () => { | |
primaryEmail: "[email protected]", | ||
}, | ||
}); | ||
|
||
orgOwner = await userService.createUser({ | ||
organizationId: org.id, | ||
identity: { | ||
authId: "foo", | ||
authName: "bar", | ||
authProviderId: "github", | ||
primaryEmail: "[email protected]", | ||
}, | ||
}); | ||
await orgService.joinOrganization(orgOwner.id, invite.id); | ||
await orgService.addOrUpdateMember(BUILTIN_INSTLLATION_ADMIN_USER_ID, org.id, orgOwner.id, "owner"); | ||
}); | ||
|
||
afterEach(async () => { | ||
|
@@ -203,4 +216,24 @@ describe("UserService", async () => { | |
expect(users.total).to.eq(1); | ||
expect(users.rows.some((u) => u.id === nonOrgUser.id)).to.be.true; | ||
}); | ||
|
||
it("should delete user", async () => { | ||
await expectError(ErrorCodes.NOT_FOUND, userService.deleteUser(nonOrgUser.id, user2.id)); | ||
await expectError(ErrorCodes.PERMISSION_DENIED, userService.deleteUser(user.id, user2.id)); | ||
// user can delete themselves | ||
await userService.deleteUser(user.id, user.id); | ||
user = await userService.findUserById(user.id, user.id); | ||
expect(user.markedDeleted).to.be.true; | ||
|
||
// org owners can delete users owned by org | ||
await expectError(ErrorCodes.NOT_FOUND, userService.deleteUser(orgOwner.id, nonOrgUser.id)); | ||
await userService.deleteUser(orgOwner.id, user2.id); | ||
user2 = await userService.findUserById(orgOwner.id, user2.id); | ||
expect(user2.markedDeleted).to.be.true; | ||
|
||
// admins can delete any user | ||
await userService.deleteUser(BUILTIN_INSTLLATION_ADMIN_USER_ID, nonOrgUser.id); | ||
nonOrgUser = await userService.findUserById(BUILTIN_INSTLLATION_ADMIN_USER_ID, nonOrgUser.id); | ||
expect(nonOrgUser.markedDeleted).to.be.true; | ||
}); | ||
}); |
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