-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
99 lines (80 loc) · 2.51 KB
/
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
/*
Name: requestbin - test.js
Author: Franklin van de Meent (https://frankl.in)
Source & docs: https://github.com/fvdm/nodejs-requestbin
Feedback: https://github.com/fvdm/nodejs-requestbin/issues
License: Unlicense / Public Domain (see UNLICENSE file)
(https://github.com/fvdm/nodejs-requestbin/raw/develop/UNLICENSE)
*/
var http = require ('httpreq');
var dotest = require ('dotest');
var app = require ('./');
// Setup
var timeout = process.env.REQUESTBIN_TIMEOUT || 5000;
var iface = process.env.REQUESTBIN_INTERFACE || null;
var baseURL = process.env.REQUESTBIN_BASE_URL || null;
var userAgent = process.env.REQUESTBIN_USER_AGENT || null;
var cache = {
bin: null,
request: null,
post: {
nodejs: process.versions.node
}
};
app.config ({
timeout: timeout,
iface: iface,
baseURL: baseURL,
userAgent: userAgent
});
dotest.add ('Error: request failed', function (test) {
app.config ({ timeout: 1 });
app.create ('invalid', function (err) {
test ()
.isError ('fail', 'err', err)
.isExactly ('fail', 'err.message', err && err.message, 'request failed')
.isError ('fail', 'err.error', err && err.error)
.done ();
});
});
dotest.add ('.create', function (test) {
app.config ({ timeout: timeout });
app.create (false, function (err, data) {
cache.bin = data || null;
if (data) {
http.post ('https://requestb.in/' + data.name, { parameters: cache.post }, function () {});
dotest.log ('info', 'https://requestb.in/' + data.name + '?inspect');
}
test (err)
.isObject ('fail', 'data', data)
.isString ('warn', 'data.name', data && data.name)
.done ();
});
});
dotest.add ('.get', function (test) {
app.get (cache.bin.name, function (err, data) {
test (err)
.isObject ('fail', 'data', data)
.isExactly ('warn', 'data.name', data && data.name, cache.bin.name)
.done ();
});
});
dotest.add ('.requests', function (test) {
app.requests (cache.bin.name, function (err, data) {
cache.request = data && data [0] || null;
test (err)
.isArray ('fail', 'data', data)
.isNotEmpty ('warn', 'data', data)
.isObject ('warn', 'data[0]', data && data [0])
.done ();
});
});
dotest.add ('.request', function (test) {
app.request (cache.bin.name, cache.request.id, function (err, data) {
test (err)
.isObject ('fail', 'data', data)
.isExactly ('warn', 'data.id', data && data.id, cache.request.id)
.done ();
});
});
dotest.run (1000);