Skip to content

Commit

Permalink
✅ Add some tests (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger authored Nov 9, 2022
1 parent 0720607 commit a2fa688
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
25 changes: 25 additions & 0 deletions libs/ledger-live-common/src/mock/fixtures/nfts.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
4 changes: 2 additions & 2 deletions libs/ledger-live-common/src/mock/fixtures/nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -307,7 +307,7 @@ const NFTs = [
},
];

const NFTs_POLYGON = [
export const NFTs_POLYGON = [
{
id: "js:2:ethereum:0xB98d10d9f6d07bA283bFD21B2dFEc050f9Ae282A:+0x68a0B29526f342de944BBd6bF61D9c644B96b771+7",
tokenId: "7",
Expand Down
20 changes: 19 additions & 1 deletion libs/ledger-live-common/src/nft/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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(
Expand All @@ -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);
});
});

0 comments on commit a2fa688

Please sign in to comment.