|
1
|
|
|
process.env.NODE_ENV = 'test'; |
|
2
|
|
|
|
|
3
|
|
|
const chai = require('chai'); |
|
4
|
|
|
const chaiHttp = require('chai-http'); |
|
5
|
|
|
const server = require('../app.js'); |
|
6
|
|
|
|
|
7
|
|
|
chai.should(); |
|
8
|
|
|
|
|
9
|
|
|
chai.use(chaiHttp); |
|
10
|
|
|
|
|
11
|
|
|
describe('Reports', () => { |
|
12
|
|
|
describe('GET /reports/week/1', () => { |
|
13
|
|
|
it('200 HAPPY PATH', (done) => { |
|
14
|
|
|
chai.request(server) |
|
15
|
|
|
.get("/reports/week/1") |
|
16
|
|
|
.end((err, res) => { |
|
17
|
|
|
res.should.have.status(200); |
|
18
|
|
|
res.body.should.be.an("object"); |
|
19
|
|
|
// res.body.data.should.be.an("array"); |
|
20
|
|
|
// res.body.data.length.should.be.above(0); |
|
21
|
|
|
|
|
22
|
|
|
done(); |
|
23
|
|
|
}); |
|
24
|
|
|
}); |
|
25
|
|
|
}); |
|
26
|
|
|
|
|
27
|
|
|
describe('POST /reports', () => { |
|
28
|
|
|
it('should get 401 as we do not provide valid token', (done) => { |
|
29
|
|
|
let payload={ |
|
30
|
|
|
"text":"updated text", |
|
31
|
|
|
"week":1 |
|
32
|
|
|
} |
|
33
|
|
|
chai.request(server) |
|
34
|
|
|
.post("/reports") |
|
35
|
|
|
.send(payload) |
|
36
|
|
|
.end((err, res) => { |
|
37
|
|
|
res.should.have.status(401); |
|
38
|
|
|
res.body.should.be.an("object"); |
|
39
|
|
|
done(); |
|
40
|
|
|
}); |
|
41
|
|
|
}); |
|
42
|
|
|
}); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
describe('Login', () => { |
|
46
|
|
|
describe('GET /login', () => { |
|
47
|
|
|
it('200 HAPPY PATH', (done) => { |
|
48
|
|
|
chai.request(server) |
|
49
|
|
|
.get("/login") |
|
50
|
|
|
.end((err, res) => { |
|
51
|
|
|
res.should.have.status(200); |
|
52
|
|
|
res.body.should.be.an("object"); |
|
53
|
|
|
|
|
54
|
|
|
done(); |
|
55
|
|
|
}); |
|
56
|
|
|
}); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
describe('POST /login', () => { |
|
60
|
|
|
it('Should get 401 as user and pass is wrong', (done) => { |
|
61
|
|
|
let user = { |
|
62
|
|
|
email: "[email protected]", |
|
63
|
|
|
password: "123test", |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
chai.request(server) |
|
67
|
|
|
.post("/login") |
|
68
|
|
|
.send(user) |
|
69
|
|
|
.end((err, res) => { |
|
70
|
|
|
res.should.have.status(401); |
|
71
|
|
|
res.body.should.be.an("object"); |
|
72
|
|
|
res.body.errors.status.should.be.equal(401); |
|
73
|
|
|
done(); |
|
74
|
|
|
}); |
|
75
|
|
|
}); |
|
76
|
|
|
}); |
|
77
|
|
|
}); |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
describe('Register', () => { |
|
82
|
|
|
describe('GET /register', () => { |
|
83
|
|
|
it('200 HAPPY PATH', (done) => { |
|
84
|
|
|
chai.request(server) |
|
85
|
|
|
.get("/register") |
|
86
|
|
|
.end((err, res) => { |
|
87
|
|
|
res.should.have.status(200); |
|
88
|
|
|
res.body.should.be.an("object"); |
|
89
|
|
|
|
|
90
|
|
|
done(); |
|
91
|
|
|
}); |
|
92
|
|
|
}); |
|
93
|
|
|
}); |
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
|