UNPKG

@zondax/ledger-js

Version:

TS / Node API for apps running on Ledger devices

60 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /****************************************************************************** * (c) 2018 - 2024 Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ const common_1 = require("./common"); const consts_1 = require("./consts"); const errors_1 = require("./errors"); const responseError_1 = require("./responseError"); describe('errorCodeToString', () => { it('should return the correct error message for a known error code', () => { const knownErrorCode = 0x9000; const expectedMessage = 'No errors'; expect((0, errors_1.errorCodeToString)(knownErrorCode)).toEqual(expectedMessage); }); it('should return the correct error message for a custom error code', () => { const knownErrorCode = 0xabcd; const expectedMessage = 'test custom error'; expect((0, errors_1.errorCodeToString)(knownErrorCode, { 0xabcd: expectedMessage })).toEqual(expectedMessage); }); it('should return the correct error message for a known error code, when a custom error list is passed', () => { const knownErrorCode = 0x9000; const expectedMessage = 'No errors'; expect((0, errors_1.errorCodeToString)(knownErrorCode, { [knownErrorCode]: 'Custom no errors' })).toEqual(expectedMessage); }); it('should return "Unknown Return Code" for an unknown error code', () => { const unknownErrorCode = 0x9999; const expectedMessage = 'Unknown Return Code: 0x9999'; expect((0, errors_1.errorCodeToString)(unknownErrorCode)).toEqual(expectedMessage); }); }); describe('processErrorResponse', () => { it('should return correct response object when statusCode is present', () => { const response = { statusCode: 0x9000 }; const expectedResponse = new responseError_1.ResponseError(0x9000, 'No errors'); expect((0, common_1.processErrorResponse)(response)).toEqual(expectedResponse); }); it('should return the input as is when returnCode and errorMessage are present', () => { const response = { returnCode: 0x9000, errorMessage: 'Success' }; expect((0, common_1.processErrorResponse)(response)).toEqual(response); }); it('should return a default error response when neither statusCode nor returnCode/errorMessage are present', () => { const response = { someOtherKey: 123 }; const expectedResponse = responseError_1.ResponseError.fromReturnCode(consts_1.LedgerError.UnknownTransportError); expect((0, common_1.processErrorResponse)(response)).toEqual(expectedResponse); }); }); //# sourceMappingURL=common.test.js.map