-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (core) [NO-ISSUE]: Add a ListDeviceSessions use case (#303)
- Loading branch information
Showing
8 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/device-sdk-core": patch | ||
--- | ||
|
||
Add ListDeviceSessions use case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/core/src/internal/device-session/use-case/ListDeviceSessionsUseCase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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 { 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"; | ||
|
||
import { ListDeviceSessionsUseCase } from "./ListDeviceSessionsUseCase"; | ||
|
||
let logger: LoggerPublisherService; | ||
let sessionService: DeviceSessionService; | ||
let managerApiDataSource: ManagerApiDataSource; | ||
let managerApi: ManagerApiService; | ||
|
||
describe("ListDeviceSessionsUseCase", () => { | ||
beforeEach(() => { | ||
logger = new DefaultLoggerPublisherService( | ||
[], | ||
"list-device-sessions-use-case-test", | ||
); | ||
managerApiDataSource = new AxiosManagerApiDataSource({ | ||
managerApiUrl: "http://fake.url", | ||
}); | ||
managerApi = new DefaultManagerApiService(managerApiDataSource); | ||
sessionService = new DefaultDeviceSessionService(() => logger); | ||
}); | ||
|
||
it("should list all device sessions", () => { | ||
// given | ||
const deviceSession1 = deviceSessionStubBuilder( | ||
{ id: "1" }, | ||
() => logger, | ||
managerApi, | ||
); | ||
const deviceSession2 = deviceSessionStubBuilder( | ||
{ id: "2" }, | ||
() => logger, | ||
managerApi, | ||
); | ||
sessionService.addDeviceSession(deviceSession1); | ||
sessionService.addDeviceSession(deviceSession2); | ||
const useCase = new ListDeviceSessionsUseCase(sessionService, () => logger); | ||
|
||
// when | ||
const response = useCase.execute(); | ||
|
||
// then | ||
expect(response).toStrictEqual([deviceSession1, deviceSession2]); | ||
}); | ||
|
||
it("should return empty array if no device sessions", () => { | ||
// given | ||
const useCase = new ListDeviceSessionsUseCase(sessionService, () => logger); | ||
|
||
// when | ||
const response = useCase.execute(); | ||
|
||
// then | ||
expect(response).toStrictEqual([]); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/core/src/internal/device-session/use-case/ListDeviceSessionsUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { inject, injectable } from "inversify"; | ||
|
||
import { deviceSessionTypes } from "@internal/device-session/di/deviceSessionTypes"; | ||
import { DeviceSession } from "@internal/device-session/model/DeviceSession"; | ||
import type { DeviceSessionService } from "@internal/device-session/service/DeviceSessionService"; | ||
import { loggerTypes } from "@internal/logger-publisher/di/loggerTypes"; | ||
import { LoggerPublisherService } from "@internal/logger-publisher/service/LoggerPublisherService"; | ||
|
||
/** | ||
* List all device sessions. | ||
*/ | ||
@injectable() | ||
export class ListDeviceSessionsUseCase { | ||
private readonly _sessionService: DeviceSessionService; | ||
private readonly _logger: LoggerPublisherService; | ||
|
||
constructor( | ||
@inject(deviceSessionTypes.DeviceSessionService) | ||
sessionService: DeviceSessionService, | ||
@inject(loggerTypes.LoggerPublisherServiceFactory) | ||
loggerFactory: (tag: string) => LoggerPublisherService, | ||
) { | ||
this._sessionService = sessionService; | ||
this._logger = loggerFactory("ListDeviceSessionsUseCase"); | ||
} | ||
|
||
execute(): DeviceSession[] { | ||
this._logger.info("Listing device sessions"); | ||
return this._sessionService.getDeviceSessions(); | ||
} | ||
} |