From 9aa7d1ae083a5448186f50dd07b2d4d0f2403bb7 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Mon, 1 Aug 2022 15:44:27 +0200
Subject: [PATCH] feat(TU): increase TU

---
 __tests__/aggregate.spec.js | 54 +++++++++++++++++++++++++++++++++++++
 src/aggregate.js            |  4 +--
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/__tests__/aggregate.spec.js b/__tests__/aggregate.spec.js
index 5f304ad..c7b8122 100644
--- a/__tests__/aggregate.spec.js
+++ b/__tests__/aggregate.spec.js
@@ -4,4 +4,58 @@ describe('buildAgregatedData', () => {
     const reply = await buildAgregatedData([], 'com.enedis.day')
     expect(reply).toEqual([])
   })
+  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 month value', async () => {
+    const reply = await buildAgregatedData(
+      {
+        '2022-08': 36,
+      },
+      'com.grandlyon.enedis.month'
+    )
+    expect(reply).toEqual([
+      {
+        day: 0,
+        hour: 0,
+        load: 36,
+        minute: 0,
+        month: 8,
+        year: 2022,
+      },
+    ])
+  })
+  it('should return daily value', async () => {
+    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: 36,
+        minute: 0,
+        month: 8,
+        year: 2022,
+      },
+    ])
+  })
 })
diff --git a/src/aggregate.js b/src/aggregate.js
index 808d34f..00a6619 100644
--- a/src/aggregate.js
+++ b/src/aggregate.js
@@ -9,7 +9,7 @@ async function buildAgregatedData(data, doctype) {
   let agregatedData = []
   // eslint-disable-next-line no-unused-vars
   for (let [key, value] of Object.entries(data)) {
-    const data = await buildDataFromKey(doctype, key, value)
+    const data = buildDataFromKey(doctype, key, value)
     const oldValue = await resetInProgressAggregatedData(data, doctype)
     data.load += oldValue
     agregatedData.push(data)
@@ -23,7 +23,7 @@ async function buildAgregatedData(data, doctype) {
  * For year doctype: key = "YYYY"
  * For month doctype: key = "YYYY-MM"
  */
-async function buildDataFromKey(doctype, key, value) {
+function buildDataFromKey(doctype, key, value) {
   let year, month, day, hour
   if (doctype === 'com.grandlyon.enedis.year') {
     year = key
-- 
GitLab