Skip to content

Commit

Permalink
user.service.ts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rayaanoidPrime committed May 22, 2024
1 parent ce50743 commit 8a84f04
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apps/api/src/user/user.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,43 @@ describe('User Controller Tests', () => {
expect(updatedOtp.code).not.toEqual('123456')
})

it('should return 409 Conflict if the email already exists', async () => {
const result = await app.inject({
method: 'PUT',
url: `/user/${regularUser.id}`,
headers: {
'x-e2e-user-email': adminUser.email
},
payload: {
email: adminUser.email // existing email
}
})

expect(result.statusCode).toEqual(409)
expect(JSON.parse(result.body)).toEqual({
statusCode: 409,
message: 'User with this email already exists',
error: 'Conflict'
})
})

it('should return 409 Conflict if no previous OTP exists for email change', async () => {
const result = await app.inject({
method: 'POST',
url: `/user/resend-email-change-otp`,
headers: {
'x-e2e-user-email': regularUser.email
}
})

expect(result.statusCode).toEqual(409)
expect(JSON.parse(result.body)).toEqual({
statusCode: 409,
message: `No previous OTP for email change exists for user ${regularUser.id}`,
error: 'Conflict'
})
})

// test('user should be able to delete their own account', async () => {
// const result = await app.inject({
// method: 'DELETE',
Expand Down

0 comments on commit 8a84f04

Please sign in to comment.