From e8afacd14b25ff79dd60c74bc708003ddc147080 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 Feb 2026 17:32:17 +0100 Subject: [PATCH] refactor(tests): standardize test naming to BDD style --- .../ConfigurationKeyUtils.test.ts | 48 +++++++++---------- .../ocpp/2.0/OCPP20VariableManager.test.ts | 4 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/charging-station/ConfigurationKeyUtils.test.ts b/tests/charging-station/ConfigurationKeyUtils.test.ts index c7104fd4..f1572099 100644 --- a/tests/charging-station/ConfigurationKeyUtils.test.ts +++ b/tests/charging-station/ConfigurationKeyUtils.test.ts @@ -17,7 +17,7 @@ const VALUE_B = 'ValueB' await describe('ConfigurationKeyUtils test suite', async () => { await describe('getConfigurationKey()', async () => { - await it('returns undefined when configurationKey array is missing', () => { + await it('should return undefined when configurationKey array is missing', () => { const cs = createChargingStation() // remove array // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment @@ -25,7 +25,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(getConfigurationKey(cs, TEST_KEY_1)).toBeUndefined() }) - await it('finds existing key (case-sensitive)', () => { + await it('should find existing key (case-sensitive)', () => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const k = getConfigurationKey(cs, TEST_KEY_1) @@ -33,13 +33,13 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(k?.value).toBe(VALUE_A) }) - await it('respects case sensitivity (no match)', () => { + await it('should respect case sensitivity (no match)', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) expect(getConfigurationKey(cs, MIXED_CASE_KEY.toLowerCase())).toBeUndefined() }) - await it('supports caseInsensitive lookup', () => { + await it('should support caseInsensitive lookup', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) const k = getConfigurationKey(cs, MIXED_CASE_KEY.toLowerCase(), true) @@ -48,7 +48,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { }) await describe('addConfigurationKey()', async () => { - await it('no-op when configurationKey array missing', () => { + await it('should no-op when configurationKey array missing', () => { const cs = createChargingStation() // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment cs.ocppConfiguration = {} as any @@ -56,7 +56,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(getConfigurationKey(cs, TEST_KEY_1)).toBeUndefined() }) - await it('adds new key with default options', () => { + await it('should add new key with default options', () => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const k = getConfigurationKey(cs, TEST_KEY_1) @@ -68,7 +68,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(k?.visible).toBe(true) }) - await it('adds new key with custom options', () => { + await it('should add new key with custom options', () => { const cs = createChargingStation() addConfigurationKey( cs, @@ -83,7 +83,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(k?.visible).toBe(false) }) - await it('logs error and does not overwrite value when key exists and overwrite=false', t => { + await it('should log error and not overwrite value when key exists and overwrite=false', t => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, { readonly: false }, { save: false }) const errorMock = t.mock.method(logger, 'error') @@ -105,7 +105,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(errorMock.mock.calls.length).toBe(1) }) - await it('logs error and leaves key untouched when identical options & value attempted (overwrite=false)', t => { + await it('should log error and leave key untouched when identical options & value attempted (overwrite=false)', t => { const cs = createChargingStation() addConfigurationKey( cs, @@ -131,7 +131,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(errorMock.mock.calls.length).toBe(1) }) - await it('overwrites existing key value and options when overwrite=true', () => { + await it('should overwrite existing key value and options when overwrite=true', () => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, { readonly: false }, { save: false }) addConfigurationKey( @@ -148,7 +148,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(k?.visible).toBe(false) }) - await it('caseInsensitive overwrite updates existing differently cased key', () => { + await it('should caseInsensitive overwrite update existing differently cased key', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) addConfigurationKey( @@ -163,7 +163,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(k?.readonly).toBe(true) }) - await it('case-insensitive false creates separate key with different case', () => { + await it('should case-insensitive false create separate key with different case', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) addConfigurationKey(cs, MIXED_CASE_KEY.toLowerCase(), VALUE_B, undefined, { @@ -177,14 +177,14 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(orig).not.toBe(second) }) - await it('calls saveOcppConfiguration when params.save=true (new key)', t => { + await it('should call saveOcppConfiguration when params.save=true (new key)', t => { const cs = createChargingStation() const saveMock = t.mock.method(cs, 'saveOcppConfiguration') addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: true }) expect(saveMock.mock.calls.length).toBe(1) }) - await it('calls saveOcppConfiguration when overwriting existing key and save=true', t => { + await it('should call saveOcppConfiguration when overwriting existing key and save=true', t => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const saveMock = t.mock.method(cs, 'saveOcppConfiguration') @@ -200,7 +200,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { }) await describe('setConfigurationKeyValue()', async () => { - await it('returns undefined and logs error for non-existing key', t => { + await it('should return undefined and log error for non-existing key', t => { const cs = createChargingStation() const errorMock = t.mock.method(logger, 'error') const res = setConfigurationKeyValue(cs, TEST_KEY_1, VALUE_A) @@ -208,7 +208,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(errorMock.mock.calls.length).toBe(1) }) - await it('returns undefined without logging when configurationKey array missing', t => { + await it('should return undefined without logging when configurationKey array missing', t => { const cs = createChargingStation() // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment cs.ocppConfiguration = {} as any @@ -218,7 +218,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(errorMock.mock.calls.length).toBe(0) }) - await it('updates existing key value and saves', t => { + await it('should update existing key value and save', t => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const saveMock = t.mock.method(cs, 'saveOcppConfiguration') @@ -227,7 +227,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(saveMock.mock.calls.length).toBe(1) }) - await it('caseInsensitive value update works', () => { + await it('should caseInsensitive value update work', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) const updated = setConfigurationKeyValue(cs, MIXED_CASE_KEY.toLowerCase(), VALUE_B, true) @@ -236,7 +236,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { }) await describe('deleteConfigurationKey()', async () => { - await it('returns undefined when configurationKey array missing', () => { + await it('should return undefined when configurationKey array missing', () => { const cs = createChargingStation() // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment cs.ocppConfiguration = {} as any @@ -244,13 +244,13 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(res).toBeUndefined() }) - await it('returns undefined when key does not exist', () => { + await it('should return undefined when key does not exist', () => { const cs = createChargingStation() const res = deleteConfigurationKey(cs, TEST_KEY_1) expect(res).toBeUndefined() }) - await it('deletes existing key and saves by default', t => { + await it('should delete existing key and save by default', t => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const saveMock = t.mock.method(cs, 'saveOcppConfiguration') @@ -262,7 +262,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(saveMock.mock.calls.length).toBe(1) }) - await it('does not save when params.save=false', t => { + await it('should not save when params.save=false', t => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, undefined, { save: false }) const saveMock = t.mock.method(cs, 'saveOcppConfiguration') @@ -271,7 +271,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { expect(saveMock.mock.calls.length).toBe(0) }) - await it('caseInsensitive deletion removes key with different case', () => { + await it('should caseInsensitive deletion remove key with different case', () => { const cs = createChargingStation() addConfigurationKey(cs, MIXED_CASE_KEY, VALUE_A, undefined, { save: false }) const deleted = deleteConfigurationKey(cs, MIXED_CASE_KEY.toLowerCase(), { @@ -284,7 +284,7 @@ await describe('ConfigurationKeyUtils test suite', async () => { }) await describe('Combined scenarios', async () => { - await it('add then set then delete lifecycle', () => { + await it('should add then set then delete lifecycle', () => { const cs = createChargingStation() addConfigurationKey(cs, TEST_KEY_1, VALUE_A, { readonly: false }, { save: false }) const setRes = setConfigurationKeyValue(cs, TEST_KEY_1, VALUE_B) diff --git a/tests/charging-station/ocpp/2.0/OCPP20VariableManager.test.ts b/tests/charging-station/ocpp/2.0/OCPP20VariableManager.test.ts index bc3f9541..da53b9a7 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20VariableManager.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20VariableManager.test.ts @@ -1386,7 +1386,7 @@ await describe('B05/B06 - OCPP20VariableManager test suite', async () => { websocketPingInterval: Constants.DEFAULT_WEBSOCKET_PING_INTERVAL, }) - await it('Returns NotSupportedAttributeType for MinSet HeartbeatInterval', () => { + await it('should return NotSupportedAttributeType for MinSet HeartbeatInterval', () => { const component = { name: OCPP20ComponentName.OCPPCommCtrlr } const variable = { name: OCPP20OptionalVariableName.HeartbeatInterval } const res = manager.getVariables(station, [ @@ -1396,7 +1396,7 @@ await describe('B05/B06 - OCPP20VariableManager test suite', async () => { expect(res.attributeStatusInfo?.reasonCode).toBe(ReasonCodeEnumType.UnsupportedParam) }) - await it('Returns NotSupportedAttributeType for MaxSet WebSocketPingInterval', () => { + await it('should return NotSupportedAttributeType for MaxSet WebSocketPingInterval', () => { const component = { name: OCPP20ComponentName.ChargingStation } const variable = { name: OCPP20OptionalVariableName.WebSocketPingInterval } const res = manager.getVariables(station, [ -- 2.53.0