-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SS-1.4' of https://github.com/Skill-Sync/SkillSync-Backend
- Loading branch information
Showing
10 changed files
with
272 additions
and
94 deletions.
There are no files selected for viewing
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
Empty file.
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 |
---|---|---|
@@ -1,83 +1,82 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
|
||
const { mongoConnect, mongoDisconnect } = require('../utils/mongoDB'); | ||
//--------------------------------// | ||
describe('Authentication and Authorization endpoints testing', () => { | ||
beforeAll(async () => { | ||
await mongoConnect(); | ||
}); | ||
beforeAll(async () => { | ||
await mongoConnect(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoDisconnect(); | ||
}); | ||
afterAll(async () => { | ||
await mongoDisconnect(); | ||
}); | ||
|
||
describe('Authentication', () => { | ||
const UserSignUpData = {}; | ||
const InvalidUserSignUpData = {}; | ||
describe('Authentication', () => { | ||
const UserSignUpData = {}; | ||
const InvalidUserSignUpData = {}; | ||
|
||
const MentorSignUpData = {}; | ||
const InvalidMentorSignUpData = {}; | ||
const MentorSignUpData = {}; | ||
const InvalidMentorSignUpData = {}; | ||
|
||
const UserLoginData = {}; | ||
const InvalidUserLoginData = {}; | ||
const UserLoginData = {}; | ||
const InvalidUserLoginData = {}; | ||
|
||
describe('Signup endpoints', () => { | ||
test('User signup should respond with 201', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(UserSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(201); | ||
expect(response.body.user.role).toBe('user'); | ||
}); | ||
describe('Signup endpoints', () => { | ||
test('User signup should respond with 201', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(UserSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(201); | ||
expect(response.body.user.role).toBe('user'); | ||
}); | ||
|
||
test('Mentor signup should respond with 201', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(MentorSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(201); | ||
expect(response.body.user.role).toBe('mentor'); | ||
}); | ||
test('Mentor signup should respond with 201', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(MentorSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(201); | ||
expect(response.body.user.role).toBe('mentor'); | ||
}); | ||
|
||
test('User signup should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(InvalidUserSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
test('User signup should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(InvalidUserSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
|
||
test('Mentor signup should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(InvalidMentorSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
}); | ||
test('Mentor signup should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/signup') | ||
.send(InvalidMentorSignUpData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
}); | ||
|
||
describe('Login endpoints', () => { | ||
test('User login should respond with 200', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/login') | ||
.send(UserLoginData) | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
describe('Login endpoints', () => { | ||
test('User login should respond with 200', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/login') | ||
.send(UserLoginData) | ||
.expect('Content-Type', /json/) | ||
.expect(200); | ||
}); | ||
|
||
test('User login should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/login') | ||
.send(InvalidUserLoginData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
test('User login should catch missing required properties', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/authRouter/login') | ||
.send(InvalidUserLoginData) | ||
.expect('Content-Type', /json/) | ||
.expect(400); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Authorization', () => { | ||
// Authorization endpoints such as ask for new access token using refresh token will be tested here | ||
}); | ||
describe('Authorization', () => { | ||
// Authorization endpoints such as ask for new access token using refresh token will be tested here | ||
}); | ||
}); |
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,49 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
const { mongoConnect, mongoDisconnect } = require('../utils/mongoDB'); | ||
//--------------------------------// | ||
const accessToken = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWNjZXNzIiwiaWQiOiI2NTA0YmRlYWExZjliMTU1NGI5YjAwNjUiLCJ1c2VyVHlwZSI6InVzZXIiLCJpYXQiOjE2OTQ4OTE1NDAsImV4cCI6MTY5NDg5MjQ0MH0.CNrsSxPBCJ3NveCQUyRolfBdbHws3H6suy4SH74lAls`; | ||
const refreshToken = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoicmVmcmVzaCIsImlkIjoiNjUwNGJkZWFhMWY5YjE1NTRiOWIwMDY1IiwidXNlclR5cGUiOiJ1c2VyIiwicmVmcmVzaFNlc3Npb24iOiI2NTA1ZmUxNGE5MDFjNGQ4YzUwOGFjMWYiLCJpYXQiOjE2OTQ4OTE1NDAsImV4cCI6MTY5NTQ5NjM0MH0.g-PRJ_sv3hjCQqGzFaLpsnzkmVIuOnkzRTYURiqE_3A`; | ||
//--------------------------------// | ||
|
||
const mockFriendship = { | ||
status: 'accepted' | ||
}; | ||
|
||
beforeAll(async () => { | ||
await mongoConnect(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoDisconnect(); | ||
}); | ||
|
||
describe('User Routes', () => { | ||
it('should get a list of user friends', async () => { | ||
const response = await request(app) | ||
.get('/users') | ||
.set('Authorization', `Bearer ${accessToken} ${refreshToken}`); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.body.status).toBe('success'); | ||
expect(response.body.friends).toBeDefined(); | ||
}); | ||
|
||
it('should create or edit a friendship', async () => { | ||
const response = await request(app) | ||
.post('/users/6504bdeaa1f9b1554b9b0065') | ||
.set('Authorization', `Bearer ${accessToken} ${refreshToken}`) | ||
.send(mockFriendship); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.body.newFriendship).toBeDefined(); | ||
}); | ||
|
||
it('should delete a friendship', async () => { | ||
const response = await request(app) | ||
.delete('/users/6504bdeaa1f9b1554b9b0065') | ||
.set('Authorization', `Bearer ${accessToken} ${refreshToken}`); | ||
|
||
expect(response.statusCode).toBe(204); | ||
}); | ||
}); |
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,84 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); // Assuming your Express app is in this file | ||
const { mongoConnect, mongoDisconnect } = require('../utils/mongoDB'); | ||
//--------------------------------// | ||
const User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JJovZsGCM`; | ||
//--------------------------------// | ||
const testUser = { | ||
_id: 'testUserId', | ||
userType: 'user' | ||
}; | ||
|
||
const testMeeting = { | ||
_id: '6504e775469e21d5c0bfef66', | ||
mentor: '6504bdf7a1f9b1554b9b0089', | ||
user: '6504bdeaa1f9b1554b9b0065' | ||
}; | ||
|
||
beforeAll(async () => { | ||
await mongoConnect(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mongoDisconnect(); | ||
}); | ||
|
||
describe('Express Routes', () => { | ||
it('should get user meetings', async () => { | ||
const response = await request(app) | ||
.get('/meetings') | ||
.set( | ||
'Authorization', | ||
`Bearer ${UserAccessToken} ${UserRefreshToken}` | ||
) | ||
.expect(200); | ||
|
||
expect(response.body.status).toBe('success'); | ||
expect(response.body.data.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('should get a meeting by ID', async () => { | ||
const response = await request(app) | ||
.get(`/meetings/${testMeeting._id}`) | ||
.set( | ||
'Authorization', | ||
`Bearer ${UserAccessToken} ${UserRefreshToken}` | ||
) | ||
.expect(200); | ||
|
||
expect(response.body.status).toBe('success'); | ||
expect(response.body.data._id).toBe(testMeeting._id); | ||
}); | ||
|
||
it('should create a new meeting', async () => { | ||
const response = await request(app) | ||
.patch(`/meetings/6504e775469e21d5c0bfef71`) | ||
.set( | ||
'Authorization', | ||
`Bearer ${UserAccessToken} ${UserRefreshToken}` | ||
) | ||
.send({}) | ||
.expect(200); | ||
|
||
expect(response.body.status).toBe('success'); | ||
expect(response.body.data.status).toBe('accepted'); | ||
}); | ||
|
||
it('should update a meeting', async () => { | ||
const response = await request(app) | ||
.post(`/meetings/6504e775469e21d5c0bfef71`) | ||
.set( | ||
'Authorization', | ||
`Bearer ${mentorAccessToken} ${mentorRefreshToken}` | ||
) | ||
.send({ status: 'accepted' }) | ||
.expect(200); | ||
|
||
expect(response.body.status).toBe('success'); | ||
expect(response.body.data.status).toBe('accepted'); | ||
}); | ||
}); |
Empty file.
Oops, something went wrong.