node-red-contrib-octopus-intelligent 1.0.4 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,194 +0,0 @@
1
- # Test Implementation Summary
2
-
3
- ## Tests Implemented: MQTT Refresh Cooldown (v1.0.4.9)
4
-
5
- **File:** `__tests__/mqtt-refresh-cooldown.test.js`
6
-
7
- **Test Results:** ✅ **5/5 PASSED**
8
-
9
- ---
10
-
11
- ## Test Coverage
12
-
13
- ### Test 1.2: MQTT Button - Rapid Clicking During Cooldown
14
- **Status:** ✅ PASSED
15
-
16
- **What it tests:**
17
- - Simulates user clicking "Octopus Refresh API" button 5 times in 2 seconds
18
- - Verifies only the first click executes
19
- - Confirms subsequent 4 clicks are blocked
20
- - Validates warning messages are logged for each blocked attempt
21
- - Checks Node-RED status updates show cooldown countdown
22
-
23
- **Implementation approach:**
24
- - Uses local payload input/output (no actual Node-RED runtime)
25
- - Mocks `Date.now()` to control time progression
26
- - Tracks published MQTT messages in `publishedMessages` array
27
- - Tracks warnings in `warnings` array
28
- - Simulates button presses by calling `pressMqttRefreshButton()` function
29
-
30
- **Key assertions:**
31
- ```javascript
32
- expect(result1.blocked).toBe(false); // First click works
33
- expect(result2.blocked).toBe(true); // Second click blocked
34
- expect(publishedMessages).toHaveLength(1); // Only 1 MQTT message
35
- expect(warnings).toHaveLength(4); // 4 blocked attempts logged
36
- ```
37
-
38
- ---
39
-
40
- ### Test 4.2: Countdown Doesn't Go Negative
41
- **Status:** ✅ PASSED (validated within Test 1.2 context)
42
-
43
- **What it tests:**
44
- - Button pressed, 30-second cooldown starts
45
- - After 30 seconds, timer expires
46
- - `refresh_available_at` changes from ISO timestamp to `null`
47
- - Value remains `null` after expiry (doesn't show "5 seconds ago")
48
- - Can refresh again after cooldown expires
49
-
50
- **Implementation approach:**
51
- - Uses time advancement via `advanceTime()` helper
52
- - Checks payload values at T+0s, T+29s, T+30s, T+35s
53
- - Validates timer cleanup and null state persistence
54
-
55
- **Key assertions:**
56
- ```javascript
57
- // At T+0s: Timestamp published
58
- expect(initialPayload.refresh_available_at).not.toBeNull();
59
- expect(initialPayload.refresh_available_at).toMatch(/^\d{4}-\d{2}-\d{2}T/);
60
-
61
- // At T+30s: Null published (NOT negative time)
62
- expect(expiryPayload.refresh_available_at).toBeNull();
63
-
64
- // At T+35s: Still null (no additional publishes)
65
- expect(publishedMessages).toHaveLength(2);
66
- ```
67
-
68
- ---
69
-
70
- ## Additional Tests Implemented
71
-
72
- ### Test 3: Correct Timestamp Values Throughout Lifecycle
73
- **Status:** ✅ PASSED
74
-
75
- Validates exact payload values at:
76
- - T+0s: Future timestamp (30s ahead)
77
- - T+15s: No publish (midpoint)
78
- - T+30s: Null published (expiry)
79
- - T+31s: No publish (after expiry)
80
-
81
- **Result:** Confirms exactly 2 MQTT messages per refresh (start + expiry)
82
-
83
- ---
84
-
85
- ### Test 4: Timer Cleanup
86
- **Status:** ✅ PASSED
87
-
88
- Verifies:
89
- - Timer is created when button pressed
90
- - Timer executes at 30 seconds
91
- - Timer is removed from active timers after execution
92
- - New timer can be created for subsequent refresh
93
-
94
- ---
95
-
96
- ### Test 5: MQTT Message Structure
97
- **Status:** ✅ PASSED
98
-
99
- Validates published messages contain:
100
- - Correct topic: `nodered_octopus/{account}/status`
101
- - Correct payload structure with all required fields
102
- - ISO 8601 timestamp format
103
- - `retain: true` option
104
-
105
- ---
106
-
107
- ## Test Architecture
108
-
109
- ### Mock Strategy
110
- ```javascript
111
- // Time control
112
- jest.spyOn(Date, 'now').mockImplementation(() => currentTime);
113
-
114
- // Timer tracking
115
- jest.spyOn(global, 'setTimeout').mockImplementation((callback, delay) => {
116
- timers.push({ callback, delay, executeAt: currentTime + delay });
117
- });
118
-
119
- // MQTT publish tracking
120
- node.broker.client.publish = jest.fn((topic, payload, options) => {
121
- publishedMessages.push({ topic, payload: JSON.parse(payload), options });
122
- });
123
- ```
124
-
125
- ### State Management
126
- - **Persistent across calls:** `lastManualRefresh`, `cooldownExpiryTimer`, `lastKnownState`
127
- - **Reset per test:** `publishedMessages`, `warnings`, `timers`
128
- - **Controlled advancement:** `advanceTime(milliseconds)` helper
129
-
130
- ### Helper Functions
131
- ```javascript
132
- pressMqttRefreshButton() // Simulates MQTT button press
133
- advanceTime(ms) // Advances time and executes timers
134
- ```
135
-
136
- ---
137
-
138
- ## Coverage Summary
139
-
140
- | Feature | Test | Status |
141
- |---------|------|--------|
142
- | MQTT rate limiting (30s) | Test 1.2 | ✅ PASS |
143
- | Rapid click blocking | Test 1.2 | ✅ PASS |
144
- | Countdown expiry | Test 4.2 | ✅ PASS |
145
- | No negative countdown | Test 4.2 | ✅ PASS |
146
- | Timestamp values | Test 3 | ✅ PASS |
147
- | Timer cleanup | Test 4 | ✅ PASS |
148
- | MQTT message structure | Test 5 | ✅ PASS |
149
-
150
- **Total:** 7 features tested across 5 test cases
151
-
152
- ---
153
-
154
- ## Running the Tests
155
-
156
- ```bash
157
- # Run only these tests
158
- npm test -- mqtt-refresh-cooldown.test.js
159
-
160
- # Run all tests
161
- npm test
162
-
163
- # Run with coverage
164
- npm run test:coverage
165
- ```
166
-
167
- ---
168
-
169
- ## Test Output Example
170
-
171
- ```
172
- PASS __tests__/mqtt-refresh-cooldown.test.js
173
- MQTT Refresh Button Cooldown
174
- ✓ Test 1.2: Should block rapid MQTT button clicks during cooldown (7 ms)
175
- ✓ Test 4.2: Should clear countdown at expiry and not go negative (4 ms)
176
- ✓ Should publish correct timestamp values throughout cooldown lifecycle (1 ms)
177
- ✓ Should properly clean up cooldown timer after expiry (1 ms)
178
- ✓ Should publish MQTT messages with correct structure (1 ms)
179
-
180
- Test Suites: 1 passed, 1 total
181
- Tests: 5 passed, 5 total
182
- ```
183
-
184
- ---
185
-
186
- ## Next Steps
187
-
188
- Remaining tests from test plan to implement:
189
- - Test 1.4: Node-RED Input - No Rate Limiting
190
- - Test 1.5: Mixed MQTT and Node-RED Refreshes
191
- - Test 2.1-2.4: API Complexity Tracking
192
- - Test 3.1-3.2: Refresh Button Existence
193
- - Edge cases (E1-E3)
194
- - Performance tests (P1-P2)
@@ -1,495 +0,0 @@
1
- /**
2
- * Charging Now Validation Mode Tests
3
- *
4
- * Comprehensive tests using real API response structure to verify that
5
- * charging_now is correctly detected across various scenarios:
6
- * - 1 slot, 3 slots, 6 slots
7
- * - Active slot at different positions (first, middle, last)
8
- * - No active slots (between slots, before all slots)
9
- * - Validation mode vs normal mode
10
- *
11
- * Based on real API response structure from user's system.
12
- */
13
-
14
- const {
15
- mockRealApiResponse_1Slot_Active,
16
- mockRealApiResponse_1Slot_Future,
17
- mockRealApiResponse_3Slots_FirstActive,
18
- mockRealApiResponse_3Slots_MiddleActive,
19
- mockRealApiResponse_3Slots_LastActive,
20
- mockRealApiResponse_3Slots_NoneActive,
21
- mockRealApiResponse_6Slots_FirstActive,
22
- mockRealApiResponse_6Slots_ThirdActive,
23
- mockRealApiResponse_6Slots_LastActive,
24
- mockRealApiResponse_6Slots_NoneActive,
25
- createMockBroker
26
- } = require('../test-mocks');
27
-
28
- describe('Charging Now - Real API Data Tests', () => {
29
- let mockBroker;
30
- let chargingNow;
31
- let cachedSlots;
32
- let stateCheckInterval;
33
-
34
- // Mock node for logging
35
- const mockNode = {
36
- log: jest.fn(),
37
- warn: jest.fn()
38
- };
39
-
40
- beforeEach(() => {
41
- jest.clearAllMocks();
42
- jest.useFakeTimers();
43
-
44
- mockBroker = createMockBroker();
45
-
46
- // Initialize state variables
47
- chargingNow = false;
48
- cachedSlots = [];
49
- stateCheckInterval = null;
50
- });
51
-
52
- afterEach(() => {
53
- jest.useRealTimers();
54
- });
55
-
56
- // ==========================================================================
57
- // Helper Functions
58
- // ==========================================================================
59
-
60
- function publishChargingState(state) {
61
- chargingNow = state;
62
- const enableMqtt = true;
63
- const stateTopic = 'nodered_octopus/A-TEST1234/status';
64
-
65
- if (enableMqtt && mockBroker) {
66
- const payload = state ? "ON" : "OFF";
67
- mockBroker.client.publish(`${stateTopic}/charging_now`, payload, { retain: true });
68
- }
69
- }
70
-
71
- function setupChargingTimers(slots) {
72
- cachedSlots = slots;
73
- const now = new Date();
74
-
75
- const activeSlot = slots.find(s => {
76
- const start = new Date(s.startDt);
77
- const end = new Date(s.endDt);
78
- return start <= now && end > now;
79
- });
80
-
81
- if (activeSlot) {
82
- const newState = true;
83
- if (chargingNow !== newState) {
84
- publishChargingState(newState);
85
- }
86
- mockNode.log("Currently charging - end timer set");
87
- } else {
88
- const newState = false;
89
- if (chargingNow !== newState) {
90
- publishChargingState(newState);
91
- }
92
- }
93
- }
94
-
95
- // BUGGY version - skips setupChargingTimers in validation mode
96
- function processDataWithBug(slots, validationMode) {
97
- if (!validationMode) {
98
- setupChargingTimers(slots);
99
- if (!stateCheckInterval) {
100
- stateCheckInterval = setInterval(() => {}, 10000);
101
- }
102
- }
103
- return { charging_now: chargingNow };
104
- }
105
-
106
- // FIXED version - always calls setupChargingTimers
107
- function processDataFixed(slots, validationMode) {
108
- setupChargingTimers(slots);
109
- if (!validationMode && !stateCheckInterval) {
110
- stateCheckInterval = setInterval(() => {}, 10000);
111
- }
112
- return { charging_now: chargingNow };
113
- }
114
-
115
- // ==========================================================================
116
- // Test Matrix: 1 Slot Scenarios
117
- // ==========================================================================
118
-
119
- describe('1 Slot Scenarios', () => {
120
- test('1 slot - ACTIVE (charging now)', () => {
121
- const mock = mockRealApiResponse_1Slot_Active;
122
- jest.setSystemTime(new Date(mock.testTime));
123
-
124
- const slots = mock.data.data.plannedDispatches;
125
- chargingNow = false;
126
-
127
- setupChargingTimers(slots);
128
-
129
- expect(chargingNow).toBe(mock.expectedChargingNow);
130
- expect(chargingNow).toBe(true);
131
- });
132
-
133
- test('1 slot - NOT ACTIVE (future)', () => {
134
- const mock = mockRealApiResponse_1Slot_Future;
135
- jest.setSystemTime(new Date(mock.testTime));
136
-
137
- const slots = mock.data.data.plannedDispatches;
138
- chargingNow = false;
139
-
140
- setupChargingTimers(slots);
141
-
142
- expect(chargingNow).toBe(mock.expectedChargingNow);
143
- expect(chargingNow).toBe(false);
144
- });
145
- });
146
-
147
- // ==========================================================================
148
- // Test Matrix: 3 Slots Scenarios
149
- // ==========================================================================
150
-
151
- describe('3 Slots Scenarios', () => {
152
- test('3 slots - FIRST ACTIVE', () => {
153
- const mock = mockRealApiResponse_3Slots_FirstActive;
154
- jest.setSystemTime(new Date(mock.testTime));
155
-
156
- const slots = mock.data.data.plannedDispatches;
157
- chargingNow = false;
158
-
159
- setupChargingTimers(slots);
160
-
161
- expect(chargingNow).toBe(mock.expectedChargingNow);
162
- expect(chargingNow).toBe(true);
163
- });
164
-
165
- test('3 slots - MIDDLE ACTIVE', () => {
166
- const mock = mockRealApiResponse_3Slots_MiddleActive;
167
- jest.setSystemTime(new Date(mock.testTime));
168
-
169
- const slots = mock.data.data.plannedDispatches;
170
- chargingNow = false;
171
-
172
- setupChargingTimers(slots);
173
-
174
- expect(chargingNow).toBe(mock.expectedChargingNow);
175
- expect(chargingNow).toBe(true);
176
- });
177
-
178
- test('3 slots - LAST ACTIVE', () => {
179
- const mock = mockRealApiResponse_3Slots_LastActive;
180
- jest.setSystemTime(new Date(mock.testTime));
181
-
182
- const slots = mock.data.data.plannedDispatches;
183
- chargingNow = false;
184
-
185
- setupChargingTimers(slots);
186
-
187
- expect(chargingNow).toBe(mock.expectedChargingNow);
188
- expect(chargingNow).toBe(true);
189
- });
190
-
191
- test('3 slots - NONE ACTIVE (between slots)', () => {
192
- const mock = mockRealApiResponse_3Slots_NoneActive;
193
- jest.setSystemTime(new Date(mock.testTime));
194
-
195
- const slots = mock.data.data.plannedDispatches;
196
- chargingNow = false;
197
-
198
- setupChargingTimers(slots);
199
-
200
- expect(chargingNow).toBe(mock.expectedChargingNow);
201
- expect(chargingNow).toBe(false);
202
- });
203
- });
204
-
205
- // ==========================================================================
206
- // Test Matrix: 6 Slots Scenarios
207
- // ==========================================================================
208
-
209
- describe('6 Slots Scenarios', () => {
210
- test('6 slots - FIRST ACTIVE', () => {
211
- const mock = mockRealApiResponse_6Slots_FirstActive;
212
- jest.setSystemTime(new Date(mock.testTime));
213
-
214
- const slots = mock.data.data.plannedDispatches;
215
- chargingNow = false;
216
-
217
- setupChargingTimers(slots);
218
-
219
- expect(chargingNow).toBe(mock.expectedChargingNow);
220
- expect(chargingNow).toBe(true);
221
- });
222
-
223
- test('6 slots - THIRD ACTIVE (middle)', () => {
224
- const mock = mockRealApiResponse_6Slots_ThirdActive;
225
- jest.setSystemTime(new Date(mock.testTime));
226
-
227
- const slots = mock.data.data.plannedDispatches;
228
- chargingNow = false;
229
-
230
- setupChargingTimers(slots);
231
-
232
- expect(chargingNow).toBe(mock.expectedChargingNow);
233
- expect(chargingNow).toBe(true);
234
- });
235
-
236
- test('6 slots - LAST ACTIVE', () => {
237
- const mock = mockRealApiResponse_6Slots_LastActive;
238
- jest.setSystemTime(new Date(mock.testTime));
239
-
240
- const slots = mock.data.data.plannedDispatches;
241
- chargingNow = false;
242
-
243
- setupChargingTimers(slots);
244
-
245
- expect(chargingNow).toBe(mock.expectedChargingNow);
246
- expect(chargingNow).toBe(true);
247
- });
248
-
249
- test('6 slots - NONE ACTIVE (between slots)', () => {
250
- const mock = mockRealApiResponse_6Slots_NoneActive;
251
- jest.setSystemTime(new Date(mock.testTime));
252
-
253
- const slots = mock.data.data.plannedDispatches;
254
- chargingNow = false;
255
-
256
- setupChargingTimers(slots);
257
-
258
- expect(chargingNow).toBe(mock.expectedChargingNow);
259
- expect(chargingNow).toBe(false);
260
- });
261
- });
262
-
263
- // ==========================================================================
264
- // Validation Mode Bug Tests (BEFORE FIX)
265
- // ==========================================================================
266
-
267
- describe('BEFORE FIX: Validation Mode Bug', () => {
268
- test('DEMONSTRATES BUG: validation mode skips setupChargingTimers() with active slot', () => {
269
- const mock = mockRealApiResponse_3Slots_MiddleActive;
270
- jest.setSystemTime(new Date(mock.testTime));
271
-
272
- const slots = mock.data.data.plannedDispatches;
273
- chargingNow = false;
274
-
275
- // Process in validation mode with BUGGY version
276
- const payload = processDataWithBug(slots, true);
277
-
278
- // BUG: chargingNow remains false even though we're in active slot
279
- expect(chargingNow).toBe(false); // ❌ Should be true
280
- expect(payload.charging_now).toBe(false); // ❌ Should be true
281
-
282
- // MQTT not updated (setupChargingTimers was skipped)
283
- const published = mockBroker.getPublished();
284
- expect(published.length).toBe(0);
285
- });
286
-
287
- test('COMPARISON: normal mode correctly updates state', () => {
288
- const mock = mockRealApiResponse_3Slots_MiddleActive;
289
- jest.setSystemTime(new Date(mock.testTime));
290
-
291
- const slots = mock.data.data.plannedDispatches;
292
- chargingNow = false;
293
-
294
- // Process in NORMAL mode
295
- const payload = processDataWithBug(slots, false);
296
-
297
- // Normal mode works correctly
298
- expect(chargingNow).toBe(true); // ✅ Correct
299
- expect(payload.charging_now).toBe(true); // ✅ Correct
300
-
301
- const published = mockBroker.getPublished();
302
- expect(published.length).toBe(1);
303
- expect(published[0].payload).toBe('ON');
304
- });
305
-
306
- test('BUG AFFECTS ALL SLOT COUNTS: 1 slot validation mode', () => {
307
- const mock = mockRealApiResponse_1Slot_Active;
308
- jest.setSystemTime(new Date(mock.testTime));
309
-
310
- const slots = mock.data.data.plannedDispatches;
311
- chargingNow = false;
312
-
313
- const payload = processDataWithBug(slots, true);
314
-
315
- expect(chargingNow).toBe(false); // ❌ Bug
316
- });
317
-
318
- test('BUG AFFECTS ALL SLOT COUNTS: 6 slots validation mode', () => {
319
- const mock = mockRealApiResponse_6Slots_LastActive;
320
- jest.setSystemTime(new Date(mock.testTime));
321
-
322
- const slots = mock.data.data.plannedDispatches;
323
- chargingNow = false;
324
-
325
- const payload = processDataWithBug(slots, true);
326
-
327
- expect(chargingNow).toBe(false); // ❌ Bug
328
- });
329
- });
330
-
331
- // ==========================================================================
332
- // Fixed Behavior Tests (AFTER FIX)
333
- // ==========================================================================
334
-
335
- describe('AFTER FIX: Validation Mode Fixed', () => {
336
- test('VERIFIES FIX: validation mode now correctly detects 1 active slot', () => {
337
- const mock = mockRealApiResponse_1Slot_Active;
338
- jest.setSystemTime(new Date(mock.testTime));
339
-
340
- const slots = mock.data.data.plannedDispatches;
341
- chargingNow = false;
342
-
343
- const payload = processDataFixed(slots, true);
344
-
345
- expect(chargingNow).toBe(true); // ✅ FIXED
346
- expect(payload.charging_now).toBe(true); // ✅ FIXED
347
-
348
- const published = mockBroker.getPublished();
349
- expect(published.length).toBe(1);
350
- expect(published[0].payload).toBe('ON');
351
- });
352
-
353
- test('VERIFIES FIX: validation mode works with 3 slots - first active', () => {
354
- const mock = mockRealApiResponse_3Slots_FirstActive;
355
- jest.setSystemTime(new Date(mock.testTime));
356
-
357
- const slots = mock.data.data.plannedDispatches;
358
- chargingNow = false;
359
-
360
- const payload = processDataFixed(slots, true);
361
-
362
- expect(chargingNow).toBe(true); // ✅ FIXED
363
- });
364
-
365
- test('VERIFIES FIX: validation mode works with 3 slots - middle active', () => {
366
- const mock = mockRealApiResponse_3Slots_MiddleActive;
367
- jest.setSystemTime(new Date(mock.testTime));
368
-
369
- const slots = mock.data.data.plannedDispatches;
370
- chargingNow = false;
371
-
372
- const payload = processDataFixed(slots, true);
373
-
374
- expect(chargingNow).toBe(true); // ✅ FIXED
375
- });
376
-
377
- test('VERIFIES FIX: validation mode works with 3 slots - last active', () => {
378
- const mock = mockRealApiResponse_3Slots_LastActive;
379
- jest.setSystemTime(new Date(mock.testTime));
380
-
381
- const slots = mock.data.data.plannedDispatches;
382
- chargingNow = false;
383
-
384
- const payload = processDataFixed(slots, true);
385
-
386
- expect(chargingNow).toBe(true); // ✅ FIXED
387
- });
388
-
389
- test('VERIFIES FIX: validation mode works with 6 slots - first active', () => {
390
- const mock = mockRealApiResponse_6Slots_FirstActive;
391
- jest.setSystemTime(new Date(mock.testTime));
392
-
393
- const slots = mock.data.data.plannedDispatches;
394
- chargingNow = false;
395
-
396
- const payload = processDataFixed(slots, true);
397
-
398
- expect(chargingNow).toBe(true); // ✅ FIXED
399
- });
400
-
401
- test('VERIFIES FIX: validation mode works with 6 slots - middle active', () => {
402
- const mock = mockRealApiResponse_6Slots_ThirdActive;
403
- jest.setSystemTime(new Date(mock.testTime));
404
-
405
- const slots = mock.data.data.plannedDispatches;
406
- chargingNow = false;
407
-
408
- const payload = processDataFixed(slots, true);
409
-
410
- expect(chargingNow).toBe(true); // ✅ FIXED
411
- });
412
-
413
- test('VERIFIES FIX: validation mode works with 6 slots - last active', () => {
414
- const mock = mockRealApiResponse_6Slots_LastActive;
415
- jest.setSystemTime(new Date(mock.testTime));
416
-
417
- const slots = mock.data.data.plannedDispatches;
418
- chargingNow = false;
419
-
420
- const payload = processDataFixed(slots, true);
421
-
422
- expect(chargingNow).toBe(true); // ✅ FIXED
423
- });
424
-
425
- test('VERIFIES FIX: validation mode correctly shows not charging when between slots', () => {
426
- const mock = mockRealApiResponse_3Slots_NoneActive;
427
- jest.setSystemTime(new Date(mock.testTime));
428
-
429
- const slots = mock.data.data.plannedDispatches;
430
- chargingNow = false;
431
-
432
- const payload = processDataFixed(slots, true);
433
-
434
- expect(chargingNow).toBe(false); // ✅ Correct
435
- });
436
-
437
- test('VERIFIES FIX: reconciliation loop NOT started in validation mode', () => {
438
- const mock = mockRealApiResponse_1Slot_Active;
439
- jest.setSystemTime(new Date(mock.testTime));
440
-
441
- const slots = mock.data.data.plannedDispatches;
442
- stateCheckInterval = null;
443
-
444
- processDataFixed(slots, true);
445
-
446
- expect(stateCheckInterval).toBeNull();
447
- });
448
-
449
- test('VERIFIES FIX: reconciliation loop IS started in normal mode', () => {
450
- const mock = mockRealApiResponse_1Slot_Active;
451
- jest.setSystemTime(new Date(mock.testTime));
452
-
453
- const slots = mock.data.data.plannedDispatches;
454
- stateCheckInterval = null;
455
-
456
- processDataFixed(slots, false);
457
-
458
- expect(stateCheckInterval).not.toBeNull();
459
- });
460
- });
461
-
462
- // ==========================================================================
463
- // Summary Test - Complete Matrix Coverage
464
- // ==========================================================================
465
-
466
- describe('Test Matrix Summary', () => {
467
- test('SUMMARY: All real API scenarios covered', () => {
468
- const scenarios = [
469
- { name: '1 slot active', mock: mockRealApiResponse_1Slot_Active, expected: true },
470
- { name: '1 slot future', mock: mockRealApiResponse_1Slot_Future, expected: false },
471
- { name: '3 slots first active', mock: mockRealApiResponse_3Slots_FirstActive, expected: true },
472
- { name: '3 slots middle active', mock: mockRealApiResponse_3Slots_MiddleActive, expected: true },
473
- { name: '3 slots last active', mock: mockRealApiResponse_3Slots_LastActive, expected: true },
474
- { name: '3 slots none active', mock: mockRealApiResponse_3Slots_NoneActive, expected: false },
475
- { name: '6 slots first active', mock: mockRealApiResponse_6Slots_FirstActive, expected: true },
476
- { name: '6 slots middle active', mock: mockRealApiResponse_6Slots_ThirdActive, expected: true },
477
- { name: '6 slots last active', mock: mockRealApiResponse_6Slots_LastActive, expected: true },
478
- { name: '6 slots none active', mock: mockRealApiResponse_6Slots_NoneActive, expected: false }
479
- ];
480
-
481
- scenarios.forEach(scenario => {
482
- jest.setSystemTime(new Date(scenario.mock.testTime));
483
- const slots = scenario.mock.data.data.plannedDispatches;
484
- chargingNow = false;
485
-
486
- setupChargingTimers(slots);
487
-
488
- expect(chargingNow).toBe(scenario.expected);
489
- });
490
-
491
- // Verify test matrix coverage
492
- expect(scenarios.length).toBe(10); // Complete coverage
493
- });
494
- });
495
- });