Skip to content

Commit 244a4e2

Browse files
committed
cleaning up test, moving to auth
1 parent 239fea3 commit 244a4e2

File tree

2 files changed

+74
-143
lines changed

2 files changed

+74
-143
lines changed

test/auth.js

+74
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const createdID = []
1818
let verification = ''
1919
let verificationForgot = ''
2020
const email = faker.internet.email()
21+
const failedLoginAttempts = 5
22+
const badUser = {
23+
name: 'Bad user',
24+
25+
password: '54321'
26+
}
27+
const badLoginDetails = {
28+
29+
password: '12345'
30+
}
2131

2232
chai.use(chaiHttp)
2333

@@ -180,6 +190,70 @@ describe('*********** AUTH ***********', () => {
180190
})
181191
})
182192

193+
describe('/POST register', () => {
194+
it('it should POST register', (done) => {
195+
chai
196+
.request(server)
197+
.post('/register')
198+
.send(badUser)
199+
.end((err, res) => {
200+
res.should.have.status(201)
201+
res.body.should.be.an('object')
202+
res.body.should.include.keys('token', 'user')
203+
createdID.push(res.body.user._id)
204+
done()
205+
})
206+
})
207+
})
208+
209+
describe('/POST login', () => {
210+
for (let x = 1; x < failedLoginAttempts + 1; x++) {
211+
it(`it should NOT POST login after password fail #${x}`, (done) => {
212+
chai
213+
.request(server)
214+
.post('/login')
215+
.send(badLoginDetails)
216+
.end((err, res) => {
217+
res.should.have.status(409)
218+
res.body.should.be.a('object')
219+
res.body.should.have.property('errors').that.has.property('msg')
220+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
221+
done()
222+
})
223+
})
224+
}
225+
226+
it('it should NOT POST login after password fail #6 and be blocked', (done) => {
227+
chai
228+
.request(server)
229+
.post('/login')
230+
.send(badLoginDetails)
231+
.end((err, res) => {
232+
res.should.have.status(409)
233+
res.body.should.be.a('object')
234+
res.body.should.have.property('errors').that.has.property('msg')
235+
res.body.errors.should.have.property('msg').eql('BLOCKED_USER')
236+
done()
237+
})
238+
})
239+
240+
it('it should NOT POST login after being blocked sending post with correct password', (done) => {
241+
chai
242+
.request(server)
243+
.post('/login')
244+
.send({
245+
email: badUser.email,
246+
password: badUser.password
247+
})
248+
.end((err, res) => {
249+
res.should.have.status(409)
250+
res.body.should.be.a('object')
251+
res.body.should.have.property('errors').that.has.property('msg')
252+
res.body.errors.should.have.property('msg').eql('BLOCKED_USER')
253+
done()
254+
})
255+
})
256+
})
183257
after(() => {
184258
createdID.forEach((id) => {
185259
User.findByIdAndRemove(id, (err) => {

test/block.js

-143
This file was deleted.

0 commit comments

Comments
 (0)