Skip to content

Commit 5886507

Browse files
committed
adding blocking test
1 parent 9027a07 commit 5886507

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

test/block.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/* eslint handle-callback-err: "off"*/
2+
3+
process.env.NODE_ENV = 'test'
4+
5+
const chai = require('chai')
6+
const chaiHttp = require('chai-http')
7+
const server = require('../server')
8+
const User = require('../app/models/user')
9+
10+
const badUser = {
11+
name: 'Bad user',
12+
email: 'bad@user.com',
13+
password: '54321'
14+
}
15+
const badLoginDetails = {
16+
email: 'bad@user.com',
17+
password: '12345'
18+
}
19+
const createdID = []
20+
21+
chai.use(chaiHttp)
22+
describe('*********** BLOCK ***********', () => {
23+
it('it should POST register', (done) => {
24+
chai
25+
.request(server)
26+
.post('/register')
27+
.send(badUser)
28+
.end((err, res) => {
29+
res.should.have.status(201)
30+
res.body.should.be.an('object')
31+
res.body.should.include.keys('token', 'user')
32+
createdID.push(res.body.user._id)
33+
done()
34+
})
35+
})
36+
})
37+
38+
describe('/POST login', () => {
39+
it('it should NOT POST login after password fail #1', (done) => {
40+
chai
41+
.request(server)
42+
.post('/login')
43+
.send(badLoginDetails)
44+
.end((err, res) => {
45+
res.should.have.status(409)
46+
res.body.should.be.a('object')
47+
res.body.should.have.property('errors').that.has.property('msg')
48+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
49+
done()
50+
})
51+
})
52+
it('it should NOT POST login after password fail #2', (done) => {
53+
chai
54+
.request(server)
55+
.post('/login')
56+
.send(badLoginDetails)
57+
.end((err, res) => {
58+
res.should.have.status(409)
59+
res.body.should.be.a('object')
60+
res.body.should.have.property('errors').that.has.property('msg')
61+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
62+
done()
63+
})
64+
})
65+
it('it should NOT POST login after password fail #3', (done) => {
66+
chai
67+
.request(server)
68+
.post('/login')
69+
.send(badLoginDetails)
70+
.end((err, res) => {
71+
res.should.have.status(409)
72+
res.body.should.be.a('object')
73+
res.body.should.have.property('errors').that.has.property('msg')
74+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
75+
done()
76+
})
77+
})
78+
it('it should NOT POST login after password fail #4', (done) => {
79+
chai
80+
.request(server)
81+
.post('/login')
82+
.send(badLoginDetails)
83+
.end((err, res) => {
84+
res.should.have.status(409)
85+
res.body.should.be.a('object')
86+
res.body.should.have.property('errors').that.has.property('msg')
87+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
88+
done()
89+
})
90+
})
91+
it('it should NOT POST login after password fail #5', (done) => {
92+
chai
93+
.request(server)
94+
.post('/login')
95+
.send(badLoginDetails)
96+
.end((err, res) => {
97+
res.should.have.status(409)
98+
res.body.should.be.a('object')
99+
res.body.should.have.property('errors').that.has.property('msg')
100+
res.body.errors.should.have.property('msg').eql('WRONG_PASSWORD')
101+
done()
102+
})
103+
})
104+
it('it should NOT POST login after password fail #6 and be blocked', (done) => {
105+
chai
106+
.request(server)
107+
.post('/login')
108+
.send(badLoginDetails)
109+
.end((err, res) => {
110+
res.should.have.status(409)
111+
res.body.should.be.a('object')
112+
res.body.should.have.property('errors').that.has.property('msg')
113+
res.body.errors.should.have.property('msg').eql('BLOCKED_USER')
114+
done()
115+
})
116+
})
117+
it('it should NOT POST login after being blocked sending post with correct password', (done) => {
118+
chai
119+
.request(server)
120+
.post('/login')
121+
.send({
122+
email: badUser.email,
123+
password: badUser.password
124+
})
125+
.end((err, res) => {
126+
res.should.have.status(409)
127+
res.body.should.be.a('object')
128+
res.body.should.have.property('errors').that.has.property('msg')
129+
res.body.errors.should.have.property('msg').eql('BLOCKED_USER')
130+
done()
131+
})
132+
})
133+
})
134+
135+
after(() => {
136+
createdID.forEach((id) => {
137+
User.findByIdAndRemove(id, (err) => {
138+
if (err) {
139+
console.log(err)
140+
}
141+
})
142+
})
143+
})

0 commit comments

Comments
 (0)