From: Jérôme Benoit Date: Fri, 6 Mar 2026 22:40:36 +0000 (+0100) Subject: fix: correct @mikro-orm/sqlite import to @mikro-orm/better-sqlite, format ElectricUti... X-Git-Tag: ocpp-server@v3.0.0~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6f8f3c31a9d9ba42a67e01578b7bef81a82dc44a;p=e-mobility-charging-stations-simulator.git fix: correct @mikro-orm/sqlite import to @mikro-orm/better-sqlite, format ElectricUtils tests --- diff --git a/mikro-orm.config.ts b/mikro-orm.config.ts new file mode 100644 index 00000000..db186aa2 --- /dev/null +++ b/mikro-orm.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from '@mikro-orm/better-sqlite' + +import { Constants } from './src/utils/index.js' + +export default defineConfig({ + dbName: `${Constants.DEFAULT_PERFORMANCE_DIRECTORY}/${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`, + debug: true, + entities: ['./dist/types/orm/entities/*.js'], + entitiesTs: ['./src/types/orm/entities/*.ts'], +}) diff --git a/tests/utils/ElectricUtils.test.ts b/tests/utils/ElectricUtils.test.ts index 99786162..a9cd9ac4 100644 --- a/tests/utils/ElectricUtils.test.ts +++ b/tests/utils/ElectricUtils.test.ts @@ -16,53 +16,65 @@ await describe('ElectricUtils', async () => { afterEach(() => { standardCleanup() }) + await it('should calculate DC power from voltage and current', () => { expect(DCElectricUtils.power(230, 1)).toBe(230) }) + await it('should calculate DC amperage from power and voltage', () => { expect(DCElectricUtils.amperage(1, 230)).toBe(0) }) + await it('should calculate total AC power for all phases', () => { expect(ACElectricUtils.powerTotal(3, 230, 1)).toBe(690) }) + await it('should calculate AC power per phase', () => { expect(ACElectricUtils.powerPerPhase(230, 1)).toBe(230) }) + await it('should calculate total AC amperage for all phases', () => { expect(ACElectricUtils.amperageTotal(3, 1)).toBe(3) }) + await it('should calculate total AC amperage from power and voltage', () => { expect(ACElectricUtils.amperageTotalFromPower(690, 230)).toBe(3) }) + await it('should calculate AC amperage per phase from power', () => { expect(ACElectricUtils.amperagePerPhaseFromPower(3, 690, 230)).toBe(1) }) + await it('should return 0 for DC amperage when voltage is zero', () => { expect(DCElectricUtils.amperage(1000, 0)).toBe(0) }) + await it('should return 0 for AC amperage when voltage is zero', () => { expect(ACElectricUtils.amperageTotalFromPower(1000, 0)).toBe(0) }) + await it('should return 0 for AC amperage when cosPhi is zero', () => { expect(ACElectricUtils.amperageTotalFromPower(1000, 230, 0)).toBe(0) }) + await it('should return 0 for AC amperage per phase when phases is zero or negative', () => { expect(ACElectricUtils.amperagePerPhaseFromPower(0, 690, 230)).toBe(0) expect(ACElectricUtils.amperagePerPhaseFromPower(-1, 690, 230)).toBe(0) }) + await it('should round AC power per phase with non-unity cosPhi', () => { expect(ACElectricUtils.powerPerPhase(230, 10, COS_PHI_RESIDENTIAL)).toBe(1955) }) + await it('should round DC amperage when power is not evenly divisible by voltage', () => { expect(DCElectricUtils.amperage(100, 3)).toBe(33) }) + await it('should calculate DC power as voltage times current', () => { expect(DCElectricUtils.power(0, 10)).toBe(0) expect(DCElectricUtils.power(400, 0)).toBe(0) }) - // Realistic EV charging scenarios - await it('should calculate 7.4 kW single-phase AC home charger values', () => { // 230V × 32A × 1 phase × cosPhi=1 = 7360W expect(ACElectricUtils.powerPerPhase(230, 32)).toBe(7360)