UNPKG

@ledgerhq/live-common

Version:
79 lines 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const hw_transport_mocker_1 = require("@ledgerhq/hw-transport-mocker"); const toggleOnboardingEarlyCheck_1 = require("./toggleOnboardingEarlyCheck"); const errors_1 = require("@ledgerhq/errors"); describe("@deviceSDK/commands/toggleOnboardingEarlyCheckCmd", () => { describe("When the device is neither in the WELCOME and WELCOME_STEP2 onboarding state, and it returns 0x6982", () => { it("should throw an error", done => { const transport = new hw_transport_mocker_1.MockTransport(Buffer.from([0x69, 0x82])); (0, toggleOnboardingEarlyCheck_1.toggleOnboardingEarlyCheckCmd)({ transport, p2: toggleOnboardingEarlyCheck_1.ToggleTypeP2.EnterChecking, }).subscribe({ next: _ => { done("An error should have been thrown"); }, error: (error) => { try { if (error instanceof errors_1.TransportStatusError) { expect(error.statusCode).toBe(errors_1.StatusCodes.SECURITY_STATUS_NOT_SATISFIED); done(); } else { done("An incorrect error has been received"); } } catch (expectError) { done(expectError); } }, }); }); }); describe("When the sent APDU is not respected the expected format, and it returns 0x6700", () => { it("should throw an error", done => { const transport = new hw_transport_mocker_1.MockTransport(Buffer.from([0x67, 0x00])); (0, toggleOnboardingEarlyCheck_1.toggleOnboardingEarlyCheckCmd)({ transport, p2: toggleOnboardingEarlyCheck_1.ToggleTypeP2.EnterChecking, }).subscribe({ next: _ => { done("An error should have been thrown"); }, error: (error) => { try { if (error instanceof errors_1.TransportStatusError) { expect(error.statusCode).toBe(errors_1.StatusCodes.INCORRECT_LENGTH); done(); } else { done("An incorrect error has been received"); } } catch (expectError) { done(expectError); } }, }); }); }); describe("When the device is in the expected onboarding state", () => { it("should be able to enter or exit the onboarding early checks step successfully", done => { const transport = new hw_transport_mocker_1.MockTransport(Buffer.from([0x90, 0x00])); // enter and exit have the same behavior (0, toggleOnboardingEarlyCheck_1.toggleOnboardingEarlyCheckCmd)({ transport, p2: toggleOnboardingEarlyCheck_1.ToggleTypeP2.EnterChecking, }).subscribe({ next: _ => { done(); }, error: (error) => { done(`No error should have been thrown: ${error}`); }, }); }); }); }); //# sourceMappingURL=toggleOnboardingEarlyCheck.test.js.map