-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sef-global:main' into main
- Loading branch information
Showing
15 changed files
with
673 additions
and
678 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.