-
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.
- Loading branch information
Showing
16 changed files
with
161 additions
and
14 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
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
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,3 +1,4 @@ | ||
//token type | ||
const tokenTypes = { | ||
ACCESS: 'access', | ||
REFRESH: 'refresh', | ||
|
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
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,24 @@ | ||
const multer = require('multer'); | ||
const fs = require('fs'); | ||
const storage = multer.diskStorage({ | ||
destination: function (req, file, callback) { | ||
const destPath = req.uploadPath; | ||
if (!fs.existsSync(destPath)) | ||
fs.mkdirSync(destPath); | ||
callback(null, destPath); | ||
}, | ||
filename: function (req, file, callback) { | ||
const parts = file.originalname.split("."); | ||
const extension = parts[parts.length - 1]; | ||
let fileName = file.fieldname + '-' + Date.now(); | ||
if (extension === 'png' || extension === 'jpeg' || extension === 'jpg') | ||
fileName += '.' + extension; | ||
|
||
callback(null, fileName); | ||
} | ||
}); | ||
|
||
|
||
const upload = multer({storage: storage}); | ||
|
||
module.exports = {upload}; |
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,8 @@ | ||
const sanitizeHtml = require('sanitize-html'); | ||
exports.sanitizeInput = (dirty, options) => { | ||
const htmlSanitizeOptions = { | ||
allowedTags: [], allowedAttributes: [] | ||
}; | ||
|
||
return sanitizeHtml(dirty, options || htmlSanitizeOptions); | ||
}; |
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,103 @@ | ||
const chai = require('chai'); | ||
|
||
const { expect } = chai; | ||
const sinon = require('sinon'); | ||
const httpStatus = require('http-status'); | ||
const AuthService = require('../../src/services/AuthService'); | ||
const UserDaom = require('../../src/daom/UserDaom'); | ||
const models = require('../../src/models'); | ||
|
||
const User = models.user; | ||
const bcrypt = require('bcryptjs'); | ||
|
||
let authService; | ||
const loginData = { | ||
email: 'example@mail.com', | ||
password: '123123Asd', | ||
}; | ||
const userData = { | ||
first_name: 'Samuel', | ||
last_name: 'Owadayo', | ||
email: 'example@mail.com', | ||
uuid: '4d85f12b-6e5b-468b-a971-eabe8acc9d08', | ||
}; | ||
describe('User Login test', () => { | ||
beforeEach(() => { | ||
authService = new AuthService(); | ||
}); | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('User Login successfully', async () => { | ||
const expectedResponse = { | ||
statusCode: httpStatus.OK, | ||
response: { | ||
status: true, | ||
code: httpStatus.OK, | ||
message: 'Login Successful', | ||
data: { | ||
id: 1, | ||
first_name: 'Samuel', | ||
last_name: 'Owadayo', | ||
email: 'example@mail.com', | ||
email_verified: 1, | ||
uuid: '4d85f12b-6e5b-468b-a971-eabe8acc9d08', | ||
}, | ||
}, | ||
}; | ||
userData.id = 1; | ||
userData.password = bcrypt.hashSync(loginData.password, 8); | ||
userData.email_verified = 1; | ||
const userModel = new User(userData); | ||
|
||
sinon.stub(UserDaom.prototype, 'findByEmail').callsFake((email) => { | ||
return userModel; | ||
}); | ||
const userLogin = await authService.loginWithEmailPassword( | ||
loginData.email, | ||
loginData.password, | ||
); | ||
expect(userLogin).to.deep.include(expectedResponse); | ||
}); | ||
|
||
it('should show INVALID EMAIL ADDRESS message', async () => { | ||
const expectedResponse = { | ||
statusCode: httpStatus.BAD_REQUEST, | ||
response: { | ||
status: false, | ||
code: httpStatus.BAD_REQUEST, | ||
message: 'Invalid Email Address!', | ||
}, | ||
}; | ||
|
||
sinon.stub(UserDaom.prototype, 'findByEmail').callsFake(() => { | ||
return null; | ||
}); | ||
const response = await authService.loginWithEmailPassword('test@mail.com', '23232132'); | ||
expect(response).to.deep.include(expectedResponse); | ||
}); | ||
|
||
it('Wrong Password', async () => { | ||
const expectedResponse = { | ||
statusCode: httpStatus.BAD_REQUEST, | ||
response: { | ||
status: false, | ||
code: httpStatus.BAD_REQUEST, | ||
message: 'Wrong Password!', | ||
}, | ||
}; | ||
userData.id = 1; | ||
userData.password = bcrypt.hashSync('2322342343', 8); | ||
userData.email_verified = 1; | ||
const userModel = new User(userData); | ||
sinon.stub(UserDaom.prototype, 'findByEmail').callsFake((email) => { | ||
return userModel; | ||
}); | ||
const userLogin = await authService.loginWithEmailPassword( | ||
loginData.email, | ||
loginData.password, | ||
); | ||
expect(userLogin).to.deep.include(expectedResponse); | ||
}); | ||
}); |