From 03372f56f75ed0d16b9463598fda72c1310aa553 Mon Sep 17 00:00:00 2001 From: Boris Kubiak Date: Fri, 6 Sep 2024 14:36:28 +0200 Subject: [PATCH] Add new unit test --- src/cost.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cost.test.ts b/src/cost.test.ts index 1c7c818..2ba5adf 100644 --- a/src/cost.test.ts +++ b/src/cost.test.ts @@ -28,6 +28,33 @@ describe('Cost computer', () => { ]); }); + it('Should not bug as described by #69', () => { + const result = computeCosts( + [ + { start: '2023-06-01T00:00:00+01:00', state: 1000 * 100, sum: 0 }, // 100 kWh + { start: '2024-06-01T00:00:00+01:00', state: 1000 * 100, sum: 0 }, // 100 kWh + ], + [ + { price: 0.2516, start_date: '2024-02-01' }, + { price: 0.2276, start_date: '2023-08-01', end_date: '2024-01-31' }, + { price: 0.2062, start_date: '2023-02-01', end_date: '2023-07-31' }, + ], + ); + + expect(result).toEqual([ + { + start: '2023-06-01T00:00:00+01:00', + state: 20.62, // = 100 kWh * 0.2062 + sum: 20.62, + }, + { + start: '2024-06-01T00:00:00+01:00', + state: 25.16, // = 100 kWh * 0.2516 + sum: 20.62 + 25.16, + }, + ]); + }); + it('Should take weekday in account', () => { const result = computeCosts( [