Skip to content

Commit

Permalink
Add tests for the get my application endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhawa97 committed Oct 29, 2023
1 parent f2a95bc commit 32fde87
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/routes/profile/profile.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,52 @@ describe('profile', () => {
})
})

describe('Get my mentor applications route', () => {
it('should return a 200 with mentor applications for the user', async () => {
const response = await agent
.get('/api/me/applications?type=mentor')
.expect(200)

if (
response.body.message === 'No mentor applications found for the user'
) {
expect(response.body).not.toHaveProperty('mentor applications')
} else {
expect(response.body).toHaveProperty('mentor applications')
expect(response.body['mentor applications']).toBeInstanceOf(Array)
expect(response.body['mentor applications']).toHaveProperty('state')
expect(response.body['mentor applications']).toHaveProperty('category')
expect(response.body['mentor applications']).toHaveProperty(
'availability'
)
expect(response.body['mentor applications']).toHaveProperty('uuid')
expect(response.body['mentor applications']).toHaveProperty(
'created_at'
)
expect(response.body['mentor applications']).toHaveProperty(
'updated_at'
)
}
})

it('should return a 404 for an invalid application type', async () => {
const response = await agent
.get('/api/me/applications?type=invalidType')
.expect(404)

expect(response.body).toHaveProperty(
'message',
'Invalid application type'
)
})

it('should return a 401 when a valid access token is not provided', async () => {
await supertest(server)
.get('/api/me/applications?type=mentor')
.expect(401)
})
})

describe('Delete profile route', () => {
it('should delete the user profile and return a 200', async () => {
await agent.delete('/api/me/profile').expect(200)
Expand All @@ -66,9 +112,9 @@ describe('profile', () => {
it('should return a 401 when a valid access token is not provided', async () => {
await supertest(server).delete(`/api/me/profile`).send({}).expect(401)
})
})

afterAll(async () => {
await dataSource.destroy()
})
afterAll(async () => {
await dataSource.destroy()
})
})

0 comments on commit 32fde87

Please sign in to comment.