UNPKG

@tvkitchen/countertop

Version:

The entry point for developers who want to set up a TV Kitchen.

115 lines (109 loc) 4.28 kB
"use strict"; var _kafkajs = require("kafkajs"); var _CountertopStation = _interopRequireDefault(require("../CountertopStation")); var _CountertopTopology = _interopRequireDefault(require("../CountertopTopology")); var _jest = require("../../tools/utils/jest"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } jest.mock('kafkajs'); describe('CountertopStation #unit', () => { describe('constructor', () => { it('Should require an appliance', () => { expect(() => new _CountertopStation.default()).toThrow(); }); it('Should accept a custom logger', () => { const logger = {}; const appliance = (0, _jest.generateMockAppliance)({ inputTypes: [], outputTypes: [] }); const countertopStation = new _CountertopStation.default(appliance, {}, { logger }); expect(countertopStation.logger).toBe(logger); }); }); describe('invokeTopology', () => { it('Should return an empty array when sent an empty toplogy', async () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: [], outputTypes: [] }); const countertopStation = new _CountertopStation.default(appliance); const topology = new _CountertopTopology.default(); const workers = await countertopStation.invokeTopology(topology); expect(workers).toEqual([]); }); it('Should return workers if the station is part of the toplogy', async () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: [], outputTypes: ['bar'] }); const countertopStation = new _CountertopStation.default(appliance, {}, { kafka: new _kafkajs.Kafka() }); const topology = new _CountertopTopology.default([countertopStation]); const workers = await countertopStation.invokeTopology(topology); expect(workers.length).toEqual(1); }); }); describe('start', () => { it('should return true when assigned no streams', async () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: [], outputTypes: [] }); const countertopStation = new _CountertopStation.default(appliance); expect((await countertopStation.start())).toBe(true); }); }); describe('stop', () => { it('should return true when assigned no streams', async () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: [], outputTypes: [] }); const countertopStation = new _CountertopStation.default(appliance); expect((await countertopStation.stop())).toBe(true); }); }); describe('getInputTypes', () => { it('should return the input types of its appliance', () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: ['foo'], outputTypes: ['bar'] }); const countertopStation = new _CountertopStation.default(appliance); expect(countertopStation.getInputTypes()).toEqual(['foo']); }); it('should pass settings to appliance getInputTypes', () => { const appliance = (0, _jest.generateMockAppliance)({ getInputTypes: settings => settings.inputTypes }); const settings = { inputTypes: ['foo'] }; const countertopStation = new _CountertopStation.default(appliance, settings); expect(countertopStation.getInputTypes()).toEqual(['foo']); }); }); describe('getOutputTypes', () => { it('should return the output types of its appliance', () => { const appliance = (0, _jest.generateMockAppliance)({ inputTypes: ['foo'], outputTypes: ['bar'] }); const countertopStation = new _CountertopStation.default(appliance); expect(countertopStation.getOutputTypes()).toEqual(['bar']); }); it('should pass settings to appliance getOutputTypes', () => { const appliance = (0, _jest.generateMockAppliance)({ getOutputTypes: settings => settings.outputTypes }); const settings = { outputTypes: ['bar'] }; const countertopStation = new _CountertopStation.default(appliance, settings); expect(countertopStation.getOutputTypes()).toEqual(['bar']); }); }); });