This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
/
conmock-test.js
104 lines (100 loc) · 3.36 KB
/
conmock-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
92
93
94
95
96
97
98
99
100
101
102
103
104
var vows = require('vows')
var assert = require('assert')
var should = require('should')
var conmock = require('./conmock.js')
vows.describe('Connection mocking').addBatch({
'Mocker': {
'#send' : {
topic: function () {
function wut (request, response, next) { response.send('okay', 200) };
conmock(wut, {}, this.callback);
},
'and knows what was sent' : function (err, mock) {
mock.fntype.should.equal('send');
mock.status.should.equal(200);
mock.body.should.equal('okay');
},
},
'#json' : {
topic: function () {
function wut (request, response, next) { response.json({message: 'yup'}, 200) };
conmock(wut, {}, this.callback);
},
'and knows what was sent' : function (err, mock) {
mock.fntype.should.equal('json');
mock.status.should.equal(200);
mock.body.message.should.equal('yup');
},
},
'#render' : {
topic: function () {
function wut (request, response, next) {
response.statusCode = 'fffffffuuuuuuuuuuuu';
response.render('ohai', {some: "thing", status: 404})
};
conmock(wut, {}, this.callback);
},
'and knows the options and the render path' : function (err, mock) {
mock.fntype.should.equal('render');
mock.path.should.equal('ohai');
mock.status.should.equal(404);
mock.options.some.should.equal('thing');
},
},
'#header' : {
topic: function () {
function wut (request, response, next) {
response.header('oh', 'hai');
response.send('okay')
};
conmock(wut, {}, this.callback);
},
'and knows the options and the render path' : function (err, mock) {
mock.fntype.should.equal('send');
mock.status.should.equal(200);
mock.headers['oh'].should.equal('hai');
},
},
'#next': {
topic: function () {
function mware (request, response, next) {
response.header('oh', 'hai');
next();
};
conmock(mware, {}, this.callback);
},
'callback gets called, knows headers': function (err, mock) {
mock.headers['oh'].should.equal('hai');
}
},
'#contentType' : {
'given "json"': {
topic: function () {
function wut (request, response, next) { response.contentType('json'); response.send('okay') };
conmock(wut, {}, this.callback);
},
'content-type should be "application/json"' : function (err, mock) {
mock.headers['Content-Type'].should.equal('application/json');
},
},
'given "txt"': {
topic: function () {
function wut (request, response, next) { response.contentType('txt'); response.send('okay') };
conmock(wut, {}, this.callback);
},
'content-type should be "text/plain"' : function (err, mock) {
mock.headers['Content-Type'].should.equal('text/plain');
},
},
'given "html"': {
topic: function () {
function wut (request, response, next) { response.contentType('html'); response.send('okay') };
conmock(wut, {}, this.callback);
},
'content-type should be "text/plain"' : function (err, mock) {
mock.headers['Content-Type'].should.equal('text/html');
},
}
},
}
}).export(module);