-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added middleware verification and fix column name
- Loading branch information
1 parent
30fc8a1
commit 757e3c4
Showing
8 changed files
with
89 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const Yup = require('yup'); | ||
|
||
module.exports = { | ||
async SingIn(req, res, next) { | ||
try { | ||
const schema = Yup.object().shape({ | ||
email: Yup.string().email().required(), | ||
senha: Yup.string().required() | ||
}); | ||
|
||
await schema.validate(req.body, { abortEarly: false }); | ||
|
||
return next(); | ||
} catch (error) { | ||
return res.json({ error }); | ||
} | ||
}, | ||
async SingUp(req, res, next) { | ||
try { | ||
const schema = Yup.object().shape({ | ||
nome: Yup.string().required(), | ||
email: Yup.string().email().required(), | ||
senha: Yup.string().required(), | ||
telefones: Yup.array( | ||
Yup.object().shape({ | ||
numero: Yup.string().required(), | ||
ddd: Yup.string().required() | ||
}) | ||
) | ||
}); | ||
|
||
await schema.validate(req.body, { abortEarly: false }); | ||
|
||
return next(); | ||
} catch (error) { | ||
return res.json({ error }); | ||
} | ||
} | ||
}; |
File renamed without changes.
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,26 +1,14 @@ | ||
const request = require('supertest'); | ||
const app = require('../src/app'); | ||
|
||
describe('Authentication', () => { | ||
it('should create session authentication', async (done) => { | ||
const response = await request(app).post('/login').send({ | ||
email: '[email protected]', | ||
password: '123' | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('Login', () => { | ||
describe('Create', () => { | ||
it('should create user session', async (done) => { | ||
const response = await request(app) | ||
.post('/user/create') | ||
.send({ | ||
name: 'Caio Agiani', | ||
email: 'caio.agiani14@gmail.com', | ||
password: '123', | ||
nome: 'Caio Agiani', | ||
email: `caio.agiani${Math.floor(Math.random() * 9999) + 1}@gmail.com`, | ||
senha: '123123123', | ||
telefones: [ | ||
{ | ||
numero: '999865802', | ||
|
@@ -34,10 +22,22 @@ describe('Login', () => { | |
}); | ||
}); | ||
|
||
describe('Authentication', () => { | ||
it('should create session authentication', async (done) => { | ||
const response = await request(app).post('/login').send({ | ||
email: '[email protected]', | ||
senha: '123' | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('User', () => { | ||
it('should list user by id', async (done) => { | ||
const response = await request(app) | ||
.get('/user/5ec46b12bf6de842bc001b08') | ||
.get('/user/5f877dc25d9f7b5c08f77c16') | ||
.send(); | ||
|
||
expect(response.status).toBe(401); | ||
|