-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
70 lines (64 loc) · 1.68 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
const test = require("tape");
const router = require("./router");
const supertest = require("supertest");
test("initialise", t => {
let num = 2;
t.equal(num, 2, "Should return 2");
t.end();
});
test("Check status code is 200 on homepage", t => {
supertest(router)
.get("/")
.expect(200)
.expect("content-type", /html/)
.end((error, response) => {
t.error(error);
t.equal(response.text.includes('<title>Blog Home</title>'), true);
t.end();
});
});
test("Check status code is 200 on form page", t => {
supertest(router)
.get("/displayForm")
.expect(200)
.expect("content-type", /html/)
.end((error, response) => {
t.error(error);
t.equal(response.text.includes('<title>Blog Post</title>'), true);
t.end();
});
});
test("Check status code is 404 on incorrect url", t => {
supertest(router)
.get("/random")
.expect(404)
.expect("Content-type", /html/)
.end((error, response) => {
t.error(error);
t.equal(response.text, "<h1>Not found</h1>")
t.end()
});
});
test("Check status code is 302 on post creation", t => {
supertest(router)
.post("/create-post")
.expect(302)
.expect("location", "/")
.end((error, response) => {
t.error(error);
t.end();
})
})
test("Does blog post send correct data", t => {
supertest(router)
.post("/create-post")
.send('blogpost=hello')
.redirects()
.expect(200)
.expect("Content-Type", /html/)
.end((err, res) => {
t.error(err);
t.equal(res.text.includes('hello'), true);
t.end();
});
});