Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhawa97 committed Sep 23, 2023
1 parent 6ad0f26 commit 9d6330e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/controllers/mentor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const mentorDetailsHandler = async (
},
mentees: mentor.mentees
}
res.status(statusCode).json({ mentorDetails, message })
res.status(statusCode).json({ ...mentorDetails })
}
} catch (err) {
if (err instanceof Error) {
Expand Down
21 changes: 21 additions & 0 deletions src/routes/mentor/mentor.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { dataSource } from '../../configs/dbConfig'
import { mentorApplicationInfo, mockUser } from '../../../mocks'
import { v4 as uuidv4 } from 'uuid'
import Category from '../../entities/category.entity'
import type Mentor from '../../entities/mentor.entity'

const port = Math.floor(Math.random() * (9999 - 3000 + 1)) + 3000

let server: Express
let agent: supertest.SuperAgentTest
let savedCategory: Category
let savedMentor: Mentor

describe('Mentor application', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -38,6 +40,7 @@ describe('Mentor application', () => {

expect(response.body).toHaveProperty('mentor')
expect(response.body).toHaveProperty('message')
savedMentor = response.body.mentor
})

it('should return a 409 when the user is already a mentor or has an pending invitation', async () => {
Expand All @@ -60,6 +63,24 @@ describe('Mentor application', () => {
it('should return a 401 when a valid access token is not provided', async () => {
await supertest(server).post('/api/mentors').send({}).expect(401)
})
})

describe('Get mentor details route', () => {
it('should return a 200 with the mentor details', async () => {
const response = await agent
.get(`/api/mentors/${savedMentor.uuid}`)
.expect(200)

expect(response.body).toHaveProperty('mentorId')
expect(response.body).toHaveProperty('category')
expect(response.body).toHaveProperty('profile')
expect(response.body).toHaveProperty('mentees')
})

it('should return a 404 when the mentor ID is not found', async () => {
const nonExistentId = uuidv4()
await agent.get(`/api/mentors/${nonExistentId}`).expect(404)
})

afterAll(async () => {
await dataSource.destroy()
Expand Down

0 comments on commit 9d6330e

Please sign in to comment.