Skip to content

Commit 75fd80b

Browse files
authored
Merge pull request #36 from davellanedam/development
Development
2 parents eff60dc + 694e99e commit 75fd80b

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v6.1.13 (May 18, 2019)
2+
3+
- Add role validation to User creator, Fixes [#35](https://github.com/davellanedam/node-express-mongodb-jwt-rest-api-skeleton/issues/35)
4+
15
## v6.1.12 (May 17, 2019)
26

37
- NPM updated

app/controllers/users.validate.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ exports.createItem = [
3535
.withMessage('MISSING')
3636
.not()
3737
.isEmpty()
38-
.withMessage('IS_EMPTY'),
38+
.withMessage('IS_EMPTY')
39+
.isIn(['user', 'admin'])
40+
.withMessage('USER_NOT_IN_KNOWN_ROLE'),
3941
check('phone')
4042
.exists()
4143
.withMessage('MISSING')

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-express-mongodb-jwt-rest-api-skeleton",
3-
"version": "6.1.12",
3+
"version": "6.1.13",
44
"description": "Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)",
55
"license": "MIT",
66
"repository": {

test/users.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ describe('*********** USERS ***********', () => {
131131
done()
132132
})
133133
})
134+
it('it should NOT POST a user with not known role', done => {
135+
const user = {
136+
name: faker.random.words(),
137+
email,
138+
password: faker.random.words(),
139+
role: faker.random.words()
140+
}
141+
chai
142+
.request(server)
143+
.post('/users')
144+
.set('Authorization', `Bearer ${token}`)
145+
.send(user)
146+
.end((err, res) => {
147+
res.should.have.status(422)
148+
res.body.should.be.a('object')
149+
res.body.should.have.property('errors')
150+
done()
151+
})
152+
})
134153
})
135154
describe('/GET/:id user', () => {
136155
it('it should GET a user by the given id', done => {

0 commit comments

Comments
 (0)