Skip to content

Commit 50bf997

Browse files
authored
Merge pull request #348 from ASHWINIAJIT/user-status
Added status property in user object
2 parents c9437a0 + 76d5c29 commit 50bf997

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

constants/users.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const userStatusEnum = ['ooo', 'idle', 'active']
2+
module.exports = userStatusEnum

docs/swaggerDefinition.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ const swaggerOptions = {
445445
},
446446
tokens: {
447447
type: 'object'
448+
},
449+
status: {
450+
type: 'string'
448451
}
449452
}
450453
},

middlewares/validators/user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const joi = require('joi')
2+
const userStatusEnum = require('../../constants/users')
23

34
const updateUser = async (req, res, next) => {
45
const schema = joi.object().keys({
@@ -14,7 +15,8 @@ const updateUser = async (req, res, next) => {
1415
linkedin_id: joi.string().optional(),
1516
twitter_id: joi.string().optional(),
1617
instagram_id: joi.string().optional(),
17-
website: joi.string().optional()
18+
website: joi.string().optional(),
19+
status: joi.any().valid(...userStatusEnum).optional()
1820
})
1921

2022
try {

test/fixtures/user/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = () => {
2323
2424
tokens: {
2525
githubAccessToken: 'githubAccessToken'
26-
}
26+
},
27+
status: 'active'
2728
},
2829
{
2930
username: 'nikhil',

test/integration/users.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,46 @@ describe('Users', function () {
4444
return done()
4545
})
4646
})
47+
48+
it('Should update the user status', function (done) {
49+
chai
50+
.request(app)
51+
.patch('/users/self')
52+
.set('cookie', `${cookieName}=${jwt}`)
53+
.send({
54+
status: 'ooo'
55+
})
56+
.end((err, res) => {
57+
if (err) { return done(err) }
58+
59+
expect(res).to.have.status(204)
60+
61+
return done()
62+
})
63+
})
64+
65+
it('Should return 400 for invalid status value', function (done) {
66+
chai
67+
.request(app)
68+
.patch('/users/self')
69+
.set('cookie', `${cookieName}=${jwt}`)
70+
.send({
71+
status: 'blah'
72+
})
73+
.end((err, res) => {
74+
if (err) { return done(err) }
75+
76+
expect(res).to.have.status(400)
77+
expect(res.body).to.be.an('object')
78+
expect(res.body).to.eql({
79+
statusCode: 400,
80+
error: 'Bad Request',
81+
message: '"status" must be one of [ooo, idle, active]'
82+
})
83+
84+
return done()
85+
})
86+
})
4787
})
4888

4989
describe('GET /users', function () {

0 commit comments

Comments
 (0)