stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
59 lines (58 loc) • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const _1 = require(".");
const conveyor_belts_1 = require("../../../../../../stellar-plus/utils/pipeline/conveyor-belts");
describe('Debug Plugin', () => {
let debugPluginAll;
let debugPluginInfo;
let debugPluginError;
it('initializes with a debug level', () => {
debugPluginAll = new _1.DebugPlugin('all');
debugPluginInfo = new _1.DebugPlugin('info');
debugPluginError = new _1.DebugPlugin('error');
expect(debugPluginAll).toBeDefined();
expect(debugPluginInfo).toBeDefined();
expect(debugPluginError).toBeDefined();
});
describe('after initialization', () => {
let mockedFn;
beforeEach(() => {
jest.clearAllMocks();
mockedFn = jest.fn();
});
it('should log Info for conveyor belts', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
debugPluginInfo.preProcess = mockedFn;
debugPluginInfo.postProcess = mockedFn;
const belt = new conveyor_belts_1.ConveyorBelt({ type: 'Sum', plugins: [debugPluginInfo] });
belt.process = (num) => num + 1;
yield belt.execute(1);
expect(mockedFn).toHaveBeenCalledTimes(2);
}));
it('should log All for conveyor belts', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
debugPluginAll.preProcess = mockedFn;
debugPluginAll.postProcess = mockedFn;
const belt = new conveyor_belts_1.ConveyorBelt({ type: 'Sum', plugins: [debugPluginAll] });
belt.process = (num) => num + 1;
yield belt.execute(1);
expect(mockedFn).toHaveBeenCalledTimes(2);
}));
it('should log Error for conveyor belts when throwing', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
mockedFn.mockImplementationOnce((item) => item);
debugPluginError.processError = mockedFn;
const belt = new conveyor_belts_1.ConveyorBelt({ type: 'Sum', plugins: [debugPluginError] });
belt.process = (num) => {
throw Error('Mocked Error');
};
yield expect(belt.execute(1)).rejects.toThrow();
expect(mockedFn).toHaveBeenCalledTimes(1);
}));
it('should not log Error for conveyor belts when not throwing', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
debugPluginError.processError = mockedFn;
const belt = new conveyor_belts_1.ConveyorBelt({ type: 'Sum', plugins: [debugPluginError] });
belt.process = (num) => num + 1;
yield expect(belt.execute(1)).resolves.toBe(2);
expect(mockedFn).not.toHaveBeenCalled();
}));
});
});