Skip to content

Commit 37a2265

Browse files
committed
Tests for refresh token
1 parent 1a12b17 commit 37a2265

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

test/auth.js

+38-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const loginDetails = {
1313
1414
password: '12345'
1515
}
16+
let token = ''
1617
const createdID = []
1718
let verification = ''
1819
let verificationForgot = ''
@@ -40,6 +41,7 @@ describe('*********** AUTH ***********', () => {
4041
.get('/404url')
4142
.end((err, res) => {
4243
res.should.have.status(404)
44+
res.body.should.be.an('object')
4345
done()
4446
})
4547
})
@@ -53,7 +55,9 @@ describe('*********** AUTH ***********', () => {
5355
.send(loginDetails)
5456
.end((err, res) => {
5557
res.should.have.status(200)
58+
res.body.should.be.an('object')
5659
res.body.should.have.property('token')
60+
token = res.body.token
5761
done()
5862
})
5963
})
@@ -72,6 +76,7 @@ describe('*********** AUTH ***********', () => {
7276
.send(user)
7377
.end((err, res) => {
7478
res.should.have.status(201)
79+
res.body.should.be.an('object')
7580
res.body.should.include.keys('token', 'user')
7681
createdID.push(res.body.user._id)
7782
verification = res.body.user.verification
@@ -107,15 +112,16 @@ describe('*********** AUTH ***********', () => {
107112
})
108113
.end((err, res) => {
109114
res.should.have.status(200)
115+
res.body.should.be.an('object')
110116
res.body.should.include.keys('email', 'verified')
111117
res.body.verified.should.equal(true)
112118
done()
113119
})
114120
})
115121
})
116122

117-
describe('/POST forgotPassword', () => {
118-
it('it should POST forgotPassword', done => {
123+
describe('/POST forgot', () => {
124+
it('it should POST forgot', done => {
119125
chai
120126
.request(server)
121127
.post('/forgot')
@@ -124,15 +130,16 @@ describe('*********** AUTH ***********', () => {
124130
})
125131
.end((err, res) => {
126132
res.should.have.status(200)
133+
res.body.should.be.an('object')
127134
res.body.should.include.keys('msg', 'verification')
128135
verificationForgot = res.body.verification
129136
done()
130137
})
131138
})
132139
})
133140

134-
describe('/POST resetPassword', () => {
135-
it('it should POST resetPassword', done => {
141+
describe('/POST reset', () => {
142+
it('it should POST reset', done => {
136143
chai
137144
.request(server)
138145
.post('/reset')
@@ -149,6 +156,33 @@ describe('*********** AUTH ***********', () => {
149156
})
150157
})
151158

159+
describe('/POST token', () => {
160+
it('it should NOT be able to consume the route since no token was sent', done => {
161+
chai
162+
.request(server)
163+
.post('/token')
164+
.end((err, res) => {
165+
res.should.have.status(401)
166+
done()
167+
})
168+
})
169+
it('it should GET a fresh token', done => {
170+
chai
171+
.request(server)
172+
.post('/token')
173+
.set('Authorization', `Bearer ${token}`)
174+
.send({
175+
token
176+
})
177+
.end((err, res) => {
178+
res.should.have.status(200)
179+
res.body.should.be.an('object')
180+
res.body.should.have.property('token')
181+
done()
182+
})
183+
})
184+
})
185+
152186
after(() => {
153187
createdID.forEach(id => {
154188
User.findByIdAndRemove(id, err => {

0 commit comments

Comments
 (0)