This repository was archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtransformer.test.js
More file actions
98 lines (89 loc) · 4.01 KB
/
transformer.test.js
File metadata and controls
98 lines (89 loc) · 4.01 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
const Transformer = require('./transformer')
test('Transformer exists', () => {
new Transformer()
});
test('countMembershipsByYearAndWeek', () => {
const rows =
[{'year':2001,'week':1,'membership':'Annual','count':'20011'},
{'year':2001,'week':1,'membership':'Student','count':'20011'},
{'year':2001,'week':2,'membership':'Hourly','count':'20012'},
{'year':2001,'week':2,'membership':'Pay-As-You-Go','count':'20012'},
{'year':2002,'week':1,'membership':'Annual','count':'20021'},
{'year':2002,'week':2,'membership':'Student','count':'20022'},
{'year':2003,'week':7,'membership':'Hourly','count':'20037'},
{'year':null,'week':null,'membership':null,'count':'100'}];
const expected_result =
{2001: {1: {'Annual':20011,'Student':20011}, 2: {'Hourly':20012,'Pay-As-You-Go':20012}},
2002: {1: {'Annual':20021}, 2: {'Student':20022}},
2003: {7: {'Hourly':20037}}};
expect(Transformer.countMembershipsByYearAndWeek(rows)).toEqual(expected_result);
})
test('countMembershipsByYearAndMonth', () => {
const rows =
[{'year':2001,'month':1,'membership':'Annual','count':'20011'},
{'year':2001,'month':1,'membership':'Student','count':'20011'},
{'year':2001,'month':2,'membership':'Hourly','count':'20012'},
{'year':2001,'month':2,'membership':'Pay-As-You-Go','count':'20012'},
{'year':2002,'month':1,'membership':'Annual','count':'20021'},
{'year':2002,'month':2,'membership':'Student','count':'20022'},
{'year':2003,'month':7,'membership':'Hourly','count':'20037'},
{'year':null,'month':null,'membership':null,'count':'100'}];
const expected_result =
{2001: {1: {'Annual':20011,'Student':20011}, 2: {'Hourly':20012,'Pay-As-You-Go':20012}},
2002: {1: {'Annual':20021}, 2: {'Student':20022}},
2003: {7: {'Hourly':20037}}};
expect(Transformer.countMembershipsByYearAndMonth(rows)).toEqual(expected_result);
})
test('countByYearAndDayOfYear', () => {
const rows =
[{'year':2001,'day':1,'count':'20011'},
{'year':2001,'day':2,'count':'20012'},
{'year':2001,'day':4,'count':'20014'},
{'year':2001,'day':7,'count':'20017'},
{'year':2002,'day':1,'count':'20021'},
{'year':2002,'day':3,'count':'20023'},
{'year':2003,'day':7,'count':'20037'},
{'year':null,'day':null,'count':'100'}];
const expected_result =
{2001: {1:20011,2:20012,4:20014,7:20017},
2002: {1:20021, 3:20023},
2003: {7:20037}};
expect(Transformer.countByYearAndDayOfYear(rows)).toEqual(expected_result);
})
test('countByYearAndMonthAndDay', () => {
const rows =
[{'year':2001,'month':1,'day':1,'count':'200111'},
{'year':2001,'month':1,'day':2,'count':'200112'},
{'year':2001,'month':2,'day':1,'count':'200121'},
{'year':2001,'month':2,'day':2,'count':'200122'},
{'year':2002,'month':1,'day':1,'count':'200211'},
{'year':2002,'month':2,'day':1,'count':'200221'},
{'year':2003,'month':7,'day':1,'count':'200371'},
{'year':null,'month':null,'day':null,'count':'100'}];
const expected_result =
{2001: {1: {1:200111,2:200112}, 2: {1:200121,2:200122}},
2002: {1: {1:200211}, 2: {1:200221}},
2003: {7: {1:200371}}};
expect(Transformer.countByYearAndMonthAndDay(rows)).toEqual(expected_result);
})
test('countByYearAndMonth', () => {
const rows =
[{'month':1,'year':2001,'count':'20011'},
{'month':2,'year':2001,'count':'20012'},
{'month':1,'year':2002,'count':'20021'},
{'month':2,'year':2002,'count':'20022'},
{'month':7,'year':2003,'count':'20037'},
{'month':null,'year':null,'count':'100'}];
const expected_result =
{2001:[{1:20011},{2:20012}], 2002:[{1:20021},{2:20022}], 2003:[{7:20037}]};
expect(Transformer.countByYearAndMonth(rows)).toEqual(expected_result);
});
test('countByPeriod', () => {
const rows =
[{'fake':0,'count':'429'},
{'fake':1,'count':'231'},
{'fake':23,'count':'710'},
{'fake':null,'count':'183'}];
const expected_result = {'0': 429, '1':231, '23':710};
expect(Transformer.countByPeriod(rows, 'fake')).toEqual(expected_result);
});