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 483adf1
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/merge_queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
checks:
name: Run health check and unit tests
runs-on: ubuntu-latest
runs-on: ledgerhq-device-sdk
steps:
- uses: actions/checkout@v4

Expand All @@ -25,4 +25,4 @@ jobs:
- name: Tests
id: unit-tests
if: ${{ steps.health-check.conclusion == 'success' }}
run: pnpm test
run: pnpm test -- -- --maxWorkers=50%
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ jobs:
- name: Tests
id: unit-tests
if: ${{ steps.health-check.conclusion == 'success' }}
run: pnpm test:coverage -- --max-warnings=0
run: pnpm test:coverage -- --maxWorkers=50%

- uses: sonarsource/sonarqube-scan-action@v4
if: ${{ steps.unit-tests.conclusion == 'success' && github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.fork == 'false' }}
if: ${{ steps.unit-tests.conclusion == 'success' && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork }}
env:
SONAR_TOKEN: ${{ secrets.PUBLIC_GREEN_SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.PUBLIC_SONAR_HOST_URL }}
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
1 change: 1 addition & 0 deletions packages/device-management-kit/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
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);
});
});
1 change: 1 addition & 0 deletions packages/flipper-plugin-client/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { JestConfigWithTsJest } from "ts-jest";
const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/signer/context-module/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/signer/signer-btc/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/signer/signer-eth/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/signer/signer-solana/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/signer/signer-utils/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
setupFiles: ["<rootDir>/jest.setup.ts"],
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/transport-mock/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { JestConfigWithTsJest } from "ts-jest";
const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
testPathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
modulePathIgnorePatterns: ["<rootDir>/lib/esm", "<rootDir>/lib/cjs"],
collectCoverageFrom: [
"src/**/*.ts",
"!src/**/*.stub.ts",
Expand Down
29 changes: 15 additions & 14 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@
"inputs": ["src/**/*.ts", "index.ts"]
},
"lint": {
"dependsOn": ["build"],
"outputs": []
"dependsOn": ["build"]
},
"lint:fix": {
"dependsOn": ["build"],
"outputs": []
"dependsOn": ["build"]
},
"prettier": {
"dependsOn": ["^prettier"],
"outputs": []
"dependsOn": ["^prettier"]
},
"prettier:fix": {
"dependsOn": ["^prettier:fix"],
"outputs": []
"dependsOn": ["^prettier:fix"]
},
"dev": {
"cache": false,
"persistent": true
},
"test": {
"dependsOn": ["^build"],
"outputs": [],
"inputs": ["src/**/*.ts", "tests/**/*.ts"]
"inputs": ["src/**/*.ts"]
},
"test:coverage": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"],
"inputs": ["src/**/*.ts", "tests/**/*.ts"]
"inputs": ["src/**/*.ts"]
},
"typecheck": {
"dependsOn": ["^build", "^typecheck"],
"outputs": []
"dependsOn": ["^build", "^typecheck"]
},
"@ledgerhq/device-management-kit-sample#typecheck": {
"dependsOn": ["build", "^typecheck"]
},
"@ledgerhq/ledger-dmk-docs#typecheck": {
"dependsOn": ["build", "^typecheck"]
},
"health-check": {
"dependsOn": ["build", "prettier", "lint", "typecheck"]
"dependsOn": ["build", "prettier", "lint", "typecheck"],
"outputs": []
}
}
}

0 comments on commit 483adf1

Please sign in to comment.