-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbot-dpaste.spec.js
48 lines (39 loc) · 1.12 KB
/
dbot-dpaste.spec.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
var dpaste = require('./dbot-dpaste')
, http = require('follow-redirects').http;
// Mock regex matches
var testString = 'some dummy content'
, matches = ['', testString]
, pattern = /http:\/\/dpaste\.cc\/paste\/([a-z0-9]{24})/;
describe('dpaste', function () {
var asyncResult;
it('should return a correct url', function (done) {
dpaste.callback(matches).then(function (result) {
asyncResult = result;
expect(asyncResult).toMatch(pattern);
done();
});
});
it('should have pasted the right content', function (done) {
var params = {
host: 'dpaste.cc',
port: 80,
method: 'GET',
path: '/paste/' + asyncResult.split('/').pop(),
headers: {
'User-Agent': 'curl'
}
}
, req = http.request(params, function (res) {
res.setEncoding('utf8');
var buffer = '';
res.on('data', function (chunk) {
buffer += chunk;
});
res.on('end', function () {
expect(buffer).toEqual(testString);
});
});
req.end();
done();
});
});