-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.test.js
91 lines (84 loc) · 2.62 KB
/
express.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
var superagent = require('superagent')
var expect = require('expect.js')
describe('manifesto server', function(){
var id
it('posts an object', function(done){
superagent.post('http://localhost:3000/collections/test')
.send({ name: 'John'
, email: '[email protected]'
})
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(res.body.length).to.eql(1)
//expect(res.body[0]._id.length).to.eql(24)
id = res.body[0]._id
done()
})
})
it('retrieves an object', function(done){
superagent.get('http://localhost:3000/collections/test/'+id)
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(typeof res.body).to.eql('object')
expect(res.body._id.length).to.eql(24)
expect(res.body._id).to.eql(id)
done()
})
})
it('retrieves a collection', function(done){
superagent.get('http://localhost:3000/collections/test')
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(res.body.length).to.be.above(0)
expect(res.body.map(function (item){return item._id})).to.contain(id)
done()
})
})
it('updates an object', function(done){
superagent.put('http://localhost:3000/collections/test/'+id)
.send({name: 'Peter'
, email: '[email protected]'})
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(typeof res.body).to.eql('object')
expect(res.body.msg).to.eql('success')
done()
})
})
it('checks an updated object', function(done){
superagent.get('http://localhost:3000/collections/test/'+id)
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(typeof res.body).to.eql('object')
expect(res.body._id.length).to.eql(24)
expect(res.body._id).to.eql(id)
expect(res.body.name).to.eql('Peter')
done()
})
})
it('removes an object', function(done){
superagent.del('http://localhost:3000/collections/test/'+id)
.end(function(e, res){
// console.log(res.body)
expect(e).to.eql(null)
expect(typeof res.body).to.eql('object')
expect(res.body.msg).to.eql('success')
done()
})
})
it('sets up a manifest collection', function(done){
superagent.post('http://localhost:3000/collections/manifests')
.send({ _id: 'foo:123'
, label: 'Thus Spoke Zarathustra'
})
.end(function(e, res){
// this is not a test
done()
})
})
})