@cubejs-client/core 0.29.8 → 0.29.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,454 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ * @copyright Cube Dev, Inc.
4
+ * @fileoverview CubejsApi class unit tests.
5
+ */
6
+
7
+ /* globals describe,test,expect,beforeEach,jest */
8
+
9
+ import ResultSet from './ResultSet';
10
+ import { CubejsApi } from './index';
11
+
12
+ jest.mock('./ResultSet');
13
+ beforeEach(() => {
14
+ ResultSet.mockClear();
15
+ });
16
+
17
+ const mockData = {
18
+ regular_1: {
19
+ result_default: [
20
+ {
21
+ 'ECommerceRecordsUs2021.city': 'Missouri City',
22
+ 'ECommerceRecordsUs2021.avg_discount': '0.80000000000000000000'
23
+ },
24
+ {
25
+ 'ECommerceRecordsUs2021.city': 'Abilene',
26
+ 'ECommerceRecordsUs2021.avg_discount': '0.80000000000000000000'
27
+ }
28
+ ],
29
+ result_compact: {
30
+ members: ['ECommerceRecordsUs2021.city', 'ECommerceRecordsUs2021.avg_discount'],
31
+ dataset: [['Missouri City', '0.80000000000000000000'], ['Abilene', '0.80000000000000000000']],
32
+ }
33
+ },
34
+ regular_2: {
35
+ result_default: [
36
+ {
37
+ 'ECommerceRecordsUs2021.postalCode': '95823',
38
+ 'ECommerceRecordsUs2021.avg_profit': '646.1258666666666667'
39
+ },
40
+ {
41
+ 'ECommerceRecordsUs2021.postalCode': '64055',
42
+ 'ECommerceRecordsUs2021.avg_profit': '487.8315000000000000'
43
+ }
44
+ ],
45
+ result_compact: {
46
+ members: [
47
+ 'ECommerceRecordsUs2021.postalCode',
48
+ 'ECommerceRecordsUs2021.avg_profit',
49
+ ],
50
+ dataset: [
51
+ ['95823', '646.1258666666666667'],
52
+ ['64055', '487.8315000000000000']
53
+ ],
54
+ }
55
+ },
56
+ compare: [{
57
+ result_default: [
58
+ {
59
+ 'ECommerceRecordsUs2021.orderDate.day': '2020-01-01T00:00:00.000',
60
+ 'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
61
+ 'ECommerceRecordsUs2021.count': '10',
62
+ compareDateRange: '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
63
+ },
64
+ {
65
+ 'ECommerceRecordsUs2021.orderDate.day': '2020-01-02T00:00:00.000',
66
+ 'ECommerceRecordsUs2021.orderDate': '2020-01-02T00:00:00.000',
67
+ 'ECommerceRecordsUs2021.count': '8',
68
+ compareDateRange: '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
69
+ }
70
+ ],
71
+ result_compact: {
72
+ members: [
73
+ 'ECommerceRecordsUs2021.orderDate.day',
74
+ 'ECommerceRecordsUs2021.orderDate',
75
+ 'ECommerceRecordsUs2021.count',
76
+ 'compareDateRange',
77
+ ],
78
+ dataset: [
79
+ [
80
+ '2020-01-01T00:00:00.000',
81
+ '2020-01-01T00:00:00.000',
82
+ '10',
83
+ '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999',
84
+ ],
85
+ [
86
+ '2020-01-02T00:00:00.000',
87
+ '2020-01-02T00:00:00.000',
88
+ '8',
89
+ '2020-01-01T00:00:00.000 - 2020-01-31T23:59:59.999'
90
+ ],
91
+ ],
92
+ },
93
+ }, {
94
+ result_default: [
95
+ {
96
+ 'ECommerceRecordsUs2021.orderDate.day': '2020-03-02T00:00:00.000',
97
+ 'ECommerceRecordsUs2021.orderDate': '2020-03-02T00:00:00.000',
98
+ 'ECommerceRecordsUs2021.count': '11',
99
+ compareDateRange: '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
100
+ },
101
+ {
102
+ 'ECommerceRecordsUs2021.orderDate.day': '2020-03-03T00:00:00.000',
103
+ 'ECommerceRecordsUs2021.orderDate': '2020-03-03T00:00:00.000',
104
+ 'ECommerceRecordsUs2021.count': '7',
105
+ compareDateRange: '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
106
+ }
107
+ ],
108
+ result_compact: {
109
+ members: [
110
+ 'ECommerceRecordsUs2021.orderDate.day',
111
+ 'ECommerceRecordsUs2021.orderDate',
112
+ 'ECommerceRecordsUs2021.count',
113
+ 'compareDateRange',
114
+ ],
115
+ dataset: [
116
+ [
117
+ '2020-03-02T00:00:00.000',
118
+ '2020-03-02T00:00:00.000',
119
+ '11',
120
+ '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999',
121
+ ],
122
+ [
123
+ '2020-03-03T00:00:00.000',
124
+ '2020-03-03T00:00:00.000',
125
+ '7',
126
+ '2020-03-01T00:00:00.000 - 2020-03-31T23:59:59.999'
127
+ ],
128
+ ],
129
+ },
130
+ }],
131
+ blending: [{
132
+ result_default: [
133
+ {
134
+ 'ECommerceRecordsUs2021.orderDate.month': '2020-01-01T00:00:00.000',
135
+ 'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
136
+ 'ECommerceRecordsUs2021.avg_discount': '0.15638297872340425532',
137
+ 'time.month': '2020-01-01T00:00:00.000'
138
+ },
139
+ {
140
+ 'ECommerceRecordsUs2021.orderDate.month': '2020-02-01T00:00:00.000',
141
+ 'ECommerceRecordsUs2021.orderDate': '2020-02-01T00:00:00.000',
142
+ 'ECommerceRecordsUs2021.avg_discount': '0.17573529411764705882',
143
+ 'time.month': '2020-02-01T00:00:00.000'
144
+ }
145
+ ],
146
+ result_compact: {
147
+ members: [
148
+ 'ECommerceRecordsUs2021.orderDate.month',
149
+ 'ECommerceRecordsUs2021.orderDate',
150
+ 'ECommerceRecordsUs2021.avg_discount',
151
+ 'time.month',
152
+ ],
153
+ dataset: [
154
+ [
155
+ '2020-01-01T00:00:00.000',
156
+ '2020-01-01T00:00:00.000',
157
+ '0.15638297872340425532',
158
+ '2020-01-01T00:00:00.000',
159
+ ],
160
+ [
161
+ '2020-02-01T00:00:00.000',
162
+ '2020-02-01T00:00:00.000',
163
+ '0.17573529411764705882',
164
+ '2020-02-01T00:00:00.000',
165
+ ],
166
+ ],
167
+ },
168
+ }, {
169
+ result_default: [{
170
+ 'ECommerceRecordsUs2021.orderDate.month': '2020-01-01T00:00:00.000',
171
+ 'ECommerceRecordsUs2021.orderDate': '2020-01-01T00:00:00.000',
172
+ 'ECommerceRecordsUs2021.avg_discount': '0.28571428571428571429',
173
+ 'time.month': '2020-01-01T00:00:00.000'
174
+ },
175
+ {
176
+ 'ECommerceRecordsUs2021.orderDate.month': '2020-02-01T00:00:00.000',
177
+ 'ECommerceRecordsUs2021.orderDate': '2020-02-01T00:00:00.000',
178
+ 'ECommerceRecordsUs2021.avg_discount': '0.21777777777777777778',
179
+ 'time.month': '2020-02-01T00:00:00.000'
180
+ }],
181
+ result_compact: {
182
+ members: [
183
+ 'ECommerceRecordsUs2021.orderDate.month',
184
+ 'ECommerceRecordsUs2021.orderDate',
185
+ 'ECommerceRecordsUs2021.avg_discount',
186
+ 'time.month',
187
+ ],
188
+ dataset: [
189
+ [
190
+ '2020-01-01T00:00:00.000',
191
+ '2020-01-01T00:00:00.000',
192
+ '0.28571428571428571429',
193
+ '2020-01-01T00:00:00.000',
194
+ ],
195
+ [
196
+ '2020-02-01T00:00:00.000',
197
+ '2020-02-01T00:00:00.000',
198
+ '0.21777777777777777778',
199
+ '2020-02-01T00:00:00.000',
200
+ ],
201
+ ],
202
+ },
203
+ }],
204
+ };
205
+
206
+ describe('CubejsApi', () => {
207
+ test('CubejsApi#loadResponseInternal should work with the "default" resType for regular query', () => {
208
+ const api = new CubejsApi(undefined, {
209
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
210
+ });
211
+ const income = {
212
+ results: [{
213
+ query: {},
214
+ data: JSON.parse(
215
+ JSON.stringify(
216
+ mockData.regular_1.result_default
217
+ )
218
+ )
219
+ }],
220
+ };
221
+ const outcome = {
222
+ results: [{
223
+ query: {},
224
+ data: JSON.parse(
225
+ JSON.stringify(
226
+ mockData.regular_1.result_default
227
+ )
228
+ )
229
+ }],
230
+ };
231
+ api.loadResponseInternal(income);
232
+ expect(ResultSet).toHaveBeenCalled();
233
+ expect(ResultSet).toHaveBeenCalledTimes(1);
234
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
235
+ parseDateMeasures: undefined
236
+ });
237
+ });
238
+
239
+ test('CubejsApi#loadResponseInternal should work with the "default" resType for compare date range query', () => {
240
+ const api = new CubejsApi(undefined, {
241
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
242
+ });
243
+ const income = {
244
+ results: [{
245
+ query: {},
246
+ data: JSON.parse(
247
+ JSON.stringify(
248
+ mockData.compare[0].result_default
249
+ )
250
+ )
251
+ }, {
252
+ query: {},
253
+ data: JSON.parse(
254
+ JSON.stringify(
255
+ mockData.compare[1].result_default
256
+ )
257
+ )
258
+ }],
259
+ };
260
+ const outcome = {
261
+ results: [{
262
+ query: {},
263
+ data: JSON.parse(
264
+ JSON.stringify(
265
+ mockData.compare[0].result_default
266
+ )
267
+ )
268
+ }, {
269
+ query: {},
270
+ data: JSON.parse(
271
+ JSON.stringify(
272
+ mockData.compare[1].result_default
273
+ )
274
+ )
275
+ }],
276
+ };
277
+ api.loadResponseInternal(income);
278
+ expect(ResultSet).toHaveBeenCalled();
279
+ expect(ResultSet).toHaveBeenCalledTimes(1);
280
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
281
+ parseDateMeasures: undefined
282
+ });
283
+ });
284
+
285
+ test('CubejsApi#loadResponseInternal should work with the "default" resType for blending query', () => {
286
+ const api = new CubejsApi(undefined, {
287
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
288
+ });
289
+ const income = {
290
+ results: [{
291
+ query: {},
292
+ data: JSON.parse(
293
+ JSON.stringify(
294
+ mockData.blending[0].result_default
295
+ )
296
+ )
297
+ }, {
298
+ query: {},
299
+ data: JSON.parse(
300
+ JSON.stringify(
301
+ mockData.blending[1].result_default
302
+ )
303
+ )
304
+ }],
305
+ };
306
+ const outcome = {
307
+ results: [{
308
+ query: {},
309
+ data: JSON.parse(
310
+ JSON.stringify(
311
+ mockData.blending[0].result_default
312
+ )
313
+ )
314
+ }, {
315
+ query: {},
316
+ data: JSON.parse(
317
+ JSON.stringify(
318
+ mockData.blending[1].result_default
319
+ )
320
+ )
321
+ }],
322
+ };
323
+ api.loadResponseInternal(income);
324
+ expect(ResultSet).toHaveBeenCalled();
325
+ expect(ResultSet).toHaveBeenCalledTimes(1);
326
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
327
+ parseDateMeasures: undefined
328
+ });
329
+ });
330
+
331
+ test('CubejsApi#loadResponseInternal should work with the "compact" resType for regular query', () => {
332
+ const api = new CubejsApi(undefined, {
333
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
334
+ });
335
+ const income = {
336
+ results: [{
337
+ query: { responseFormat: 'compact' },
338
+ data: JSON.parse(
339
+ JSON.stringify(
340
+ mockData.regular_1.result_compact
341
+ )
342
+ )
343
+ }],
344
+ };
345
+ const outcome = {
346
+ results: [{
347
+ query: { responseFormat: 'compact' },
348
+ data: JSON.parse(
349
+ JSON.stringify(
350
+ mockData.regular_1.result_default
351
+ )
352
+ )
353
+ }],
354
+ };
355
+ api.loadResponseInternal(income);
356
+ expect(ResultSet).toHaveBeenCalled();
357
+ expect(ResultSet).toHaveBeenCalledTimes(1);
358
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
359
+ parseDateMeasures: undefined
360
+ });
361
+ });
362
+
363
+ test('CubejsApi#loadResponseInternal should work with the "compact" resType for compare date range query', () => {
364
+ const api = new CubejsApi(undefined, {
365
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
366
+ });
367
+ const income = {
368
+ results: [{
369
+ query: { responseFormat: 'compact' },
370
+ data: JSON.parse(
371
+ JSON.stringify(
372
+ mockData.compare[0].result_compact
373
+ )
374
+ )
375
+ }, {
376
+ query: { responseFormat: 'compact' },
377
+ data: JSON.parse(
378
+ JSON.stringify(
379
+ mockData.compare[1].result_compact
380
+ )
381
+ )
382
+ }],
383
+ };
384
+ const outcome = {
385
+ results: [{
386
+ query: { responseFormat: 'compact' },
387
+ data: JSON.parse(
388
+ JSON.stringify(
389
+ mockData.compare[0].result_default
390
+ )
391
+ )
392
+ }, {
393
+ query: { responseFormat: 'compact' },
394
+ data: JSON.parse(
395
+ JSON.stringify(
396
+ mockData.compare[1].result_default
397
+ )
398
+ )
399
+ }],
400
+ };
401
+ api.loadResponseInternal(income);
402
+ expect(ResultSet).toHaveBeenCalled();
403
+ expect(ResultSet).toHaveBeenCalledTimes(1);
404
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
405
+ parseDateMeasures: undefined
406
+ });
407
+ });
408
+
409
+ test('CubejsApi#loadResponseInternal should work with the "compact" resType for blending query', () => {
410
+ const api = new CubejsApi(undefined, {
411
+ apiUrl: 'http://localhost:4000/cubejs-api/v1',
412
+ });
413
+ const income = {
414
+ results: [{
415
+ query: { responseFormat: 'compact' },
416
+ data: JSON.parse(
417
+ JSON.stringify(
418
+ mockData.blending[0].result_compact
419
+ )
420
+ )
421
+ }, {
422
+ query: { responseFormat: 'compact' },
423
+ data: JSON.parse(
424
+ JSON.stringify(
425
+ mockData.blending[1].result_compact
426
+ )
427
+ )
428
+ }],
429
+ };
430
+ const outcome = {
431
+ results: [{
432
+ query: { responseFormat: 'compact' },
433
+ data: JSON.parse(
434
+ JSON.stringify(
435
+ mockData.blending[0].result_default
436
+ )
437
+ )
438
+ }, {
439
+ query: { responseFormat: 'compact' },
440
+ data: JSON.parse(
441
+ JSON.stringify(
442
+ mockData.blending[1].result_default
443
+ )
444
+ )
445
+ }],
446
+ };
447
+ api.loadResponseInternal(income);
448
+ expect(ResultSet).toHaveBeenCalled();
449
+ expect(ResultSet).toHaveBeenCalledTimes(1);
450
+ expect(ResultSet).toHaveBeenCalledWith(outcome, {
451
+ parseDateMeasures: undefined
452
+ });
453
+ });
454
+ });
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ * @copyright Cube Dev, Inc.
4
+ * @fileoverview ResultSet class unit tests.
5
+ */
6
+
7
+ /* globals describe,test,expect */
8
+
1
9
  import 'jest';
2
10
  import ResultSet from '../ResultSet';
3
11