-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
98 lines (94 loc) · 3.02 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
//During test the env variable is set to test
process.env.NODE_ENV = "test";
const chai = require("chai");
const chaiHttp = require("chai-http");
const server = require("./server");
let should = chai.should();
chai.use(chaiHttp);
describe("Order API testing", () => {
const orderId = describe("/POST Order", () => {
it("It should save order and when give correct latitude / longitude", done => {
let payload = {
origin: [55.930385, -3.118425],
destination: [50.087692, 14.42115]
};
chai
.request(server)
.post("/order")
.send(payload)
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a("object");
res.body.should.have.property("status");
res.body.status.should.be.equal("UNASSIGN");
res.body.should.have.property("id");
done();
});
});
it("it should not be able to give distance when given invalid lat/long", done => {
let payload = {
origin: [75.930385, -3.118425],
destination: [50.087692, 14.42115]
};
chai
.request(server)
.post("/order")
.send(payload)
.end((err, res) => {
res.should.have.status(500);
res.body.should.be.a("object");
res.body.should.have.property("error");
res.body.error.should.be.equal("Not able to find the path");
done();
});
});
});
describe("/PUT Order", () => {
it("It should update order status to 'taken'", done => {
let payload = {
origin: [55.930385, -3.118425],
destination: [50.087692, 14.42115]
};
chai
.request(server)
.post("/order")
.send(payload)
.end((err, orderRes) => {
const orderId = orderRes.body.id;
let payload = {
status: "taken"
};
chai
.request(server)
.put("/order/" + orderId)
.send(payload)
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a("object");
res.body.should.have.property("status");
res.body.status.should.be.equal("SUCCESS");
done();
describe("Order PUT", () => {
it("If order is already taken is should give error", done => {
let payload = {
status: "taken"
};
console.log(orderId);
chai
.request(server)
.put("/order/" + orderId)
.send(payload)
.end((err, res) => {
res.should.have.status(409);
res.body.should.be.a("object");
res.body.should.have.property("error");
res.body.error.should.be.equal("ORDER_ALREADY_BEEN_TAKEN");
done();
});
});
});
});
});
});
});
});