diff --git a/libs/ledger-live-common/src/mock/fixtures/nfts.test.ts b/libs/ledger-live-common/src/mock/fixtures/nfts.test.ts new file mode 100644 index 00000000000..1fbeff3d47f --- /dev/null +++ b/libs/ledger-live-common/src/mock/fixtures/nfts.test.ts @@ -0,0 +1,25 @@ +import { getCryptoCurrencyById } from "../../currencies"; +import { createFixtureNFT, NFTs, NFTs_POLYGON } from "./nfts"; + +const POL = getCryptoCurrencyById("polygon"); +describe("nfts fixtures", () => { + it("createFixtureNFT", () => { + const FIXTURE = createFixtureNFT("account-mock"); + expect(FIXTURE.currencyId).toEqual("ethereum"); + expect(FIXTURE.amount).not.toBeUndefined(); + expect(FIXTURE.contract).not.toBeUndefined(); + expect(FIXTURE.tokenId).not.toBeUndefined(); + expect(FIXTURE.id).toContain("account-mock"); + + expect( + NFTs.map((nft) => nft.tokenId).includes(FIXTURE.tokenId) + ).toBeTruthy(); + + const FIXTURE_POL = createFixtureNFT("account-mock-pol", POL); + expect(FIXTURE_POL.currencyId).toEqual("polygon"); + + expect( + NFTs_POLYGON.map((nft) => nft.tokenId).includes(FIXTURE_POL.tokenId) + ).toBeTruthy(); + }); +}); diff --git a/libs/ledger-live-common/src/mock/fixtures/nfts.ts b/libs/ledger-live-common/src/mock/fixtures/nfts.ts index 0a01f7f7b58..704d6d2e046 100644 --- a/libs/ledger-live-common/src/mock/fixtures/nfts.ts +++ b/libs/ledger-live-common/src/mock/fixtures/nfts.ts @@ -15,7 +15,7 @@ import { encodeNftId } from "../../nft"; const defaultEthCryptoFamily = cryptocurrenciesById["ethereum"]; -const NFTs = [ +export const NFTs = [ { id: "js:2:ethereum:0xB98d10d9f6d07bA283bFD21B2dFEc050f9Ae282A:+0xb1540922Be7c7Ed011cb41cc0Cc4adDf089b3AaF+7833", tokenId: "7833", @@ -307,7 +307,7 @@ const NFTs = [ }, ]; -const NFTs_POLYGON = [ +export const NFTs_POLYGON = [ { id: "js:2:ethereum:0xB98d10d9f6d07bA283bFD21B2dFEc050f9Ae282A:+0x68a0B29526f342de944BBd6bF61D9c644B96b771+7", tokenId: "7", diff --git a/libs/ledger-live-common/src/nft/helpers.test.ts b/libs/ledger-live-common/src/nft/helpers.test.ts index 8a81d2fb4d2..ee0886ba13c 100644 --- a/libs/ledger-live-common/src/nft/helpers.test.ts +++ b/libs/ledger-live-common/src/nft/helpers.test.ts @@ -1,10 +1,13 @@ -import { NFTStandard } from "@ledgerhq/types-live"; +import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets"; +import { Account, NFTStandard, ProtoNFT } from "@ledgerhq/types-live"; import BigNumber from "bignumber.js"; +import { genAccount } from "../mock/account"; import { getNFTByTokenId, getNftCollectionKey, getNftKey, groupByCurrency, + orderByLastReceived, } from "./helpers"; import { encodeNftId } from "./nftId"; @@ -52,6 +55,13 @@ const NFT_4 = { }; const NFTs = [NFT_1, NFT_2, NFT_3, NFT_4]; +const ETH = getCryptoCurrencyById("ethereum"); + +const accounts: Account[] = [ + genAccount("mocked-account-1", { currency: ETH, withNft: true }), + genAccount("mocked-account-2", { currency: ETH, withNft: true }), +]; + describe("helpers", () => { it("getNftKey", () => { expect(getNftKey("contract", "tokenId", "currencyId")).toEqual( @@ -70,4 +80,12 @@ describe("helpers", () => { it("groupByCurrency", () => { expect(groupByCurrency(NFTs)).toEqual([NFT_1, NFT_4, NFT_2, NFT_3]); }); + + it("orderByLastReceived", () => { + expect(orderByLastReceived(accounts, NFTs)).toHaveLength(0); + const NFTs_TEST = accounts.map((a) => a.nfts).flat() as ProtoNFT[]; + expect( + orderByLastReceived(accounts, NFTs.concat(NFTs_TEST)).length + ).toBeGreaterThanOrEqual(1); + }); });