-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
79 lines (72 loc) · 1.61 KB
/
test.js
File metadata and controls
79 lines (72 loc) · 1.61 KB
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
const test = require("tape");
const supertest = require("supertest");
const router = require("./router");
test("Initialise", t => {
let num = 2;
t.equal(num, 2, "Should return 2");
t.end();
});
//Home Route
test("Home route returns a status code of 200", t => {
supertest(router)
.get("/")
.expect("Content-Type", /html/)
.end((err, res) => {
t.error(err);
t.equal(res.statusCode, 200, "Should return 200");
t.end();
});
});
test("Home route", t => {
supertest(router)
.get("/")
.expect(200)
.expect("Content-type", /html/)
.end((err, res) => {
t.error(err);
t.equal(res.text, "Hello", "response should contain 'Hello'");
t.end();
});
});
// Elephant test
test("Elephant route", t => {
supertest(router)
.get("/elephants")
.expect(404)
.end((err, res) => {
t.error(err);
t.equal(
res.text,
"unknown uri",
"elephants should return 404 with unknown uri"
);
t.end();
});
});
test("Blog route", t => {
supertest(router)
.get("/blog")
.expect(200)
.end((err, res) => {
let oneTwoThree = JSON.parse(res.text);
t.error(err);
t.deepEqual(
oneTwoThree,
["one", "two", "three"],
"blog should return 200 with [one, two, three]"
);
t.end();
});
});
test("Blog Post request", t => {
supertest(router)
.post("/blog")
.set({ password: "potato" })
.send(["a", "b"])
.expect(200)
.end((err, res) => {
t.error(err);
t.deepEqual(res.body, ["a", "b"], "body should be [a,b]");
t.end();
});
});