@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
52 lines • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
const live_env_1 = require("@ledgerhq/live-env");
describe("swap/index", () => {
describe("isSwapOperationPending", () => {
test("should return false for ok status", () => {
const result = (0, _1.isSwapOperationPending)("finished");
expect(result).toBe(false);
});
test("should return false for ko status", () => {
const result = (0, _1.isSwapOperationPending)("refunded");
expect(result).toBe(false);
});
test("should return true for other status", () => {
const result = (0, _1.isSwapOperationPending)("RANDOM_STATUS");
expect(result).toBe(true);
});
test("should return true if not status provided", () => {
/**
* Since this TS function can be used in loosly typed JS code, we need
* to test the case of the parameter not being provided
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = (0, _1.isSwapOperationPending)();
expect(result).toBe(true);
});
});
describe("getSwapAPIVersion", () => {
const DEFAULT_SWAP_API_BASE = (0, live_env_1.getEnv)("SWAP_API_BASE");
afterEach(() => {
// Restore DEFAULT_SWAP_API_BASE
(0, live_env_1.setEnv)("SWAP_API_BASE", DEFAULT_SWAP_API_BASE);
});
test("should return version when SWAP_API_BASE contains one", () => {
const result = (0, _1.getSwapAPIVersion)();
expect(result).toBe(5);
});
test("should throw an error if no version in SWAP_API_BASE", () => {
(0, live_env_1.setEnv)("SWAP_API_BASE", "https://swap.ledger.com");
expect(_1.getSwapAPIVersion).toThrow(Error);
expect(_1.getSwapAPIVersion).toThrow("Configured swap API base URL is invalid, should end with /v<number>");
});
test("should throw an error if version is NaN", () => {
(0, live_env_1.setEnv)("SWAP_API_BASE", "https://swap.ledger.com/vtest");
expect(_1.getSwapAPIVersion).toThrow(Error);
expect(_1.getSwapAPIVersion).toThrow("Configured swap API base URL is invalid, should end with /v<number>");
});
});
});
//# sourceMappingURL=index.test.js.map