Newer
Older
const { buildAgregatedData } = require('../src/aggregate')
const { cozyClient } = require('cozy-konnector-libs')
describe('buildAgregatedData', () => {
it('should return empty', async () => {
const reply = await buildAgregatedData([], 'com.enedis.day')
expect(reply).toEqual([])
})
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
it('should return year value', async () => {
const reply = await buildAgregatedData(
{
'2022': 36,
},
'com.grandlyon.enedis.year'
)
expect(reply).toEqual([
{
day: 0,
hour: 0,
load: 36,
minute: 0,
month: 1,
year: 2022,
},
])
})
it('should return year value with doc existing', async () => {
const spy = jest.spyOn(cozyClient.data, 'findAll')
spy.mockResolvedValueOnce([{ year: 2022, month: 8, day: 1, load: 1 }])
const reply = await buildAgregatedData(
{
'2022': 36,
},
'com.grandlyon.enedis.year'
)
expect(reply).toEqual([
{
day: 0,
hour: 0,
load: 37,
minute: 0,
month: 1,
year: 2022,
},
])
})
it('should return month value', async () => {
const spy = jest.spyOn(cozyClient.data, 'findAll')
spy.mockResolvedValueOnce([{ year: 2022, month: 8, day: 1, load: 1 }])
const reply = await buildAgregatedData(
{
'2022-08': 36,
},
'com.grandlyon.enedis.month'
)
expect(reply).toEqual([
{
day: 0,
hour: 0,
load: 37,
minute: 0,
month: 8,
year: 2022,
},
])
})
it('should return daily value', async () => {
const spy = jest.spyOn(cozyClient.data, 'findAll')
spy.mockResolvedValueOnce([
{ year: 2022, month: 8, day: 1, load: 1, hour: 13 },
])
const reply = await buildAgregatedData(
{
'2022-08-01-13:39:25+00:00': 36,
},
'com.grandlyon.enedis.minute'
)
expect(reply).toEqual([
{
day: 1,
hour: 13,
load: 37,
minute: 0,
month: 8,
year: 2022,
},
])
})