Skip to content

Commit

Permalink
💚 (dmk): Fix missing ConnectUseCase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Nov 15, 2024
1 parent 3e4f9d2 commit abbdedf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"license": "Apache-2.0",
"scripts": {
"clean": "rimraf -g **/.turbo **/.next **/coverage",
"build": "turbo run build",
"build:libs": "turbo run build --filter=./packages/**",
"dev": "turbo run dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,63 +38,58 @@ describe("DefaultDeviceSessionService", () => {
);
});

afterEach(() => {
deviceSession.close();
});

it("should have an empty sessions list", () => {
expect(sessionService.getDeviceSessions()).toEqual([]);
deviceSession.close();
});

it("should add a deviceSession", () => {
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);
});

it("should not add a deviceSession if it already exists", () => {
sessionService.addDeviceSession(deviceSession);
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);
});

it("should remove a deviceSession", () => {
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
sessionService.removeDeviceSession(deviceSession.id);
expect(sessionService.getDeviceSessions()).toEqual([]);
});

it("should not remove a deviceSession if it does not exist", () => {
deviceSession.close();
sessionService.removeDeviceSession(deviceSession.id);
expect(sessionService.getDeviceSessions()).toEqual([]);
});

it("should get a deviceSession", () => {
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
expect(sessionService.getDeviceSessionById(deviceSession.id)).toEqual(
Either.of(deviceSession),
);
});

it("should not get a deviceSession if it does not exist", () => {
deviceSession.close();
expect(sessionService.getDeviceSessionById(deviceSession.id)).toEqual(
Left(new DeviceSessionNotFound()),
);
});

it("should get all sessions", () => {
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
expect(sessionService.getDeviceSessions()).toEqual([deviceSession]);
});

it("should retrieve sessionObs", () => {
expect(sessionService.sessionsObs).toBeInstanceOf(
Observable<DeviceSession>,
);
deviceSession.close();
});

it("should emit new session", (done) => {
Expand All @@ -106,7 +101,6 @@ describe("DefaultDeviceSessionService", () => {
},
});
sessionService.addDeviceSession(deviceSession);
deviceSession.close();
});

it("should emit previous added session", () => {
Expand All @@ -124,7 +118,6 @@ describe("DefaultDeviceSessionService", () => {
emittedSessions.push(emittedDeviceSession);
},
});
deviceSession.close();
lastDeviceSession.close();
expect(emittedSessions).toEqual([deviceSession, lastDeviceSession]);
subscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ describe("ConnectUseCase", () => {
managerApi = new DefaultManagerApiService(managerApiDataSource);
});

afterEach(() => {
for (const session of sessionService.getDeviceSessions()) {
sessionService.removeDeviceSession(session.id);
}
});

afterAll(() => {
jest.restoreAllMocks();
});
Expand Down Expand Up @@ -94,5 +100,6 @@ describe("ConnectUseCase", () => {
device: stubDiscoveredDevice,
});
expect(sessionId).toBe(fakeSessionId);
sessionService.removeDeviceSession(sessionId);
});
});
9 changes: 9 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://turborepo.org/schema.json",
"globalDependencies": ["turbo.json"],
"ui": "tui",
"tasks": {
"build": {
Expand Down Expand Up @@ -41,6 +42,14 @@
"dependsOn": ["^build", "^typecheck"],
"outputs": []
},
"@ledgerhq/device-management-kit-sample#typecheck": {
"dependsOn": ["build", "^typecheck"],
"outputs": []
},
"@ledgerhq/ledger-dmk-docs#typecheck": {
"dependsOn": ["build", "^typecheck"],
"outputs": []
},
"health-check": {
"dependsOn": ["build", "prettier", "lint", "typecheck"]
}
Expand Down

0 comments on commit abbdedf

Please sign in to comment.