@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
50 lines • 2.18 kB
JavaScript
import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
import { getCryptoAssetsStore, setCryptoAssetsStore } from ".";
import { legacyCryptoAssetsStore } from "@ledgerhq/cryptoassets/tokens";
describe("Testing CryptoAssetStore", () => {
it("should return the default methods from cryptoassets libs when feature flag does not exists", () => {
LiveConfig.setConfig({
some_other_feature: {
type: "boolean",
default: true,
},
});
const store = getCryptoAssetsStore();
expect(store.findTokenById).toBe(legacyCryptoAssetsStore.findTokenById);
expect(store.findTokenByAddressInCurrency).toBe(legacyCryptoAssetsStore.findTokenByAddressInCurrency);
});
it("should return the default methods from cryptoassets libs when feature flag is disabled", () => {
LiveConfig.setConfig({
feature_cal_lazy_loading: {
type: "boolean",
default: false,
},
});
const store = getCryptoAssetsStore();
expect(store.findTokenById).toBe(legacyCryptoAssetsStore.findTokenById);
expect(store.findTokenByAddressInCurrency).toBe(legacyCryptoAssetsStore.findTokenByAddressInCurrency);
});
it("should throw an error when no store is set and feature flag is enabled", () => {
LiveConfig.setConfig({
feature_cal_lazy_loading: {
type: "boolean",
default: true,
},
});
expect(() => getCryptoAssetsStore()).toThrow("CryptoAssetsStore is not set. Please call setCryptoAssetsStore first.");
});
it("should throw return the new store when feature flag is enabled", () => {
LiveConfig.setConfig({
feature_cal_lazy_loading: {
type: "boolean",
default: true,
},
});
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const newStore = {};
setCryptoAssetsStore(newStore);
const store = getCryptoAssetsStore();
expect(store).toBe(newStore);
});
});
//# sourceMappingURL=index.test.js.map