-
Notifications
You must be signed in to change notification settings - Fork 34
/
HttpClient.test.js
71 lines (56 loc) · 2.06 KB
/
HttpClient.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
'use strict';
// external files
var assert = require('chai').assert;
// local files
var clients = require('../lib');
describe('HttpClient', function () {
var CLIENT;
it('should throw on url without protocol', function () {
assert.throws(function () {
clients.createHttpClient({
url: 'localhost:3000'
});
}, 'must specify http/https protocol!');
});
it('should not throw on url with protocol', function () {
assert.doesNotThrow(function () {
CLIENT = clients.createHttpClient({
url: 'http://www.restify.com'
});
});
assert.strictEqual(CLIENT.url.protocol, 'http:');
assert.doesNotThrow(function () {
CLIENT = clients.createHttpClient({
url: 'https://www.restify.com'
});
});
assert.strictEqual(CLIENT.url.protocol, 'https:');
});
it('should trim whitespaces in url', function () {
CLIENT = clients.createHttpClient({
url: 'https://www. restify\t.com:3000'
});
assert.strictEqual(CLIENT.url.hostname, 'www.restify.com');
assert.strictEqual(CLIENT.url.port, '3000');
});
it('should fill default User Agent when none is given', function () {
CLIENT = clients.createHttpClient();
assert.strictEqual(CLIENT.headers['user-agent'].slice(0, 8),
'restify/');
});
it('should keep User Agent from headers if none is given', function () {
const userAgent = 'The Acme Browser 0.42';
CLIENT = clients.createHttpClient({
headers: {'user-agent': userAgent}
});
assert.strictEqual(CLIENT.headers['user-agent'], userAgent);
});
it('should use given User Agent', function () {
const userAgent = 'The Acme Browser 0.42';
CLIENT = clients.createHttpClient({
headers: {'user-agent': 'Not The Acme Browser 0.00'},
userAgent
});
assert.strictEqual(CLIENT.headers['user-agent'], userAgent);
});
});