-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
executable file
·70 lines (59 loc) · 2.18 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
#!/usr/bin/env node
var assert = require('assert'),
nock = require('nock');
describe('promise-request', function() {
var promiseRequest = require('./promise-request');
describe('without body', function() {
it('should work without errors', function(done) {
var expectedResponse = {success: true};
nock('https://localhost')
.get('/get')
.reply(200, expectedResponse);
promiseRequest({
host: 'localhost',
path: '/get',
scheme: 'https'
}).then(function(response) {
assert.deepEqual(response.data, expectedResponse);
}, function(error) {
assert.fail(error, expectedResponse, 'unexpected call to error callback');
}).then(done);
});
});
describe('with body', function() {
it('should work without errors', function(done) {
var expectedResponse = {success: true};
var body = {foo: 'post'};
nock('https://localhost')
.post('/post', body)
.reply(200, expectedResponse);
promiseRequest({
method: 'POST',
host: 'localhost',
path: '/post',
scheme: 'https'
}, body).then(function(response) {
assert.deepEqual(response.data, expectedResponse);
}, function(error) {
assert.fail(error, expectedResponse, 'unexpected call to error callback');
}).then(done);
});
});
describe('errors', function() {
it('should be handled', function(done) {
var expectedResponse = {success: true};
nock('https://localhost')
.get('/get')
.reply(404);
promiseRequest({
host: 'localhost',
path: '/get',
scheme: 'https'
}).then(function(response) {
assert.fail(response, 404, 'unexpected call to sucess callback');
}, function(error) {
assert.equal(error.statusCode, 404);
}).then(done);
});
});
});