UNPKG

@ic-wallet-kit/hpl

Version:
73 lines (72 loc) 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mockLogger_1 = require("../../../__tests_utils/mockLogger"); const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity"); const hplMintCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplMintCacheDataHandler/hplMintCacheDataHandler"); const repositories_1 = require("../../../repositories"); const common_1 = require("@ic-wallet-kit/common"); describe("Unit HplAccountCacheDataHandler tests", () => { const testData = [ { name: "get accounts from canister", input: { canisterId: "gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe", loadType: common_1.LoadType.Full }, data: { cacheData: undefined, }, result: common_1.FormResult.success({ canisterId: "gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe", isMinter: false }) }, { name: "get accounts from cache", input: { canisterId: "lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe", loadType: common_1.LoadType.Cache }, data: { cacheData: { canisterId: "lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe", isMinter: false } }, result: common_1.FormResult.success({ canisterId: "lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe", isMinter: false }) }, { name: "get accounts from cache, cache is empty", input: { canisterId: "gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe", loadType: common_1.LoadType.Cache }, data: { cacheData: undefined, }, result: common_1.FormResult.success({ canisterId: "gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe", isMinter: false }) } ]; for (let test of testData) { it(test.name, async () => { jest.restoreAllMocks(); const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("b"); const cacheRepository = new repositories_1.HplMintCacheRepository(); cacheRepository.getHplMintByCanisterId = jest.fn().mockReturnValue(test.data.cacheData); cacheRepository.setHplMint = jest.fn().mockReturnValue(undefined); const logger = new mockLogger_1.MockLogger(); const mintStartTime = performance.now(); const hplMintCacheDataHandler = new hplMintCacheDataHandler_1.HplMintCacheDataHandler(logger, identifierService, cacheRepository); const result = await hplMintCacheDataHandler.handle(test.input); const mintEndTime = performance.now(); console.log(`${test.name} Call to getExternalData took ${(mintEndTime - mintStartTime) / 1000} seconds`); expect(result).toEqual(test.result); }, 100000); } });