-
Notifications
You must be signed in to change notification settings - Fork 11
/
PDPClient.spec.ts
121 lines (100 loc) · 3.82 KB
/
PDPClient.spec.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import * as sinon from 'sinon';
import { expect } from 'chai';
import Transport from '../src/common/Transport';
import { HTTP_METHODS, API_SCOPE, FILTER_OPERATORS } from '../src/common/Constants';
import PDPClient from '../src/datasets/PDPClient';
import { Policy } from '../src/datasets/models';
describe('(Client): PDP', () => {
let client;
beforeEach(() => {
const transport = new Transport('test', 'test', [API_SCOPE.USER], 'api.domo.com');
client = new PDPClient(transport);
});
it('should instantiate', () => {
expect(PDPClient).to.exist;
expect(client).to.be.an.instanceOf(PDPClient);
});
it('should have correct URL base', () => {
expect(client.urlBase).to.equal('/v1/datasets');
});
it('should create', (done) => {
const spy = sinon.stub(client.transport, 'post').returns(Promise.resolve());
expect(client.create).to.exist;
expect(client.create).to.an.instanceOf(Function);
const pdp: Policy = {
name: 'test-policy',
type: 'user',
users: [1],
groups: [],
filters: [{
column: 'col1',
values: ['hello'],
not: true,
operator: FILTER_OPERATORS[FILTER_OPERATORS.EQUALS],
}],
};
const promise = client.create('1', pdp);
expect(promise).to.be.an.instanceOf(Promise);
promise.then(() => {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args[0]).to.have.property('url', `${client.urlBase}/1/policies`);
expect(spy.firstCall.args[0]).to.have.property('body', pdp);
expect(spy.firstCall.args).to.include(client.type);
done();
});
});
it('should get', (done) => {
const spy = sinon.stub(client.transport, 'get').returns(Promise.resolve());
expect(client.get).to.exist;
expect(client.get).to.an.instanceOf(Function);
const promise = client.get('1', 2);
expect(promise).to.be.an.instanceOf(Promise);
promise.then(() => {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args[0]).to.have.property('url', `${client.urlBase}/1/policies/2`);
expect(spy.firstCall.args).to.include(client.type);
done();
});
});
it('should list', (done) => {
const spy = sinon.stub(client.transport, 'get').returns(Promise.resolve());
expect(client.list).to.exist;
expect(client.list).to.an.instanceOf(Function);
const promise = client.list('1');
expect(promise).to.be.an.instanceOf(Promise);
promise.then(() => {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args[0]).to.have.property('url', `${client.urlBase}/1/policies`);
expect(spy.firstCall.args).to.include(client.type);
done();
});
});
it('should update', (done) => {
const spy = sinon.stub(client.transport, 'put').returns(Promise.resolve());
expect(client.update).to.exist;
expect(client.update).to.an.instanceOf(Function);
const pdp: Policy = { name: 'test' };
const promise = client.update('1', 2, pdp);
expect(promise).to.be.an.instanceOf(Promise);
promise.then(() => {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args[0]).to.have.property('url', `${client.urlBase}/1/policies/2`);
expect(spy.firstCall.args[0]).to.have.property('body', pdp);
expect(spy.firstCall.args).to.include(client.type);
done();
});
});
it('should delete', (done) => {
const spy = sinon.stub(client.transport, 'delete').returns(Promise.resolve());
expect(client.delete).to.exist;
expect(client.delete).to.an.instanceOf(Function);
const promise = client.delete('1', 2);
expect(promise).to.be.an.instanceOf(Promise);
promise.then(() => {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args[0]).to.have.property('url', `${client.urlBase}/1/policies/2`);
expect(spy.firstCall.args[1]).to.equal(client.type);
done();
});
});
});