-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
78 lines (72 loc) · 1.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
const test=require('tape');
const supertest=require('supertest');
const router = require('./router');
test('Initialise',(t)=>{
let num = 2;
t.equal(2,2,'Should return 2');
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','Should contain "Hello"');
t.end();
})
});
test('Elephant route', (t) => {
supertest(router)
.get('/elephants')
.expect(404)
.end((err, res) => {
t.error(err);
t.equal(res.text, 'unknown uri');
t.end();
});
});
test('GET /blog',(t)=>{
supertest(router)
.get('/blog')
.expect(200)
.end( (err,res)=>{
t.error(err);
t.deepEqual(JSON.parse(res.text),["one","two","three"]);
t.end();
})
})
test('POST /blog', (t) => {
supertest(router)
.post('/blog')
.set({password:'potato'})
.send(['a', 'b'])
.expect(200)
.end( (err, res) => {
t.error(err);
t.deepEqual(JSON.parse(res.text),['a', 'b']);
t.end();
})
})
test('POST /blog', (t) => {
supertest(router)
.post('/blog')
.expect(403)
.end((err, res)=>{
t.error(err);
t.equal(res.text, 'Forbidden')
t.end();
})
})
test('POST /blog without body',(t)=>{
supertest(router)
.post('/blog')
.set({password:'potato'})
.expect(302)
.end( (err,res)=>{
t.error(err);
t.deepEqual(JSON.parse(res.text),{Location:'/blog'});
t.end();
} )
})