@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
44 lines • 2.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const network_1 = __importDefault(require("@ledgerhq/live-network/network"));
const fetchCurrencyTo_1 = require("../fetchCurrencyTo");
const fetchCurrencyTo_mocks_1 = require("../__mocks__/fetchCurrencyTo.mocks");
const timeout_1 = require("../../../const/timeout");
const errors_1 = require("@ledgerhq/errors");
const flattenV5CurrenciesToAndFrom_1 = require("../../../utils/flattenV5CurrenciesToAndFrom");
jest.mock("@ledgerhq/live-network/network");
const mockNetwork = network_1.default;
const providers = ["changelly", "cic", "moonpay", "oneinch", "paraswap"];
describe("fetchCurrencyFrom", () => {
it("success with 200", async () => {
mockNetwork.mockReturnValueOnce({
data: fetchCurrencyTo_mocks_1.fetchCurrencyToMock,
});
const result = await (0, fetchCurrencyTo_1.fetchCurrencyTo)({
currencyFromId: "bitcoin",
providers,
});
expect(result).toStrictEqual((0, flattenV5CurrenciesToAndFrom_1.flattenV5CurrenciesToAndFrom)(fetchCurrencyTo_mocks_1.fetchCurrencyToMock));
expect(mockNetwork).toHaveBeenCalledWith({
method: "GET",
timeout: timeout_1.DEFAULT_SWAP_TIMEOUT_MS,
url: "https://swap.ledger.com/v5/currencies/to?providers-whitelist=changelly%2Ccic%2Cmoonpay%2Coneinch%2Cparaswap&additional-coins-flag=false¤cy-from=bitcoin",
});
});
it("fails with 400", async () => {
mockNetwork.mockRejectedValueOnce(new errors_1.LedgerAPI4xx());
try {
await (0, fetchCurrencyTo_1.fetchCurrencyTo)({
currencyFromId: "bitcoin",
providers,
});
}
catch (e) {
expect(e).toBeInstanceOf(errors_1.LedgerAPI4xx);
}
});
});
//# sourceMappingURL=fetchCurrencyTo.spec.js.map