-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.test.js
112 lines (95 loc) · 2.6 KB
/
api.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const request = require('supertest');
const app = require('../src/app');
describe('Test the invalid requests', () => {
test('Invalid endpoint it should response 404', done => {
request(app)
.get('/invalidEndPoint')
.then(response => {
expect(response.statusCode).toBe(404);
done();
});
});
test('Invalid params it should response 400', done => {
request(app)
.post('/api/filter')
.send({ foo: 'bar' })
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
test('Invalid params it should response 400', done => {
request(app)
.post('/api/filter')
.send({
startDate: '20-06-1900',
endDate: 0,
minCount: 'Hello',
maxCount: ''
})
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
test('MinCount > maxcount it should response 400', done => {
request(app)
.post('/api/filter')
.send({
startDate: '20-06-1900',
endDate: "20-06-1991",
minCount: 300,
maxCount: 200,
})
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
test('If min count or max count is less than zero it should response 400', done => {
request(app)
.post('/api/filter')
.send({
startDate: '20-06-1900',
endDate: "20-06-1991",
minCount: -1,
maxCount: 200,
})
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
test('If startDate is greater than endDate it should response 400', done => {
request(app)
.post('/api/filter')
.send({
startDate: '20-06-2010',
endDate: "20-06-1991",
minCount: 100,
maxCount: 5000,
})
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
});
describe('Test main endpoint', () => {
test('It should response with Success', done => {
request(app)
.post('/api/filter')
.send({
startDate: '2016-01-26',
endDate: '2017-02-02',
minCount: 1000,
maxCount: 3000
})
.then(response => {
expect(response.statusCode).toBe(200);
expect(response.body.code).toBe(0);
expect(response.body.msg).toBe('Success');
done();
});
});
});