This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-public-api.js
92 lines (72 loc) · 1.9 KB
/
test-public-api.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
'use strict';
/* global suite: false, setup: false, test: false,
teardown: false, suiteSetup: false, suiteTeardown: false */
var assert = require('assert');
var common = require('./common');
var http = require('http');
var rail = require('../');
suite('public-api', function() {
test('constructor', function() {
rail();
rail({});
rail({
proto: 'https',
request: {
cert: 'cert',
headers: {
'Content-Type': 'application/json'
}
},
buffer: {
defaults: true
}
});
});
test('rail.use', function() {
var client = rail();
var buffer = client.use('buffer', rail.plugins.buffer);
var validate = client.use('validate');
assert(buffer);
assert.strictEqual(typeof buffer._setup, 'function');
assert(validate);
assert.strictEqual(typeof validate._setup, 'function');
});
test('rail.call', function() {
var client = rail();
client.call();
client.call({});
client.call(null);
client.call(null, function() {});
client.call(function() {});
client.call({
headers: {
Test: 'X1'
}
}, function() {});
});
test('call.abort() -> __request()', function() {
var client = rail();
var call = client.call();
call.abort();
var ret = call.__request();
assert(ret === false);
});
test('call.__intercept "interceptor should be a function"', function() {
var client = rail();
var call = client.call();
assert.throws(function() {
call.__intercept('response');
}, TypeError, 'interceptor should be a function');
});
test('call.__request "No configuration available"', function(done) {
var client = rail();
var call = client.call();
call.on('error', function(err) {
assert(err);
assert(err.message, 'No configuration available');
done();
});
++call._pointer;
call.__request();
});
});