@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
68 lines (67 loc) • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const principal_1 = require("@dfinity/principal");
const mockConstrains_1 = require("../../../__tests_utils/mockConstrains");
const mockLogger_1 = require("../../../__tests_utils/mockLogger");
const seedToIdentity_1 = require("../../../__tests_utils/seedToIdentity");
const hplOwnerCacheDataHandler_1 = require("../../../internalHandlers/cacheDataHandlers/hplOwnerCacheDataHandler/hplOwnerCacheDataHandler");
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: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success({
ownerId: BigInt(42)
})
},
{
name: "get accounts from cache",
input: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Cache
},
data: {
cacheData: {
ownerId: BigInt(0)
}
},
result: common_1.FormResult.success({
ownerId: BigInt(0)
})
},
{
name: "get accounts from cache, cache is empty",
input: {
principal: principal_1.Principal.fromText("lprj7-waklu-335mt-2nt4k-2gpby-emi7t-h6d5h-d2mgk-3xyes-2o7nj-4qe"),
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success({
ownerId: BigInt(42)
})
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = await (0, seedToIdentity_1.phraseToIdentifierService)("hair guilt comic still lesson helmet glare material avocado venue giggle essence");
const cacheRepository = new repositories_1.HplOwnerCacheRepository();
cacheRepository.getHplOwnerByCanisterId = jest.fn().mockReturnValue(test.data.cacheData);
cacheRepository.setHplOwner = jest.fn().mockReturnValue(undefined);
const logger = new mockLogger_1.MockLogger();
const hplOwnerCacheDataHandler = new hplOwnerCacheDataHandler_1.HplOwnerCacheDataHandler(logger, identifierService, cacheRepository, mockConstrains_1.mockCanisterService);
const result = await hplOwnerCacheDataHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});