@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
108 lines (107 loc) • 4.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const mockLogger_1 = require("../../../__tests_utils/mockLogger");
const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity");
const hplVirtualAccountStateCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplVirtualAccountStateCacheDataHandler/hplVirtualAccountStateCacheDataHandler");
const repositories_1 = require("../../../repositories");
const service_1 = require("../../../service");
const common_1 = require("@ic-wallet-kit/common");
describe("Unit HplVirtualAccountStateCacheDataHandler tests", () => {
const testData = [
/* {
name: "get accounts state from canister",
input: {
virtualAccountId: BigInt(0),
force: true
} as HplVirtualAccountStateCacheDataInfo,
data: {
cacheData: undefined,
service: {
accountId: BigInt(0),
accountState: {
ft: BigInt(0),
},
time: BigInt(0),
virtualAccountId: BigInt(0)
}
},
result: FormResult.success(
{
accountId: BigInt(0),
accountState: {
ft: BigInt(0),
},
time: BigInt(0),
virtualAccountId: BigInt(0)
} as HplStateVirtualAccountsCacheModel)
},*/
{
name: "get accounts state from cache",
input: {
virtualAccountId: BigInt(0),
loadType: common_1.LoadType.Cache
},
data: {
service: undefined,
cacheData: [{
accountId: BigInt(44),
accountState: {
ft: BigInt(44),
},
time: BigInt(44),
virtualAccountId: BigInt(44),
}],
},
result: common_1.FormResult.success({
accountId: BigInt(44),
accountState: {
ft: BigInt(44),
},
time: BigInt(44),
virtualAccountId: BigInt(44),
})
},
/*{
name: "get accounts state from cache, cache is empty",
input: {
virtualAccountId: BigInt(0),
force: false
} as HplVirtualAccountStateCacheDataInfo,
data: {
cacheData: undefined,
service: {
accountId: BigInt(0),
accountState: {
ft: BigInt(0),
},
time: BigInt(0),
virtualAccountId: BigInt(0),
}
},
result: FormResult.success(
{
accountId: BigInt(0),
accountState: {
ft: BigInt(0),
},
time: BigInt(0),
virtualAccountId: BigInt(0),
} as HplStateVirtualAccountsCacheModel)
}*/
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = (0, seedToIdentity_1.seedToIdentifierService)("a");
const canisterService = new service_1.CanisterService("rqx66-eyaaa-aaaap-aaona-cai", "lpwlq-2iaaa-aaaap-ab2vq-cai", "n65ik-oqaaa-aaaag-acb4q-cai");
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 hplVirtualAccountStateCacheDataHandler_1.HplVirtualAccountStateCacheDataHandler(logger, identifierService, cacheRepository, canisterService);
hplVirtualAccountsStateCacheDataHandler.getExternalData = jest.fn().mockReturnValue(test.data.service);
const result = await hplVirtualAccountsStateCacheDataHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});