Skip to content

Commit

Permalink
Merge branch 'sef-global:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sathudeva7 authored Dec 26, 2023
2 parents eb08bf3 + 7c391bb commit 1d6345e
Show file tree
Hide file tree
Showing 15 changed files with 673 additions and 678 deletions.
907 changes: 490 additions & 417 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "nodemon --watch 'src/**/*.ts' --exec ts-node-dev --respawn src/server.ts",
"build": "tsc",
"test": "jest --forceExit",
"test": "jest",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write \"src/**/*.ts\""
Expand Down Expand Up @@ -53,7 +53,7 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^29.6.1",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"prettier": "^3.0.0",
"supertest": "^6.3.3",
Expand Down
19 changes: 0 additions & 19 deletions src/configs/db.test.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/controllers/admin/email.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Request, Response } from 'express'
import type { ApiResponse } from '../../types'
import { getAllMenteeEmailsService } from '../../services/admin/email.service'
import { ApplicationStatus } from '../../enums'

export const getAllMenteeEmails = async (
req: Request,
res: Response
): Promise<ApiResponse<string[]>> => {
try {
const status = req.query.status
if (
status === ApplicationStatus.APPROVED ||
status === ApplicationStatus.REJECTED ||
status === ApplicationStatus.PENDING
) {
const { emails, statusCode, message } = await getAllMenteeEmailsService(
status
)
return res.status(statusCode).json({ emails, message })
} else {
return res.status(400).json({ message: 'Invalid Status' })
}
} catch (err) {
console.error(err)
return res.status(500).json({ error: err || 'Internal Server Error' })
}
}
2 changes: 2 additions & 0 deletions src/routes/admin/admin.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import mentorRouter from './mentor/mentor.route'
import categoryRouter from './category/category.route'
import platformRouter from './platform/platform.route'
import emailTemplateRouter from './email/emailTemplate.route'
import menteeRouter from './mentee/mentee.route'

const adminRouter = express()

adminRouter.use('/users', userRouter)
adminRouter.use('/mentors', mentorRouter)
adminRouter.use('/mentee', menteeRouter)
adminRouter.use('/categories', categoryRouter)
adminRouter.use('/platform', platformRouter)
adminRouter.use('/emailTemplate', emailTemplateRouter)
Expand Down
4 changes: 4 additions & 0 deletions src/routes/admin/category/category.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ describe('Admin category routes', () => {
.send({ categoryName: 'Science' })
.expect(403)
})

afterAll(async () => {
await dataSource.destroy()
})
})
4 changes: 4 additions & 0 deletions src/routes/admin/email/emailTemplate.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ describe('Admin email template routes', () => {

expect(emailTemplate).toHaveProperty('content')
})

afterAll(async () => {
await dataSource.destroy()
})
})
88 changes: 88 additions & 0 deletions src/routes/admin/mentee/mentee.route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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'

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

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

describe('Admin mentee 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 throw status code 400', async () => {
const response = await adminAgent
.get('/api/admin/mentee/emails?status=wrongstatus')
.expect(400)
const { message } = response.body
expect(message).toContain('Invalid Status')
})

afterAll(async () => {
await dataSource.destroy()
})
})
9 changes: 9 additions & 0 deletions src/routes/admin/mentee/mentee.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from 'express'
import { requireAuth } from '../../../controllers/auth.controller'
import { getAllMenteeEmails } from '../../../controllers/admin/email.controller'

const menteeRouter = express.Router()

menteeRouter.get('/emails/', requireAuth, getAllMenteeEmails)

export default menteeRouter
4 changes: 4 additions & 0 deletions src/routes/admin/platform/platform.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ describe('Admin platform routes', () => {
})
.expect(403)
})

afterAll(async () => {
await dataSource.destroy()
})
})
4 changes: 4 additions & 0 deletions src/routes/admin/user/user.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ describe('Admin user routes', () => {
expect(userProfile).not.toHaveProperty('password')
})
})

afterAll(async () => {
await dataSource.destroy()
})
})
5 changes: 5 additions & 0 deletions src/routes/category/category.route.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { startServer } from '../../app'
import type { Express } from 'express'
import supertest from 'supertest'
import { dataSource } from '../../configs/dbConfig'

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

Expand All @@ -18,4 +19,8 @@ describe('Category route', () => {

expect(response.body).toHaveProperty('categories')
})

afterAll(async () => {
await dataSource.destroy()
})
})
120 changes: 0 additions & 120 deletions src/routes/mentor/mentor.route.test.ts

This file was deleted.

Loading

0 comments on commit 1d6345e

Please sign in to comment.