-
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.
feat(auth): set up authentication and authorization
- implement endpoint for user signup and login - implement middleware for authenticating jwt tokens - implement role checking middleware [Delivers #2]
- Loading branch information
Showing
8 changed files
with
67 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export {}; | ||
const request = require('supertest'); | ||
const app = require('../src/server'); | ||
const app = require('../src/app'); | ||
const bcrypt = require('bcrypt'); | ||
const { | ||
signUpSchema, | ||
|
@@ -27,12 +27,12 @@ describe('Auth Controller Tests', () => { | |
}; | ||
|
||
const returnedUser = { | ||
_id:"some id", | ||
fullName:"mock user", | ||
email:"[email protected]", | ||
password:"password1234", | ||
createdAt: "some date", | ||
updatedAt: "some date" | ||
_id:'some id', | ||
fullName:'mock user', | ||
email:'[email protected]', | ||
password:'password1234', | ||
createdAt: 'some date', | ||
updatedAt: 'some date' | ||
} | ||
|
||
it('should return a 201 if signup is successful', async () => { | ||
|
@@ -61,12 +61,12 @@ describe('Auth Controller Tests', () => { | |
signUpSchema.validate.mockReturnValueOnce({ error: null }); | ||
|
||
User.findOne.mockImplementationOnce(() => Promise.resolve({ | ||
_id:"some id", | ||
fullName:"mock user", | ||
email:"[email protected]", | ||
password:"password1234", | ||
createdAt: "some date", | ||
updatedAt: "some date" | ||
_id:'some id', | ||
fullName:'mock user', | ||
email:'[email protected]', | ||
password:'password1234', | ||
createdAt: 'some date', | ||
updatedAt: 'some date' | ||
})); | ||
|
||
const response = await request(app).post('/api/auth/signup').send(signUpFormData); | ||
|
@@ -89,7 +89,7 @@ describe('Auth Controller Tests', () => { | |
|
||
bcrypt.compare.mockResolvedValueOnce(true) | ||
|
||
jwt.sign.mockResolvedValueOnce("fake token") | ||
jwt.sign.mockResolvedValueOnce('fake token') | ||
|
||
const response = await request(app).post('/api/auth/login').send(loginFormData); | ||
expect(response.status).toBe(200); | ||
|
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,20 +1,11 @@ | ||
const { tester } = require('../src/controllers/testController'); | ||
export {} | ||
const request = require('supertest'); | ||
const app = require('../src/app'); | ||
|
||
const res: any = {}; | ||
|
||
(res.json = jest.fn((x: Object) => x)), | ||
(res.status = jest.fn((x: number) => res)); | ||
|
||
const req: any = { | ||
body: { | ||
name: 'test', | ||
}, | ||
}; | ||
|
||
describe('Test', () => { | ||
it('should return 200 successful upon testing route', async () => { | ||
await tester(req, res); | ||
|
||
expect(res.status).toHaveBeenCalledWith(200); | ||
const response = await request(app).get('/api/test') | ||
expect(response.status).toBe(200); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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,15 @@ | ||
export {} | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const routes = require('./routes/index'); | ||
const swaggerUi = require('swagger-ui-express'); | ||
const swaggerSpec = require('./docs/swaggerconfig'); | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
app.use(cors()); | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); | ||
app.use('/api', routes); | ||
|
||
module.exports = app; |
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