-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpRequestHelper.js
86 lines (57 loc) · 1.94 KB
/
httpRequestHelper.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
/*
* httpRequestHelper.js: Helper for easier interaction with captured requests.
*
* (C) 2012 Crosstalk Systems Inc.
*/
var assert = require( 'assert' ),
httpBodyEquals = require( './httpBodyEquals' ),
httpHasHeader = require( './httpHasHeader' );
//
// ### function helper ( wrapper, requestObj )
// #### @wrapper {object} the wrapper for the worker that responded
// #### @requestObj {object} the http request object from the worker
// Creates a helper for simpler interaction with http request from the worker.
//
var helper = function helper ( wrapper, requestObj ) {
var _helper = {};
_helper.bodyEquals = httpBodyEquals( _helper, requestObj );
_helper.hasHeader = httpHasHeader( _helper, requestObj );
_helper.getCallback = function getCallback () {
return requestObj.callback;
}
_helper.request = function request () {
return requestObj.request;
};
_helper.requestObj = function requestObj () {
return requestObj;
};
_helper.hostEquals = function hostEquals ( host ) {
assert.equal( requestObj.host, host );
return _helper;
}; // hostEquals
_helper.hostnameEquals = function hostnameEquals ( hostname ) {
assert.equal( requestObj.hostname, hostname );
return _helper;
}; // hostnameEquals
_helper.methodEquals = function methodEquals ( method ) {
assert.equal( requestObj.method, method );
return _helper;
}; // methodEquals
_helper.pathEquals = function pathEquals ( path ) {
assert.equal( requestObj.url, path );
return _helper;
}; // pathEquals
_helper.protocolEquals = function protocolEquals ( protocol ) {
assert.equal( requestObj.protocol, protocol );
return _helper;
}; // protocolEquals
_helper.urlEquals = function urlEquals ( url ) {
assert.equal( requestObj.url, url );
return _helper;
}; // urlEquals
_helper.worker = function worker () {
return wrapper;
};
return _helper;
}; // helper
module.exports = helper;