Repository navigation
Expand file tree
/
Copy pathindex.specs.js
More file actions
99 lines (92 loc) · 4.71 KB
/
Copy pathindex.specs.js
File metadata and controls
99 lines (92 loc) · 4.71 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sdk, {Oid, __RewireAPI__ as RewireApi} from './index';
import oid from './Oid';
import sinon from 'sinon';
describe('when loading the module', function() {
it('it should export the sdk as the default', () => {
sdk.should.be.a('function');
});
it('it should export Oid', () => {
Oid.should.equal(oid);
});
beforeEach(() => {
this.actual = undefined;
});
describe('given a post and get AJAX function', () => {
beforeEach(() => {
this.postFn = sinon.stub();
this.getFn = sinon.stub();
this.sdk = sdk(this.postFn, this.getFn);
});
it('it should return a function to set V1 host information', () => {
this.sdk.should.be.a('function');
});
describe('given a hostname, instance name, port, and https protocol', () => {
beforeEach(() => {
this.setSecurity = this.sdk('hostname', 'instance', 80, true);
});
it('it should return a meta object with function to authenticate via username and password', () => {
this.setSecurity.withCreds.should.be.a('function');
});
it('it should return a meta object with function to authenticate via an access token', () => {
this.setSecurity.withAccessToken.should.be.a('function');
});
it('it should return a meta object with function to authenticate implicitly', () => {
this.setSecurity.withImplicitAuth.should.be.a('function');
});
describe('given an access token', () => {
beforeEach(() => {
this.accessToken = 'access token';
});
describe('when creating the SDK', () => {
beforeEach(() => {
this.metaStub = sinon.mock()
.withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, token: this.accessToken, postFn: this.postFn, getFn: this.getFn, isBasic: false })
.returns('meta');
RewireApi.__Rewire__('createMeta', this.metaStub);
this.meta = this.setSecurity.withAccessToken(this.accessToken);
});
it('it should return a Meta object with the access token, hostname, instance, port, protocol, post and get functions', () => {
this.meta.should.equal('meta');
});
});
});
describe('given a username and password', () => {
beforeEach(() => {
this.username = 'username';
this.password = 'password';
});
describe('when creating the SDK', () => {
beforeEach(() => {
this.token = 'username token';
this.metaStub = sinon.mock()
.withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, token: this.token, postFn: this.postFn, getFn: this.getFn, isBasic: true })
.returns('meta1');
this.btoa = sinon.mock()
.withArgs(`${this.username}:${this.password}`)
.returns(this.token);
RewireApi.__Rewire__('createMeta', this.metaStub);
RewireApi.__Rewire__('btoa', this.btoa);
this.meta = this.setSecurity.withCreds(this.username, this.password);
});
it('it should return a Meta object with the username/password encoded token, hostname, instance, port, protocol, post and get functions', () => {
this.meta.should.equal('meta1');
});
});
});
describe('given no explicit credentials', () => {
describe('when creating the SDK', () => {
beforeEach(() => {
this.metaStub = sinon.mock()
.withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, postFn: this.postFn, getFn: this.getFn })
.returns('meta1');
RewireApi.__Rewire__('createMeta', this.metaStub);
this.meta = this.setSecurity.withImplicitAuth();
});
it('it should return a Meta object with hostname, instance, port, protocol, post and get functions', () => {
this.meta.should.equal('meta1');
});
});
});
});
});
});