Skip to content

Commit ebd4c6f

Browse files
committed
kick off response data test
1 parent b0f2ae5 commit ebd4c6f

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

lib/requestData.iced

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class ReqData
4545

4646
# -> mochiheaders() The incoming HTTP headers. Generally, getReqHeader is more useful.
4747
# TODO: downcase?
48-
reqHeaders: ()->
49-
# console.log @req.headers
50-
@req.headers
48+
reqHeaders: ()-> @req.headers
5149

5250
# TODO: it'd be nice to make this blocking. but, whatever
5351
# -> 'undefined', binary() The incoming request body, if any.

lib/responseData.iced

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ class ResData
66
@headers = {}
77
@body = null
88

9-
# isRedirect: ()->
10-
11-
appendToResponseBody: (body)->
12-
@body = "" if @body == null
13-
@body += body
14-
159
# -> string() Look up the current value of an outgoing request header.
1610
getRespHeader: (string)->
1711
# @res.getHeader(string)
@@ -43,27 +37,32 @@ class ResData
4337
@headers[string] = value
4438

4539
# rd() Append the given value to the body of the outgoing response.
46-
appendToResponseBody: (binary) ->
40+
appendToResponseBody: (body) ->
41+
@body = "" if @body == null
42+
@body += body
4743

4844
# rd() see respRedirect; this sets that value.
4945
doRedirect: (bool) -> @redirect = bool
5046

51-
# rd() The dispPath is the only path that can be changed during a request. This function will do so.
47+
# rd() The dispPath is the only path that can be changed during a request.
48+
# This function will do so.
5249
setDispPath: (string) ->
5350

5451
# rd() Replace the incoming request body with this for the rest of the processing.
5552
setReqBody: (binary) ->
5653

5754
# rd() Set the outgoing response body to this value.
58-
setRespBody: (binary) ->
55+
setRespBody: (body) -> @body = body
5956

60-
# rd() Use this streamed body to produce the outgoing response body on demand.
61-
setRespBody: (streambody) ->
57+
# # rd() Use this streamed body to produce the outgoing response body on demand.
58+
# setRespBody: (streambody) ->
6259

6360
# rd() Given a list of two-tuples of {headername,value}, set those outgoing response headers.
6461
setRespHeaders: (headername, value) ->
62+
@headers[headername] = value
6563

6664
# rd() Remove the named outgoing response header.
6765
removeRespHeader: (string) ->
66+
delete @headers[headername]
6867

6968
module.exports = ResData

test/fsm-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function buildTest(test) {
9090
assert.notEqual(req, undefined, 'req is required');
9191
// TODO: Use path
9292
// TODO: Check headers
93-
// assert.equal(res.statusCode(), test.checkStatus);
93+
assert.equal(res.statusCode(), test.checkStatus);
9494
assert.deepEqual(res.trace, test.checkStack);
9595
}
9696
};

test/responseData-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var vows = require('vows'),
2+
assert = require('assert'),
3+
net = require('net'),
4+
http = require('http'),
5+
iced = require('iced-coffee-script'),
6+
ResData = require('../lib/responseData');
7+
8+
vows.describe('Server').addBatch({
9+
'create a valid ResData': {
10+
topic: function () {
11+
nodeRes = {
12+
statusCode: 200,
13+
};
14+
resData = new ResData(nodeRes);
15+
resData.setRespHeader('Location', '/tmp');
16+
resData.setRespBody('data');
17+
resData.doRedirect(true);
18+
this.callback(undefined, resData);
19+
},
20+
'and fields exist': function (err, resData) {
21+
assert.equal(err, undefined);
22+
assert(resData.headers);
23+
assert(resData.res);
24+
},
25+
'and respHeaders': function (err, resData) {
26+
assert(resData.respHeaders());
27+
assert.equal(resData.respHeaders()['Location'], '/tmp');
28+
},
29+
'and getRespHeader': function (err, resData) {
30+
assert.equal(resData.getRespHeader('Location'), '/tmp');
31+
assert.equal(resData.getRespHeader('derp'), null);
32+
},
33+
'and respRedirect': function (err, resData) {
34+
assert.equal(resData.respRedirect(), true);
35+
},
36+
'and statusCode': function (err, resData) {
37+
assert.equal(resData.statusCode(), 200);
38+
}
39+
}
40+
}).export(module);

0 commit comments

Comments
 (0)