UNPKG

@ledgerhq/live-common

Version:
117 lines 5.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); const xrpModule = __importStar(require("@ledgerhq/coin-xrp/api/index")); const stellarModule = __importStar(require("@ledgerhq/coin-stellar/api/index")); const cantonModule = __importStar(require("@ledgerhq/coin-canton/api/index")); const tronModule = __importStar(require("@ledgerhq/coin-tron/api/index")); const evmModule = __importStar(require("@ledgerhq/coin-evm/api/index")); const config = __importStar(require("../../../config")); const networkApi = __importStar(require("./network/network-alpaca")); const cryptoAssets = __importStar(require("@ledgerhq/cryptoassets/currencies")); const mockApiInstance = { mock: "api" }; jest.mock("@ledgerhq/cryptoassets/currencies", () => ({ findCryptoCurrencyById: jest.fn(), })); jest.mock("../../../config", () => ({ getCurrencyConfiguration: jest.fn(), })); jest.mock("@ledgerhq/coin-xrp/api/index", () => ({ createApi: jest.fn(), })); jest.mock("@ledgerhq/coin-stellar/api/index", () => ({ createApi: jest.fn(), })); jest.mock("@ledgerhq/coin-canton/api/index", () => ({ createApi: jest.fn(), })); jest.mock("@ledgerhq/coin-tron/api/index", () => ({ createApi: jest.fn(), })); jest.mock("@ledgerhq/coin-evm/api/index", () => ({ createApi: jest.fn(), })); jest.mock("./network/network-alpaca", () => ({ getNetworkAlpacaApi: jest.fn(), })); describe("getAlpacaApi", () => { beforeEach(() => { jest.clearAllMocks(); // Common mocks cryptoAssets.findCryptoCurrencyById.mockImplementation(id => { switch (id) { case "ripple": return { family: "xrp" }; case "stellar": return { family: "stellar" }; case "canton": return { family: "canton" }; case "tron": return { family: "tron" }; case "ethereum": return { id: "ethereum", family: "evm" }; case "sonic": return { id: "sonic", family: "evm" }; default: return undefined; } }); config.getCurrencyConfiguration.mockReturnValue({ config: true }); // API mocks jest.spyOn(xrpModule, "createApi").mockReturnValue(mockApiInstance); jest.spyOn(stellarModule, "createApi").mockReturnValue(mockApiInstance); jest.spyOn(cantonModule, "createApi").mockReturnValue(mockApiInstance); jest.spyOn(tronModule, "createApi").mockReturnValue(mockApiInstance); jest.spyOn(evmModule, "createApi").mockReturnValue(mockApiInstance); jest.spyOn(networkApi, "getNetworkAlpacaApi").mockReturnValue(mockApiInstance); }); const testCases = [ { network: "xrp", module: xrpModule, label: "XRP", params: [{ config: true }] }, { network: "stellar", module: stellarModule, label: "Stellar", params: [{ config: true }] }, { network: "tron", module: tronModule, label: "Tron", params: [{ config: true }] }, { network: "canton", module: cantonModule, label: "Canton", params: [{ config: true }] }, { network: "ethereum", module: evmModule, label: "Ethereum", params: [{ config: true }, "ethereum"], }, { network: "sonic", module: evmModule, label: "Sonic", params: [{ config: true }, "sonic"] }, ]; testCases.forEach(({ network, module, label, params }) => { it(`should return ${label} API for network "${network}" and kind "local"`, () => { const result = (0, index_1.getAlpacaApi)(network, "local"); expect(result).toEqual(mockApiInstance); expect(module.createApi).toHaveBeenCalledWith(...params); }); }); it("should return network API for kind !== 'local'", () => { const result = (0, index_1.getAlpacaApi)("xrp", "remote"); expect(networkApi.getNetworkAlpacaApi).toHaveBeenCalledWith("xrp"); expect(result).toEqual(mockApiInstance); }); }); //# sourceMappingURL=index.unit.test.js.map