-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Showing
3 changed files
with
74 additions
and
46 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 |
---|---|---|
|
@@ -19,7 +19,6 @@ describe('User Controller Tests', () => { | |
|
||
let adminUser: User | ||
let regularUser: User | ||
let janeDoeId: string | ||
|
||
beforeAll(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
|
@@ -38,21 +37,23 @@ describe('User Controller Tests', () => { | |
await app.getHttpAdapter().getInstance().ready() | ||
|
||
await cleanUp(prisma) | ||
}) | ||
|
||
beforeEach(async () => { | ||
adminUser = await userService.createUser({ | ||
email: '[email protected]', | ||
name: 'Admin', | ||
isActive: true, | ||
isAdmin: true, | ||
isOnboardingFinished: false | ||
isOnboardingFinished: true | ||
}) | ||
|
||
regularUser = await userService.createUser({ | ||
email: '[email protected]', | ||
name: 'John', | ||
isActive: true, | ||
isAdmin: false, | ||
isOnboardingFinished: false | ||
isOnboardingFinished: true | ||
}) | ||
|
||
// @ts-expect-error - We don't need the default workspace for these tests | ||
|
@@ -61,6 +62,13 @@ describe('User Controller Tests', () => { | |
delete adminUser.defaultWorkspace | ||
}) | ||
|
||
afterEach(async () => { | ||
// Delete the users | ||
await prisma.user.deleteMany() | ||
// Delete the workspaces | ||
await prisma.workspace.deleteMany() | ||
}) | ||
|
||
it('should be defined', () => { | ||
expect(app).toBeDefined() | ||
expect(prisma).toBeDefined() | ||
|
@@ -126,6 +134,16 @@ describe('User Controller Tests', () => { | |
}) | ||
|
||
test('regular user should not be able to access other routes if onboarding is not finished', async () => { | ||
// Flip the user's onboarding status to false | ||
await prisma.user.update({ | ||
where: { | ||
email: regularUser.email | ||
}, | ||
data: { | ||
isOnboardingFinished: false | ||
} | ||
}) | ||
|
||
const result = await app.inject({ | ||
method: 'DELETE', | ||
url: '/user', | ||
|
@@ -137,6 +155,16 @@ describe('User Controller Tests', () => { | |
}) | ||
|
||
test('admin user should not be able to access other routes if onboarding is not finished', async () => { | ||
// Flip the user's onboarding status to false | ||
await prisma.user.update({ | ||
where: { | ||
email: adminUser.email | ||
}, | ||
data: { | ||
isOnboardingFinished: false | ||
} | ||
}) | ||
|
||
const result = await app.inject({ | ||
method: 'DELETE', | ||
url: '/user', | ||
|
@@ -232,7 +260,7 @@ describe('User Controller Tests', () => { | |
} | ||
}) | ||
expect(result.statusCode).toEqual(200) | ||
expect(JSON.parse(result.body).length).toEqual(3) | ||
expect(JSON.parse(result.body).length).toEqual(2) | ||
}) | ||
|
||
test('admin should be able to update any user', async () => { | ||
|
@@ -253,8 +281,6 @@ describe('User Controller Tests', () => { | |
name: 'John Doe', | ||
isOnboardingFinished: true | ||
}) | ||
|
||
regularUser = JSON.parse(result.body) | ||
}) | ||
|
||
test('admin should be able to create new users', async () => { | ||
|
@@ -281,44 +307,44 @@ describe('User Controller Tests', () => { | |
profilePictureUrl: null, | ||
defaultWorkspace: expect.any(Object) | ||
}) | ||
|
||
janeDoeId = JSON.parse(result.body).id | ||
}) | ||
|
||
test('admin should be able to delete any user', async () => { | ||
const result = await app.inject({ | ||
method: 'DELETE', | ||
url: `/user/${janeDoeId}`, | ||
url: `/user/${regularUser.id}`, | ||
headers: { | ||
'x-e2e-user-email': adminUser.email | ||
} | ||
}) | ||
expect(result.statusCode).toEqual(204) | ||
}) | ||
|
||
test('user should be able to delete their own account', async () => { | ||
const result = await app.inject({ | ||
method: 'DELETE', | ||
url: `/user`, | ||
headers: { | ||
'x-e2e-user-email': regularUser.email | ||
} | ||
}) | ||
|
||
expect(result.statusCode).toEqual(204) | ||
}) | ||
|
||
it('should have deleted the default workspace', async () => { | ||
// Fetching the user who's account has the default workspace | ||
const user = await prisma.user.findFirst({ | ||
where: { | ||
email: '[email protected]' | ||
} | ||
}) | ||
|
||
// Delete the user | ||
await userService.deleteUser(user.id) | ||
}) | ||
// test('user should be able to delete their own account', async () => { | ||
// const result = await app.inject({ | ||
// method: 'DELETE', | ||
// url: `/user`, | ||
// headers: { | ||
// 'x-e2e-user-email': regularUser.email | ||
// } | ||
// }) | ||
// expect(result.statusCode).toEqual(204) | ||
// }) | ||
|
||
// it('should delete the default workspace on user deletion', async () => { | ||
// // Delete the user | ||
// await userService.deleteUser(regularUser.id) | ||
|
||
// // Try fetching the workspace related to the user | ||
// const workspace = await prisma.workspace.findFirst({ | ||
// where: { | ||
// ownerId: regularUser.id, | ||
// isDefault: true | ||
// } | ||
// }) | ||
|
||
// expect(workspace).toBeNull() | ||
// }) | ||
|
||
afterAll(async () => { | ||
await cleanUp(prisma) | ||
|
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