diff --git a/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.test.ts b/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.test.ts index 360c7cf36..b450b1fd5 100644 --- a/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.test.ts +++ b/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.test.ts @@ -1,4 +1,5 @@ import { DeviceModelId } from "@api/device/DeviceModel"; +import { BleDeviceInfos } from "@internal/transport/ble/model/BleDeviceInfos"; import { StaticDeviceModelDataSource } from "./StaticDeviceModelDataSource"; @@ -149,4 +150,50 @@ describe("StaticDeviceModelDataSource", () => { expect(deviceModels3.length).toEqual(0); }); }); + describe("getBluetoothServicesInfos", () => { + it("should return the ble service infos record", () => { + // given + const dataSource = new StaticDeviceModelDataSource(); + // when + const bleServiceInfos = dataSource.getBluetoothServicesInfos(); + // then + expect(bleServiceInfos).toStrictEqual({ + "13d63400-2c97-0004-0000-4c6564676572": new BleDeviceInfos( + dataSource.getDeviceModel({ id: DeviceModelId.NANO_X }), + "13d63400-2c97-0004-0000-4c6564676572", + "13d63400-2c97-0004-0002-4c6564676572", + "13d63400-2c97-0004-0003-4c6564676572", + "13d63400-2c97-0004-0001-4c6564676572", + ), + "13d63400-2c97-6004-0000-4c6564676572": new BleDeviceInfos( + dataSource.getDeviceModel({ id: DeviceModelId.STAX }), + "13d63400-2c97-6004-0000-4c6564676572", + "13d63400-2c97-6004-0002-4c6564676572", + "13d63400-2c97-6004-0003-4c6564676572", + "13d63400-2c97-6004-0001-4c6564676572", + ), + "13d63400-2c97-3004-0000-4c6564676572": new BleDeviceInfos( + dataSource.getDeviceModel({ id: DeviceModelId.FLEX }), + "13d63400-2c97-3004-0000-4c6564676572", + "13d63400-2c97-3004-0002-4c6564676572", + "13d63400-2c97-3004-0003-4c6564676572", + "13d63400-2c97-3004-0001-4c6564676572", + ), + }); + }); + }); + describe("getBluetoothServices", () => { + it("should return the bluetooth services", () => { + // given + const dataSource = new StaticDeviceModelDataSource(); + // when + const bleServices = dataSource.getBluetoothServices(); + // then + expect(bleServices).toStrictEqual([ + "13d63400-2c97-0004-0000-4c6564676572", + "13d63400-2c97-6004-0000-4c6564676572", + "13d63400-2c97-3004-0000-4c6564676572", + ]); + }); + }); }); diff --git a/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.ts b/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.ts index c50a2cb33..57b7a9d86 100644 --- a/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.ts +++ b/packages/core/src/internal/device-model/data/StaticDeviceModelDataSource.ts @@ -134,15 +134,11 @@ export class StaticDeviceModelDataSource implements DeviceModelDataSource { } getBluetoothServices(): string[] { - return Object.values(StaticDeviceModelDataSource.deviceModelByIds).reduce< - string[] - >((acc, deviceModel) => { - const { bluetoothSpec } = deviceModel; - - if (bluetoothSpec) { - return acc.concat(bluetoothSpec.map((spec) => spec.serviceUuid)); - } - return acc; - }, []); + return Object.values(StaticDeviceModelDataSource.deviceModelByIds) + .map((deviceModel) => + (deviceModel.bluetoothSpec || []).map((spec) => spec.serviceUuid), + ) + .flat() + .filter((uuid) => !!uuid); } } diff --git a/packages/core/src/internal/device-session/use-case/CloseSessionsUseState.test.ts b/packages/core/src/internal/device-session/use-case/CloseSessionsUseState.test.ts new file mode 100644 index 000000000..238a69f92 --- /dev/null +++ b/packages/core/src/internal/device-session/use-case/CloseSessionsUseState.test.ts @@ -0,0 +1,51 @@ +import { deviceSessionStubBuilder } from "@internal/device-session/model/DeviceSession.stub"; +import { DefaultDeviceSessionService } from "@internal/device-session/service/DefaultDeviceSessionService"; +import { DeviceSessionService } from "@internal/device-session/service/DeviceSessionService"; +import { CloseSessionsUseCase } from "@internal/device-session/use-case/CloseSessionsUseCase"; +import { DefaultLoggerPublisherService } from "@internal/logger-publisher/service/DefaultLoggerPublisherService"; +import { LoggerPublisherService } from "@internal/logger-publisher/service/LoggerPublisherService"; +import { AxiosManagerApiDataSource } from "@internal/manager-api/data/AxiosManagerApiDataSource"; +import { ManagerApiDataSource } from "@internal/manager-api/data/ManagerApiDataSource"; +import { DefaultManagerApiService } from "@internal/manager-api/service/DefaultManagerApiService"; +import { ManagerApiService } from "@internal/manager-api/service/ManagerApiService"; + +let logger: LoggerPublisherService; +let managerApiDataSource: ManagerApiDataSource; +let managerApi: ManagerApiService; +let sessionService: DeviceSessionService; + +describe("CloseSessionsUseState", () => { + beforeEach(() => { + logger = new DefaultLoggerPublisherService( + [], + "close-sessions-use-case-test", + ); + managerApiDataSource = new AxiosManagerApiDataSource({ + managerApiUrl: "http://fake.url", + mockUrl: "http://fake-mock.url", + }); + managerApi = new DefaultManagerApiService(managerApiDataSource); + sessionService = new DefaultDeviceSessionService(() => logger); + }); + + it("should be able to close every session", () => { + //given + const sessions = [...Array(10).keys()].map((id) => { + const session = deviceSessionStubBuilder( + { id: id.toString() }, + () => logger, + managerApi, + ); + jest.spyOn(session, "close"); + return session; + }); + sessions.forEach((session) => sessionService.addDeviceSession(session)); + const useCase = new CloseSessionsUseCase(sessionService); + //when + useCase.execute(); + //then + sessions.forEach((session) => { + expect(session.close).toHaveBeenCalled(); + }); + }); +}); diff --git a/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.test.ts b/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.test.ts index ebae70769..d60b8122d 100644 --- a/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.test.ts +++ b/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.test.ts @@ -87,6 +87,9 @@ describe("BleDeviceConnection", () => { const response = connection.sendApdu(new Uint8Array([])); receiveApdu(connection, EMPTY_APDU_RESPONSE); // then + expect( + writeCharacteristic.writeValueWithoutResponse, + ).toHaveBeenCalledTimes(1); expect(await response).toStrictEqual( Right( new ApduResponse({ diff --git a/packages/core/src/internal/transport/mockserver/MockserverTransport.ts b/packages/core/src/internal/transport/mockserver/MockserverTransport.ts index 1016455ac..4e8ac8319 100644 --- a/packages/core/src/internal/transport/mockserver/MockserverTransport.ts +++ b/packages/core/src/internal/transport/mockserver/MockserverTransport.ts @@ -1,3 +1,5 @@ +/* istanbul ignore file */ +// pragma to ignore this file from coverage import { CommandResponse, Device, @@ -94,9 +96,6 @@ export class MockTransport implements Transport { const sessionId: string = params.deviceId; try { const session: Session = await this.mockClient.connect(sessionId); - this.logger.debug("connected device model id::", { - data: { session, sessionId }, - }); const connectedDevice = { sendApdu: (apdu) => { return this.sendApdu(