UNPKG

@ic-wallet-kit/hpl

Version:
123 lines (122 loc) 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mockConstrains_1 = require("../../../__tests_utils/mockConstrains"); const mockLogger_1 = require("../../../__tests_utils/mockLogger"); const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity"); const hplVirtualAccountsStateCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplVirtualAccountsStateCacheDataHandler/hplVirtualAccountsStateCacheDataHandler"); const repositories_1 = require("../../../repositories"); const common_1 = require("@ic-wallet-kit/common"); describe("Unit HplVirtualAccountsStateCacheDataHandler tests", () => { const testData = [ { name: "get accounts state from canister", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(1), remoteAccounts: [], loadType: common_1.LoadType.Full }, data: { cacheData: undefined, service: [ { accountId: BigInt(2), accountState: { ft: BigInt(2), }, time: BigInt(2), virtualAccountId: BigInt(2), } ] }, result: common_1.FormResult.success([ { accountId: BigInt(2), accountState: { ft: BigInt(2), }, time: BigInt(2), virtualAccountId: BigInt(2), } ]) }, { name: "get accounts state from cache", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(1), remoteAccounts: [], loadType: common_1.LoadType.Cache }, data: { cacheData: [{ accountId: BigInt(0), accountState: { ft: BigInt(0), }, time: BigInt(0), virtualAccountId: BigInt(0), }], }, result: common_1.FormResult.success([ { accountId: BigInt(0), accountState: { ft: BigInt(0), }, time: BigInt(0), virtualAccountId: BigInt(0), } ]) }, { name: "get accounts state from cache, cache is empty", input: { accountCount: BigInt(0), ftAssetCount: BigInt(0), virtualAccountCount: BigInt(1), remoteAccounts: [], loadType: common_1.LoadType.Cache }, data: { cacheData: undefined, service: [ { accountId: BigInt(5), accountState: { ft: BigInt(5), }, time: BigInt(5), virtualAccountId: BigInt(5), } ] }, result: common_1.FormResult.success([ { accountId: BigInt(5), accountState: { ft: BigInt(5), }, time: BigInt(5), virtualAccountId: BigInt(5), } ]) } ]; for (let test of testData) { it(test.name, async () => { jest.restoreAllMocks(); const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("testUnitHplVirtual".toLocaleLowerCase()); const cacheRepository = new repositories_1.HplStateCacheRepository(); cacheRepository.getHplVirtualAccountState = jest.fn().mockReturnValue(test.data.cacheData); cacheRepository.setHplVirtualAccountState = jest.fn().mockImplementation(() => { }); const logger = new mockLogger_1.MockLogger(); const hplVirtualAccountsStateCacheDataHandler = new hplVirtualAccountsStateCacheDataHandler_1.HplVirtualAccountsStateCacheDataHandler(logger, identifierService, cacheRepository, mockConstrains_1.mockCanisterService); hplVirtualAccountsStateCacheDataHandler.getExternalData = jest.fn().mockReturnValue(test.data.service); const result = await hplVirtualAccountsStateCacheDataHandler.handle(test.input); expect(result).toEqual(test.result); }, 10000); } });