From: Jérôme Benoit Date: Fri, 26 Jul 2024 16:52:31 +0000 (+0200) Subject: test: add checkConfiguration() helper test X-Git-Tag: ocpp-server@v1.5.1~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=243a494b9598b7aa85f9b5cdca067cd5fd4f5b06;p=e-mobility-charging-stations-simulator.git test: add checkConfiguration() helper test Signed-off-by: Jérôme Benoit --- diff --git a/tests/charging-station/Helpers.test.ts b/tests/charging-station/Helpers.test.ts index 865d595f..85e66adb 100644 --- a/tests/charging-station/Helpers.test.ts +++ b/tests/charging-station/Helpers.test.ts @@ -5,6 +5,7 @@ import { expect } from 'expect' import { checkChargingStationState, + checkConfiguration, checkTemplate, getChargingStationId, getHashId, @@ -14,6 +15,7 @@ import { import type { ChargingStation } from '../../src/charging-station/index.js' import { BaseError } from '../../src/exception/index.js' import { + type ChargingStationConfiguration, type ChargingStationInfo, type ChargingStationTemplate, type ConnectorStatus, @@ -163,4 +165,18 @@ await describe('Helpers test suite', async () => { checkTemplate(chargingStationTemplate, 'log prefix |', 'test-template.json') expect(logger.warn.mock.calls.length).toBe(1) }) + + await it('Verify checkConfiguration()', t => { + t.mock.method(logger, 'error') + expect(() => { + checkConfiguration(undefined, 'log prefix |', 'configuration.json') + }).toThrow( + new BaseError('Failed to read charging station configuration file configuration.json') + ) + expect(logger.error.mock.calls.length).toBe(1) + expect(() => { + checkConfiguration({} as ChargingStationConfiguration, 'log prefix |', 'configuration.json') + }).toThrow(new BaseError('Empty charging station configuration from file configuration.json')) + expect(logger.error.mock.calls.length).toBe(2) + }) })