"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const account_1 = require("@ledgerhq/coin-framework/lib/mocks/account");
const index_1 = require("@ledgerhq/live-common/currencies/index");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const getTokensWithFunds_1 = require("./getTokensWithFunds");
const ETH = (0, index_1.getCryptoCurrencyById)("ethereum");
const mockedAccounts = [
    (0, account_1.genAccount)("mocked-account-2", {
        currency: ETH,
    }),
];
describe("getTokensWithFunds", () => {
    it("should return empty array if no accounts", () => {
        const result = (0, getTokensWithFunds_1.getTokensWithFunds)([]);
        expect(result).toEqual([]);
    });
    it("should return array with accounts with funds", () => {
        const account = mockedAccounts[0];
        const result = (0, getTokensWithFunds_1.getTokensWithFunds)(mockedAccounts);
        expect(account.balance).toBeTruthy();
        expect(account.balance instanceof bignumber_js_1.default).toBe(true);
        expect(account.balance.gt(0)).toBe(true);
        expect(account.subAccounts).toBeDefined();
        expect(account.subAccounts?.length).toBe(2);
        const [zrxAccount, repAccount] = account.subAccounts || [];
        expect(zrxAccount.balance).toBeTruthy();
        expect(zrxAccount.balance instanceof bignumber_js_1.default).toBe(true);
        expect(zrxAccount.balance.gt(0)).toBe(true);
        expect(repAccount.balance).toBeTruthy();
        expect(repAccount.balance instanceof bignumber_js_1.default).toBe(true);
        expect(repAccount.balance.gt(0)).toBe(true);
        expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
    });
    it("should return array with accounts with funds", () => {
        const account = mockedAccounts[0];
        expect(account.balance).toBeTruthy();
        expect(account.balance instanceof bignumber_js_1.default).toBe(true);
        expect(account.balance.gt(0)).toBe(true);
        expect(account.subAccounts).toBeDefined();
        expect(account.subAccounts?.length).toBe(2);
        const [zrxAccount, repAccount] = account.subAccounts || [];
        const emptyRepAccount = { ...repAccount, balance: new bignumber_js_1.default(0) };
        expect(zrxAccount.balance).toBeTruthy();
        expect(zrxAccount.balance instanceof bignumber_js_1.default).toBe(true);
        expect(zrxAccount.balance.gt(0)).toBe(true);
        expect(emptyRepAccount.balance).toBeTruthy();
        expect(emptyRepAccount.balance instanceof bignumber_js_1.default).toBe(true);
        expect(emptyRepAccount.balance.gt(0)).toBe(false);
        const accounts = { ...account, subAccounts: [zrxAccount, emptyRepAccount] };
        const result = (0, getTokensWithFunds_1.getTokensWithFunds)([accounts]);
        expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum"]);
    });
    it("should return array with accounts with funds without duplication", () => {
        const account = mockedAccounts[0];
        expect(account.balance).toBeTruthy();
        expect(account.balance instanceof bignumber_js_1.default).toBe(true);
        expect(account.balance.gt(0)).toBe(true);
        expect(account.subAccounts).toBeDefined();
        expect(account.subAccounts?.length).toBe(2);
        const [zrxAccount, repAccount] = account.subAccounts || [];
        const accounts = { ...account, subAccounts: [zrxAccount, repAccount, repAccount] };
        expect(accounts.subAccounts.length).toBe(3);
        const result = (0, getTokensWithFunds_1.getTokensWithFunds)([accounts]);
        expect(result).toEqual(["ETH on Ethereum", "ZRX on Ethereum", "REP on Ethereum"]);
    });
});
//# sourceMappingURL=getTokensWithFunds.test.js.map