-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDatasetClient.spec.ts
159 lines (132 loc) · 5.52 KB
/
DatasetClient.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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 DatasetClient from '../src/datasets/DatasetClient';
import { DataSet, Policy } from '../src/datasets/models';
describe('(Client): Dataset', () => {
let client;
beforeEach((done) => {
const transport = new Transport('test', 'test', [API_SCOPE.USER], 'api.domo.com');
client = new DatasetClient(transport);
done();
});
it('should instantiate', () => {
expect(DatasetClient).to.exist;
expect(client).to.be.an.instanceOf(DatasetClient);
});
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 dataset: DataSet = {
name: 'test',
description: 'created by test',
schema: { columns: [{ name: 'col1', type: 'STRING' }] },
};
const promise = client.create(dataset);
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);
expect(spy.firstCall.args[0]).to.have.property('body', dataset);
expect(spy.firstCall.args[1]).to.equal(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);
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`);
expect(spy.firstCall.args[1]).to.equal(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 limit = 1;
const offset = 0;
const sort = 'name';
const promise = client.list(limit, offset, sort);
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);
expect(spy.firstCall.args[0].params).to.have.property('limit', limit);
expect(spy.firstCall.args[0].params).to.have.property('offset', offset);
expect(spy.firstCall.args[0].params).to.have.property('sort', sort);
expect(spy.firstCall.args[1]).to.equal(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 dataset: DataSet = { name: 'test-update' };
const promise = client.update(1, dataset);
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`);
expect(spy.firstCall.args[0]).to.have.property('body', dataset);
expect(spy.firstCall.args[1]).to.equal(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);
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`);
expect(spy.firstCall.args[1]).to.equal(client.type);
done();
});
});
it('should import csv data', (done) => {
const spy = sinon.stub(client.transport, 'put').returns(Promise.resolve());
expect(client.importData).to.exist;
expect(client.importData).to.an.instanceOf(Function);
const csv = 'example,csv,here';
const promise = client.importData(1, csv);
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/data`);
expect(spy.firstCall.args[0]).to.have.property('body', csv);
expect(spy.firstCall.args[0].headers).to.have.property('Content-Type', 'text/csv');
expect(spy.firstCall.args[1]).to.equal(client.type);
done();
});
});
it('should export csv data', (done) => {
const spy = sinon.stub(client.transport, 'get').returns(Promise.resolve());
expect(client.exportData).to.exist;
expect(client.exportData).to.an.instanceOf(Function);
const promise = client.exportData(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/data`);
expect(spy.firstCall.args[0].params).to.have.property('includeHeader', false);
expect(spy.firstCall.args[0].params).to.have.property('fileName');
expect(spy.firstCall.args[0].headers).to.have.property('Accept', 'text/csv');
expect(spy.firstCall.args).to.include(client.type);
done();
});
});
});