test-ic-wallet-middleware-icrc
Version:
Ic middleware wallet ICRC protocol
90 lines (89 loc) • 3.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const agent_1 = require("@dfinity/agent");
const principal_1 = require("@dfinity/principal");
const common_1 = require("@ic-wallet-middleware/common");
const mockLogger_1 = require("../../../../__tests_utils/mockLogger");
const serviceAssetDetailsHandler_1 = require("../../../../internalHandlers/icrcCacheDataHandlers/services/serviceAssetDetailsHandler/serviceAssetDetailsHandler");
const serviceLocalCache_1 = require("../../../../repositories/cache/serviceLocalCache/serviceLocalCache");
describe("Unit ServiceAssetDetailsHandler tests", () => {
const testData = [
{
name: "get AssetDetails from canister",
input: {
servicePrincipal: "pmr6h-yaaaa-aaaao-a3myq-cai",
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
loadType: common_1.LoadType.Full
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success({
assetDetail: {
allowanceFee: BigInt(10000),
withdrawalFee: BigInt(10000),
depositFee: BigInt(10000),
}
})
},
{
name: "get AssetDetails from cache",
input: {
servicePrincipal: "pmr6h-yaaaa-aaaao-a3myq-cai",
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
loadType: common_1.LoadType.Cache
},
data: {
cacheData: {
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
deposit: BigInt(0),
assetDetail: {
allowanceFee: BigInt(0),
withdrawalFee: BigInt(0),
depositFee: BigInt(0),
}
},
},
result: common_1.FormResult.success({
assetDetail: {
allowanceFee: BigInt(0),
withdrawalFee: BigInt(0),
depositFee: BigInt(0),
}
})
},
{
name: "get AssetDetails from cache, cache is empty",
input: {
servicePrincipal: "pmr6h-yaaaa-aaaao-a3myq-cai",
ledgerAddress: "ryjl3-tyaaa-aaaaa-aaaba-cai",
loadType: common_1.LoadType.Cache
},
data: {
cacheData: undefined,
},
result: common_1.FormResult.success({
assetDetail: {
allowanceFee: BigInt(10000),
withdrawalFee: BigInt(10000),
depositFee: BigInt(10000),
}
})
}
];
for (let test of testData) {
it(test.name, async () => {
jest.restoreAllMocks();
const identifierService = new common_1.IdentifierService();
const cacheRepository = new serviceLocalCache_1.ServiceLocalCache();
cacheRepository.getServiceAsset = jest.fn().mockReturnValue(test.data.cacheData);
cacheRepository.setServiceAsset = jest.fn().mockReturnValue(undefined);
identifierService.getAgent = jest.fn().mockReturnValue(new agent_1.HttpAgent());
identifierService.getPrincipal = jest.fn().mockReturnValue(principal_1.Principal.fromText("gjcgk-x4xlt-6dzvd-q3mrr-pvgj5-5bjoe-beege-n4b7d-7hna5-pa5uq-5qe"));
const logger = new mockLogger_1.MockLogger();
const serviceAssetDepositHandler = new serviceAssetDetailsHandler_1.ServiceAssetDetailsHandler(logger, identifierService, cacheRepository);
const result = await serviceAssetDepositHandler.handle(test.input);
expect(result).toEqual(test.result);
}, 10000);
}
});