-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_test.js
63 lines (59 loc) · 1.53 KB
/
app_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
const request = require("supertest");
const app = require("../app");
const fs = require("fs");
const data = JSON.parse(fs.readFileSync("events.json"));
describe("GET /events", () => {
it("responds with json", done => {
request(app)
.get("/events")
.expect("Content-Type", /json/)
.expect(200, done);
});
it("responds with list of events", done => {
request(app)
.get("/events")
.expect(200, data, done);
});
});
describe("POST /events", () => {
it("adds new event on available date", done => {
const newEvent = {
name: "New meetup",
date: "2012-06-16"
};
request(app)
.post("/events")
.set("Accept", "application/json")
.send({ event: newEvent })
.expect(201)
.then(() => {
request(app)
.get("/events")
.expect(200, { events: data.events.concat(newEvent) }, done);
});
});
it("does not add on date already taken", done => {
request(app)
.post("/events")
.set("Accept", "application/json")
.send({
event: {
name: "New meetup",
date: data.events[0].date
}
})
.expect(400, done);
});
});
describe("DELETE /event/:date", () => {
it("deletes event from given date", done => {
request(app)
.get("/events")
.then(response => {
const events = response.body.events;
request(app)
.delete("/event/" + events[0].date)
.expect(200, { events: events.slice(1, events.length) }, done);
}, done);
});
});