"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DataModel_1 = require("./DataModel");
const account_1 = require("./account");
const store_1 = require("@ledgerhq/live-wallet/lib/store");
const consts_1 = require("./families/aptos/consts");
const config_1 = require("./config");
jest.mock("./config", () => ({
    getCurrencyConfiguration: jest.fn(),
}));
const opRetentionStategy = (maxDaysOld, keepFirst) => (op, index) => index < keepFirst || Date.now() - op.date.getTime() < 1000 * 60 * 60 * 24 * maxDaysOld;
const schema = {
    migrations: [raw => raw],
    decode: (raw) => [(0, account_1.fromAccountRaw)(raw), (0, store_1.accountRawToAccountUserData)(raw)],
    encode: ([account, userData]) => (0, account_1.toAccountRaw)({
        ...account,
        operations: account.operations.filter(opRetentionStategy(366, 500)),
    }, userData),
};
const cryptoOrgAccount = {
    data: {
        currencyId: "crypto_org",
    },
    version: 1,
};
const aptosAccount = {
    data: {
        currencyId: "aptos",
        freshAddressPath: consts_1.APTOS_NON_HARDENED_DERIVATION_PATH,
    },
    version: 1,
};
const evmAccount = {
    data: {
        currencyId: "ethereum",
        operations: [
            {
                id: "op_evm_001",
            },
            {
                id: "op_evm_002",
                nftOperations: [{ id: "op_evm_nft_001" }],
            },
        ],
    },
    version: 1,
};
describe("DataModel", () => {
    test("createDataModel for crypto.org account", () => {
        const migratedCryptoOrgAccount = (0, DataModel_1.createDataModel)(schema).decode(cryptoOrgAccount);
        expect(migratedCryptoOrgAccount.length).toBeGreaterThan(0);
        const migratedCryptoOrgAccountRaw = migratedCryptoOrgAccount.at(0);
        expect(migratedCryptoOrgAccountRaw.cosmosResources).toBeDefined();
    });
    test("createDataModel for aptos account", () => {
        const migratedAptosAccount = (0, DataModel_1.createDataModel)(schema).decode(aptosAccount);
        expect(migratedAptosAccount.length).toBeGreaterThan(0);
        const migratedAptosAccountRaw = migratedAptosAccount.at(0);
        expect(migratedAptosAccountRaw.freshAddressPath).toEqual(consts_1.APTOS_HARDENED_DERIVATION_PATH);
    });
    describe("test for shownNfts true", () => {
        beforeAll(() => {
            config_1.getCurrencyConfiguration.mockReturnValue({
                showNfts: true,
            });
        });
        test("evm account", () => {
            const data = (0, DataModel_1.createDataModel)(schema).decode(evmAccount);
            const account = data.at(0);
            expect(account.operations).toEqual([
                expect.objectContaining({ id: "op_evm_001" }),
                expect.objectContaining({ id: "op_evm_002" }),
            ]);
        });
    });
    describe("test for shownNfts false", () => {
        beforeAll(() => {
            config_1.getCurrencyConfiguration.mockReturnValue({
                showNfts: false,
            });
        });
        test("evm account", () => {
            const data = (0, DataModel_1.createDataModel)(schema).decode(evmAccount);
            const account = data.at(0);
            expect(account.operations).toEqual([expect.objectContaining({ id: "op_evm_001" })]);
        });
    });
});
//# sourceMappingURL=DataModel.test.js.map