-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathhelpers.js
97 lines (84 loc) · 2.51 KB
/
helpers.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
'use strict';
var http = require('http');
var request = require('../').defaults({ json: true });
var t = require('chai').assert;
describe('Helpers', function () {
var server;
var url;
before(function (done) {
server = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({ method: req.method }));
res.end();
});
server.listen(0, 'localhost', function () {
url = 'http://' + server.address().address + ':' + server.address().port;
done();
});
});
it('should provide .get()', function (done) {
request.get(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'GET');
t.strictEqual(body.method, 'GET');
done();
});
});
it('should provide .head()', function (done) {
request.head(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'HEAD');
t.strictEqual(body, undefined);
done();
});
});
it('should provide .post()', function (done) {
request.post(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'POST');
t.strictEqual(body.method, 'POST');
done();
});
});
it('should provide .put()', function (done) {
request.put(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'PUT');
t.strictEqual(body.method, 'PUT');
done();
});
});
it('should provide .patch()', function (done) {
request.patch(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'PATCH');
t.strictEqual(body.method, 'PATCH');
done();
});
});
it('should provide .delete()', function (done) {
request.delete(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'DELETE');
t.strictEqual(body.method, 'DELETE');
done();
});
});
it('should provide .del()', function (done) {
request.del(url, function (err, resp, body) {
t.strictEqual(resp.statusCode, 200);
t.strictEqual(resp.request.method, 'DELETE');
t.strictEqual(body.method, 'DELETE');
done();
});
});
after(function (done) {
if (server) {
server.close(function () {
done();
});
} else {
done();
}
});
});