Skip to content

Commit

Permalink
add unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
janithlahirukariyawasam committed Nov 27, 2023
1 parent edc193f commit 8c082f5
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/routes/admin/mentee/mentee.route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { startServer } from '../../../app'
import type { Express } from 'express'
import supertest from 'supertest'
import bcrypt from 'bcrypt'
import { mockAdmin, mockUser } from '../../../../mocks'
import { dataSource } from '../../../configs/dbConfig'
import Profile from '../../../entities/profile.entity'
import { ProfileTypes } from '../../../enums'
import type EmailTemplate from '../../../entities/emailTemplate.entity'

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

let server: Express
let agent: supertest.SuperAgentTest
let adminAgent: supertest.SuperAgentTest
let savedEmailTemplate: EmailTemplate

Check warning on line 16 in src/routes/admin/mentee/mentee.route.test.ts

View workflow job for this annotation

GitHub Actions / build

'savedEmailTemplate' is defined but never used

describe('Admin email template routes', () => {
beforeAll(async () => {
server = await startServer(port)
agent = supertest.agent(server)
adminAgent = supertest.agent(server)

await supertest(server)
.post('/api/auth/register')
.send(mockUser)
.expect(201)
await agent.post('/api/auth/login').send(mockUser).expect(200)

const profileRepository = dataSource.getRepository(Profile)

const hashedPassword = await bcrypt.hash(mockAdmin.password, 10)
const newProfile = profileRepository.create({
primary_email: mockAdmin.email,
password: hashedPassword,
contact_email: '',
first_name: '',
last_name: '',
image_url: '',
linkedin_url: '',
type: ProfileTypes.ADMIN
})

await profileRepository.save(newProfile)

await adminAgent.post('/api/auth/login').send(mockAdmin).expect(200)
}, 5000)

it('should get all mentee emails with status approved', async () => {
const response = await adminAgent
.get('/api/admin/mentee/emails?status=approved')
.expect(200)

const { emails, message } = response.body
expect(emails).toBeInstanceOf(Array)
expect(message).toContain('All mentee emails with status approved')
})

it('should get all mentee emails with status rejected', async () => {
const response = await adminAgent
.get('/api/admin/mentee/emails?status=rejected')
.expect(200)

const { emails, message } = response.body
expect(emails).toBeInstanceOf(Array)
expect(message).toContain('All mentee emails with status rejected')
})

it('should get all mentee emails with status pending', async () => {
const response = await adminAgent
.get('/api/admin/mentee/emails?status=pending')
.expect(200)

const { emails, message } = response.body
expect(emails).toBeInstanceOf(Array)
expect(message).toContain('All mentee emails with status pending')
})

it('should get all mentee emails with status pending', async () => {
const response = await adminAgent

Check warning on line 80 in src/routes/admin/mentee/mentee.route.test.ts

View workflow job for this annotation

GitHub Actions / build

'response' is assigned a value but never used
.get('/api/admin/mentee/emails?status=wrongstatus')
.expect(400)
})
})

0 comments on commit 8c082f5

Please sign in to comment.