@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
80 lines (79 loc) • 3.42 kB
JavaScript
;
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 hplAccountsStateCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplAccountsStateCacheDataHandler/hplAccountsStateCacheDataHandler");
const repositories_1 = require("../../../repositories");
const common_1 = require("@ic-wallet-kit/common");
describe("Unit HplAccountsStateCacheDataHandler tests", () => {
const testData = [
{
name: "get accounts state from canister",
input: {
accountCount: BigInt(0),
ftAssetCount: BigInt(0),
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success([])
},
{
name: "get accounts state from cache",
input: {
accountCount: BigInt(0),
ftAssetCount: BigInt(0),
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: common_1.LoadType.Cache
},
data: {
cacheData: [{
accountId: BigInt(0),
accountState: {
ft: BigInt(2),
},
}],
},
result: common_1.FormResult.success([{
accountId: BigInt(0),
accountState: {
ft: BigInt(2),
},
}])
},
{
name: "get accounts state from cache, cache is empty",
input: {
accountCount: BigInt(0),
ftAssetCount: BigInt(0),
virtualAccountCount: BigInt(0),
remoteAccounts: [],
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success([])
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("supperTest32412");
const logger = new mockLogger_1.MockLogger();
const cacheRepository = new repositories_1.HplStateCacheRepository();
//const cacheRepository = new HplStateCacheRepository(logger, identifierService, new {});
cacheRepository["identifierService"] = identifierService;
cacheRepository.getHplAccountState = jest.fn().mockReturnValue(test.data.cacheData);
cacheRepository.setHplAccountState = jest.fn().mockImplementation(() => { });
const hplAccountCacheDataHandler = new hplAccountsStateCacheDataHandler_1.HplAccountsStateCacheDataHandler(logger, identifierService, cacheRepository, mockConstrains_1.mockCanisterService);
const result = await hplAccountCacheDataHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});