-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.js
136 lines (122 loc) · 3.51 KB
/
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const chai = require('chai');
const chaiHttp = require('chai-http');
const { should } = chai;
const { server } = require('./index.js');
const { v4: uuidv4 } = require('uuid');
should();
chai.use(chaiHttp);
describe('API Tests', function() {
let callId;
const newItem = {
name: 'Burger',
description: 'Delicious beef burger',
price: 8.99,
category: 'Main'
};
before(async function() {
// Start the server before running tests
if (!server.listening) {
await new Promise(resolve => server.listen(3001, resolve));
}
});
after(async function() {
// Close the server after running tests
if (server.listening) {
await new Promise(resolve => server.close(resolve));
}
});
describe('GET /menu', () => {
it('it should GET the menu', (done) => {
chai.request(server)
.get('/menu')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('array');
done();
});
});
});
describe('POST /menu/items', () => {
it('it should POST an item to the menu', (done) => {
chai.request(server)
.post('/menu/items')
.send(newItem)
.end((err, res) => {
res.should.have.status(200);
res.text.should.equal('successfully added item to menu');
done();
});
});
});
describe('POST /calls', () => {
it('it should CREATE a call', (done) => {
chai.request(server)
.post('/calls')
.end((err, res) => {
res.should.have.status(200);
res.text.should.be.a('string');
callId = res.text;
console.log('callId:', callId);
done();
});
});
});
describe('GET /calls/:id', () => {
it('it should GET a call by id', (done) => {
chai.request(server)
.get(`/calls/${callId}`)
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('id').eql(callId);
done();
});
});
});
describe('GET /calls/:id/order', () => {
it('it should GET an order by call id', (done) => {
chai.request(server)
.get(`/calls/${callId}/order`)
.end((err, res) => {
res.should.have.status(200);
done();
});
});
});
describe('POST /calls/:id/order/items', () => {
it('it should ADD an item to an order', (done) => {
chai.request(server)
.post(`/calls/${callId}/order/items`)
.send({ item: newItem.name })
.end((err, res) => {
res.should.have.status(200);
console.log
res.text.should.equal('We were able to successfully add the item to the order!');
done();
});
});
});
describe('DELETE /calls/:id/order/items', () => {
it('it should REMOVE an item from an order', (done) => {
chai.request(server)
.delete(`/calls/${callId}/order/items`)
.send({ item: newItem.name })
.end((err, res) => {
res.should.have.status(200);
res.text.should.equal('We were able to successfully remove the item from the order!');
done();
});
});
});
describe('DELETE /menu/items', () => {
it('it should DELETE all items from the menu', (done) => {
chai.request(server)
.delete('/menu/items')
.end((err, res) => {
res.should.have.status(200);
res.text.should.equal('successfully cleared the menu');
done();
});
});
});
});