-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Update Jurisdictional Admin E2E Tests and Correct Jurisdictional…
… Admin Delete User (#4026) * fix: join jurisdictions on user for delete 4024 * fix: update tests 4024 * fix: make sure userRoles are present for deletion 4024 * fix: correct tests with userRoles for deletes
- Loading branch information
Showing
5 changed files
with
94 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum UserViews { | ||
base = 'base', | ||
full = 'full', | ||
} |
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 |
---|---|---|
|
@@ -819,20 +819,20 @@ describe('Testing Permissioning of endpoints as Jurisdictional Admin in the corr | |
.expect(200); | ||
}); | ||
|
||
it('should error as forbidden for retrieve endpoint', async () => { | ||
it('should succeed for retrieve endpoint', async () => { | ||
const userA = await prisma.userAccounts.create({ | ||
data: await userFactory(), | ||
data: await userFactory({ jurisdictionIds: [jurisId] }), | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
.get(`/user/${userA.id}`) | ||
.set('Cookie', cookies) | ||
.expect(403); | ||
.expect(200); | ||
}); | ||
|
||
it('should error as forbidden for update endpoint', async () => { | ||
it('should succeed for update endpoint', async () => { | ||
const userA = await prisma.userAccounts.create({ | ||
data: await userFactory(), | ||
data: await userFactory({ jurisdictionIds: [jurisId] }), | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
|
@@ -841,14 +841,15 @@ describe('Testing Permissioning of endpoints as Jurisdictional Admin in the corr | |
id: userA.id, | ||
firstName: 'New User First Name', | ||
lastName: 'New User Last Name', | ||
jurisdictions: [{ id: jurisId } as IdDTO], | ||
} as UserUpdate) | ||
.set('Cookie', cookies) | ||
.expect(403); | ||
.expect(200); | ||
}); | ||
|
||
it('should error as forbidden for delete endpoint', async () => { | ||
it('should succeed for delete endpoint', async () => { | ||
const userA = await prisma.userAccounts.create({ | ||
data: await userFactory(), | ||
data: await userFactory({ jurisdictionIds: [jurisId] }), | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
|
@@ -857,7 +858,7 @@ describe('Testing Permissioning of endpoints as Jurisdictional Admin in the corr | |
id: userA.id, | ||
} as IdDTO) | ||
.set('Cookie', cookies) | ||
.expect(403); | ||
.expect(200); | ||
}); | ||
|
||
it('should succeed for public resend confirmation endpoint', async () => { | ||
|
@@ -950,7 +951,10 @@ describe('Testing Permissioning of endpoints as Jurisdictional Admin in the corr | |
|
||
await request(app.getHttpServer()) | ||
.post(`/user/invite`) | ||
.send(buildUserInviteMock(juris, '[email protected]')) | ||
.send( | ||
// builds an invite for an admin | ||
buildUserInviteMock(jurisId, '[email protected]'), | ||
) | ||
.set('Cookie', cookies) | ||
.expect(403); | ||
}); | ||
|
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ import { User } from '../../../src/dtos/users/user.dto'; | |
import { PermissionService } from '../../../src/services/permission.service'; | ||
import { permissionActions } from '../../../src/enums/permissions/permission-actions-enum'; | ||
import { OrderByEnum } from '../../../src/enums/shared/order-by-enum'; | ||
import { UserViews } from '../../../src/enums/user/view-enum'; | ||
|
||
describe('Testing user service', () => { | ||
let service: UserService; | ||
|
@@ -370,7 +371,7 @@ describe('Testing user service', () => { | |
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
}); | ||
const res = await service.findUserOrError({ userId: id }, true); | ||
const res = await service.findUserOrError({ userId: id }, UserViews.full); | ||
expect(res).toEqual({ id }); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -384,12 +385,33 @@ describe('Testing user service', () => { | |
}); | ||
}); | ||
|
||
it('should find user by id and include only jurisdictions joins', async () => { | ||
const id = randomUUID(); | ||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
}); | ||
const res = await service.findUserOrError({ userId: id }, UserViews.base); | ||
expect(res).toEqual({ id }); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
jurisdictions: true, | ||
userRoles: true, | ||
}, | ||
where: { | ||
id, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should find user by email and include joins', async () => { | ||
const email = '[email protected]'; | ||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
email, | ||
}); | ||
const res = await service.findUserOrError({ email: email }, true); | ||
const res = await service.findUserOrError( | ||
{ email: email }, | ||
UserViews.full, | ||
); | ||
expect(res).toEqual({ email }); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
include: { | ||
|
@@ -408,7 +430,7 @@ describe('Testing user service', () => { | |
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
id, | ||
}); | ||
const res = await service.findUserOrError({ userId: id }, false); | ||
const res = await service.findUserOrError({ userId: id }); | ||
expect(res).toEqual({ id }); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
where: { | ||
|
@@ -422,7 +444,7 @@ describe('Testing user service', () => { | |
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue({ | ||
email, | ||
}); | ||
const res = await service.findUserOrError({ email: email }, false); | ||
const res = await service.findUserOrError({ email: email }); | ||
expect(res).toEqual({ email }); | ||
expect(prisma.userAccounts.findUnique).toHaveBeenCalledWith({ | ||
where: { | ||
|
@@ -435,7 +457,7 @@ describe('Testing user service', () => { | |
const email = '[email protected]'; | ||
prisma.userAccounts.findUnique = jest.fn().mockResolvedValue(null); | ||
await expect( | ||
async () => await service.findUserOrError({ email: email }, false), | ||
async () => await service.findUserOrError({ email: email }), | ||
).rejects.toThrowError( | ||
'user email: [email protected] was requested but not found', | ||
); | ||
|
@@ -859,6 +881,10 @@ describe('Testing user service', () => { | |
where: { | ||
id, | ||
}, | ||
include: { | ||
jurisdictions: true, | ||
userRoles: true, | ||
}, | ||
}); | ||
expect(prisma.userAccounts.delete).toHaveBeenCalledWith({ | ||
where: { | ||
|
@@ -902,6 +928,10 @@ describe('Testing user service', () => { | |
where: { | ||
id, | ||
}, | ||
include: { | ||
jurisdictions: true, | ||
userRoles: true, | ||
}, | ||
}); | ||
|
||
expect(prisma.userAccounts.delete).not.toHaveBeenCalled(); | ||
|