1
|
|
|
/* global it describe */ |
2
|
|
|
|
3
|
1 |
|
process.env.NODE_ENV = 'test'; |
4
|
|
|
|
5
|
|
|
//Require the dev-dependencies |
6
|
1 |
|
const chai = require('chai'); |
7
|
1 |
|
const chaiHttp = require('chai-http'); |
8
|
1 |
|
const server = require('../../app.js'); |
9
|
|
|
|
10
|
1 |
|
const HTMLParser = require('node-html-parser'); |
11
|
|
|
|
12
|
1 |
|
chai.should(); |
13
|
|
|
|
14
|
1 |
|
chai.use(chaiHttp); |
15
|
|
|
|
16
|
1 |
|
let apiKey = ""; |
17
|
|
|
|
18
|
1 |
|
describe('app', () => { |
19
|
1 |
|
describe('GET /', () => { |
20
|
1 |
|
it('200 HAPPY PATH getting base', (done) => { |
21
|
1 |
|
chai.request(server) |
22
|
|
|
.get("/") |
23
|
|
|
.end((err, res) => { |
24
|
1 |
|
res.should.have.status(200); |
25
|
|
|
|
26
|
1 |
|
done(); |
27
|
|
|
}); |
28
|
|
|
}); |
29
|
|
|
|
30
|
1 |
|
it('200 HAPPY PATH getting docs', (done) => { |
31
|
1 |
|
chai.request(server) |
32
|
|
|
.get("/v2") |
33
|
|
|
.end((err, res) => { |
34
|
1 |
|
res.should.have.status(200); |
35
|
|
|
|
36
|
1 |
|
done(); |
37
|
|
|
}); |
38
|
|
|
}); |
39
|
|
|
|
40
|
1 |
|
it('should get 401 as we do not provide valid api_key', (done) => { |
41
|
1 |
|
chai.request(server) |
42
|
|
|
.get("/v2/order") |
43
|
|
|
.end((err, res) => { |
44
|
1 |
|
res.should.have.status(401); |
45
|
1 |
|
res.body.should.be.an("object"); |
46
|
1 |
|
res.body.errors.status.should.be.equal(401); |
47
|
|
|
|
48
|
1 |
|
done(); |
49
|
|
|
}); |
50
|
|
|
}); |
51
|
|
|
|
52
|
1 |
|
it('should get 200 as we get apiKey', (done) => { |
53
|
1 |
|
let user = { |
54
|
|
|
email: "[email protected]", |
55
|
|
|
gdpr: "gdpr" |
56
|
|
|
}; |
57
|
|
|
|
58
|
1 |
|
chai.request(server) |
59
|
|
|
.post("/v2/auth/api_key/confirmation") |
60
|
|
|
.send(user) |
61
|
|
|
.end((err, res) => { |
62
|
1 |
|
res.should.have.status(200); |
63
|
|
|
|
64
|
1 |
|
let HTMLResponse = HTMLParser.parse(res.text); |
65
|
1 |
|
let apiKeyElement = HTMLResponse.querySelector('#apikey'); |
66
|
|
|
|
67
|
1 |
|
apiKey = apiKeyElement.childNodes[0].rawText; |
68
|
|
|
|
69
|
1 |
|
done(); |
70
|
|
|
}); |
71
|
|
|
}); |
72
|
|
|
|
73
|
1 |
|
it('404 not found for invalid GET route', (done) => { |
74
|
1 |
|
chai.request(server) |
75
|
|
|
.get("/v2/order?api_key=" + apiKey) |
76
|
|
|
.end((err, res) => { |
77
|
1 |
|
res.should.have.status(404); |
78
|
|
|
|
79
|
1 |
|
done(); |
80
|
|
|
}); |
81
|
|
|
}); |
82
|
|
|
|
83
|
1 |
|
it('404 not found for invalid GET route', (done) => { |
84
|
1 |
|
chai.request(server) |
85
|
|
|
.get("/v2/order?api_key=" + apiKey) |
86
|
|
|
.end((err, res) => { |
87
|
1 |
|
res.should.have.status(404); |
88
|
|
|
|
89
|
1 |
|
done(); |
90
|
|
|
}); |
91
|
|
|
}); |
92
|
|
|
|
93
|
1 |
|
it('404 not found for invalid POST route', (done) => { |
94
|
1 |
|
chai.request(server) |
95
|
|
|
.post("/v2/copy/products") |
96
|
|
|
.send({ api_key: apiKey }) |
97
|
|
|
.end((err, res) => { |
98
|
1 |
|
res.should.have.status(404); |
99
|
|
|
|
100
|
1 |
|
done(); |
101
|
|
|
}); |
102
|
|
|
}); |
103
|
|
|
}); |
104
|
|
|
}); |
105
|
|
|
|