-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrequest-test.js
More file actions
70 lines (53 loc) · 1.66 KB
/
request-test.js
File metadata and controls
70 lines (53 loc) · 1.66 KB
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
'use strict';
var _ = require('lodash');
var assert = require('chai').assert;
var request = require('../lib/request');
var RequestError = require('../lib/errors').RequestError;
describe('request', function () {
describe('createHeaders', function () {
it('adds the user agent and host headers', function () {
var headers = request.createHeaders('api.7digital.com');
assert.equal(headers.Host, 'api.7digital.com');
assert.equal(headers['User-Agent'], 'Node.js HTTP Client');
});
});
describe('prepare', function () {
it('adds the consumer key to the params', function () {
var preparedData = request.prepare({}, 'YOUR_KEY_HERE');
assert.equal(preparedData.oauth_consumer_key, 'YOUR_KEY_HERE');
});
it('converts dates to the correct format', function () {
var preparedData = request.prepare({
someParam: new Date(2005, 5, 3)
});
assert.equal(preparedData.someParam, '20050603');
});
});
describe('dispatch', function () {
it('calls back with the error', function (done) {
var logger = { info: _.noop, error: _.noop };
var hostInfo = {
port: 443,
host: 'wibble'
};
request.dispatch('', 'GET', {}, {}, hostInfo, {}, logger,
function (err) {
assert(err);
assert.instanceOf(err, RequestError,
'expected instance of RequestError');
assert.instanceOf(err.cause(), Error);
done();
});
});
});
describe('dispatchSecure', function () {
it('calls back with an error for unknown verbs', function (done) {
var logger = { info: _.noop, error: _.noop };
request.dispatchSecure('', 'BLAH', {}, {}, null, {}, {}, logger,
function (err) {
assert(err);
done();
});
});
});
});