Skip to content

Commit 30bd1d6

Browse files
committed
add tests for /v2/users endpoint
1 parent a344563 commit 30bd1d6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/tests/v2/user.routes.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe(`User tests (v${VERSION})`, function() {
1818
})
1919
after(async function() {
2020
await testUser.destroyToken()
21+
process.env.BYPASS_LOGIN = true
2122
})
2223

2324
it('should login', function (done) {
@@ -64,4 +65,34 @@ describe(`User tests (v${VERSION})`, function() {
6465
done()
6566
})
6667
})
68+
it('should get all users', function(done) {
69+
request(app)
70+
.get(`/v${VERSION}/users`)
71+
.set('Accept', 'application/json')
72+
.set('token', token)
73+
.send()
74+
.expect('Content-Type', 'application/json; charset=utf-8')
75+
.expect(200)
76+
.end((err, res) => {
77+
if (err) return done(err)
78+
expect(res.body).to.deep.include.members([{email: testUser.user.email, displayName: testUser.user.displayName}])
79+
done()
80+
})
81+
})
82+
it('should not get all users', function(done) {
83+
process.env.BYPASS_LOGIN = false
84+
request(app)
85+
.get(`/v${VERSION}/users`)
86+
.set('Accept', 'application/json')
87+
.set('token', randomWords())
88+
.send()
89+
.expect('Content-Type', 'application/json; charset=utf-8')
90+
.expect(403)
91+
.end((err, res) => {
92+
if (err) return done(err)
93+
expect(res.body.statusCode).to.equal(403)
94+
expect(res.body.message).to.equal('Access not permitted')
95+
done()
96+
})
97+
})
6798
})

0 commit comments

Comments
 (0)