UNPKG

5.49 kBPlain TextView Raw
1import { autoTransform } from '../src/autoTransform';
2
3test('autoTransform', () => {
4 expect(
5 autoTransform([
6 { gender: 'Male', height: 180 },
7 { gender: 'Female', height: 165 },
8 { gender: 'Male', height: 170 },
9 ]).schemas
10 ).toEqual([
11 {
12 groupBy: ['gender'],
13 actions: [
14 {
15 type: 'sum',
16 field: 'height',
17 as: 'SUM(height)',
18 },
19 ],
20 },
21 ]);
22});
23
24test('autoTransform', () => {
25 expect(
26 autoTransform([
27 { gender: 'Male', height: 180 },
28 { gender: 'Female', height: 165 },
29 { gender: 'Male', height: 170 },
30 ]).result
31 ).toEqual([
32 { gender: 'Male', 'SUM(height)': 350 },
33 { gender: 'Female', 'SUM(height)': 165 },
34 ]);
35});
36
37test('autoTransform', () => {
38 expect(
39 autoTransform(
40 [
41 { gender: 'Male', height: 180 },
42 { gender: 'Female', height: 165 },
43 { gender: 'Male', height: 170 },
44 ],
45 'underline'
46 ).schemas
47 ).toEqual([
48 {
49 groupBy: ['gender'],
50 actions: [
51 {
52 type: 'sum',
53 field: 'height',
54 as: 'SUM_height',
55 },
56 ],
57 },
58 ]);
59});
60
61test('autoTransform', () => {
62 expect(
63 autoTransform(
64 [
65 { gender: 'Male', height: 180 },
66 { gender: 'Female', height: 165 },
67 { gender: 'Male', height: 170 },
68 ],
69 'underline'
70 ).result
71 ).toEqual([
72 { gender: 'Male', SUM_height: 350 },
73 { gender: 'Female', SUM_height: 165 },
74 ]);
75});
76
77test('autoTransform', () => {
78 const data = [
79 { date1: '2019-12-01 08:00:00', count1: 379.44, type1: 'HOTEL1' },
80 { date1: '2019-12-01 08:00:00', count1: 140.24, type1: 'GAME1' },
81 { date1: '2019-12-01 08:00:00', count1: 407.84, type1: 'PLAIN1' },
82 { date1: '2019-12-01 08:00:00', count1: 624.99, type1: 'DIGITAL1' },
83 { date1: '2019-12-08 08:00:00', count1: 610.2, type1: 'HOTEL1' },
84 { date1: '2019-12-08 08:00:00', count1: 6.6, type1: 'GAME1' },
85 { date1: '2019-12-08 08:00:00', count1: 440.54, type1: 'PLAIN1' },
86 { date1: '2019-12-08 08:00:00', count1: 308.34, type1: 'DIGITAL1' },
87 { date1: '2019-12-15 08:00:00', count1: 647.41, type1: 'HOTEL1' },
88 { date1: '2019-12-15 08:00:00', count1: 21.58, type1: 'GAME1' },
89 { date1: '2019-12-15 08:00:00', count1: 904.91, type1: 'PLAIN1' },
90 { date1: '2019-12-15 08:00:00', count1: 851.28, type1: 'DIGITAL1' },
91 { date1: '2019-12-22 08:00:00', count1: 599.93, type1: 'HOTEL1' },
92 { date1: '2019-12-22 08:00:00', count1: 750.45, type1: 'GAME1' },
93 { date1: '2019-12-22 08:00:00', count1: 945.67, type1: 'PLAIN1' },
94 { date1: '2019-12-22 08:00:00', count1: 626.37, type1: 'DIGITAL1' },
95 { date1: '2019-12-29 08:00:00', count1: 83.11, type1: 'HOTEL1' },
96 { date1: '2019-12-29 08:00:00', count1: 403.6, type1: 'GAME1' },
97 { date1: '2019-12-29 08:00:00', count1: 789.67, type1: 'PLAIN1' },
98 { date1: '2019-12-29 08:00:00', count1: 850.6, type1: 'DIGITAL1' },
99 { date1: '2020-01-05 08:00:00', count1: 334.24, type1: 'HOTEL1' },
100 { date1: '2020-01-05 08:00:00', count1: 214.66, type1: 'GAME1' },
101 { date1: '2020-01-05 08:00:00', count1: 901.88, type1: 'PLAIN1' },
102 { date1: '2020-01-05 08:00:00', count1: 206.69, type1: 'DIGITAL1' },
103 { date1: '2020-01-12 08:00:00', count1: 368.82, type1: 'HOTEL1' },
104 { date1: '2020-01-12 08:00:00', count1: 719.22, type1: 'GAME1' },
105 { date1: '2020-01-12 08:00:00', count1: 900.63, type1: 'PLAIN1' },
106 { date1: '2020-01-12 08:00:00', count1: 649.94, type1: 'DIGITAL1' },
107 { date1: '2020-01-19 08:00:00', count1: 797.56, type1: 'HOTEL1' },
108 { date1: '2020-01-19 08:00:00', count1: 187.26, type1: 'GAME1' },
109 { date1: '2020-01-19 08:00:00', count1: 229.12, type1: 'PLAIN1' },
110 { date1: '2020-01-19 08:00:00', count1: 267.03, type1: 'DIGITAL1' },
111 { date1: '2020-01-26 08:00:00', count1: 683.9, type1: 'HOTEL1' },
112 { date1: '2020-01-26 08:00:00', count1: 549.96, type1: 'GAME1' },
113 { date1: '2020-01-26 08:00:00', count1: 262.16, type1: 'PLAIN1' },
114 { date1: '2020-01-26 08:00:00', count1: 265.62, type1: 'DIGITAL1' },
115 { date1: '2020-02-02 08:00:00', count1: 456.68, type1: 'HOTEL1' },
116 { date1: '2020-02-02 08:00:00', count1: 501.63, type1: 'GAME1' },
117 { date1: '2020-02-02 08:00:00', count1: 640.06, type1: 'PLAIN1' },
118 { date1: '2020-02-02 08:00:00', count1: 598.63, type1: 'DIGITAL1' },
119 { date1: '2020-02-09 08:00:00', count1: 654.61, type1: 'HOTEL1' },
120 { date1: '2020-02-09 08:00:00', count1: 924.48, type1: 'GAME1' },
121 { date1: '2020-02-09 08:00:00', count1: 875.01, type1: 'PLAIN1' },
122 { date1: '2020-02-09 08:00:00', count1: 57.06, type1: 'DIGITAL1' },
123 { date1: '2020-02-16 08:00:00', count1: 768.87, type1: 'HOTEL1' },
124 { date1: '2020-02-16 08:00:00', count1: 787.32, type1: 'GAME1' },
125 { date1: '2020-02-16 08:00:00', count1: 582.22, type1: 'PLAIN1' },
126 { date1: '2020-02-16 08:00:00', count1: 546.38, type1: 'DIGITAL1' },
127 { date1: '2020-02-23 08:00:00', count1: 20.74, type1: 'HOTEL1' },
128 { date1: '2020-02-23 08:00:00', count1: 100.86, type1: 'GAME1' },
129 { date1: '2020-02-23 08:00:00', count1: 997.45, type1: 'PLAIN1' },
130 { date1: '2020-02-23 08:00:00', count1: 916.24, type1: 'DIGITAL1' },
131 ];
132
133 expect(autoTransform(data, false).schemas).toEqual([
134 {
135 actions: [
136 {
137 type: 'sum',
138 field: 'count1',
139 as: 'count1',
140 },
141 ],
142 groupBy: ['date1', 'type1'],
143 },
144 ]);
145});