@tvkitchen/countertop
Version:
The entry point for developers who want to set up a TV Kitchen.
93 lines (86 loc) • 3.37 kB
JavaScript
;
var _constants = require("../../constants");
var _Countertop = _interopRequireDefault(require("../Countertop"));
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('Countertop #unit', () => {
describe('constructor', () => {
it('Should accept a custom logger', () => {
const logger = {};
const countertop = new _Countertop.default({
logger
});
expect(countertop.logger).toBe(logger);
});
});
describe('addAppliance', () => {
it('Should generate a station for the new appliance', () => {
const countertop = new _Countertop.default();
const appliance = (0, _jest.generateMockAppliance)({
inputTypes: [],
outputTypes: []
});
expect(countertop.addAppliance(appliance)).toBeInstanceOf(_CountertopStation.default);
});
});
describe('start', () => {
it('should return true when run with no appliances', async () => {
const countertop = new _Countertop.default();
expect((await countertop.start())).toBe(true);
});
it('should return false when a station does not start', async () => {
const station = {
start: async () => false
};
const countertop = new _Countertop.default();
countertop.stations = [station];
expect((await countertop.start())).toBe(false);
});
it('should update state to ERRORED when a station does not start', async () => {
const station = {
start: async () => false
};
const countertop = new _Countertop.default();
countertop.stations = [station];
await countertop.start();
expect(countertop.state).toBe(_constants.countertopStates.ERRORED);
});
});
describe('stop', () => {
it('should return true when run with no appliances', async () => {
const countertop = new _Countertop.default();
expect((await countertop.stop())).toBe(true);
});
it('should return false when a station does not stop', async () => {
const station = {
stop: async () => false
};
const countertop = new _Countertop.default();
countertop.stations = [station];
expect((await countertop.stop())).toBe(false);
});
it('should update state to ERRORED when a station does not stop', async () => {
const station = {
stop: async () => false
};
const countertop = new _Countertop.default();
countertop.stations = [station];
await countertop.stop();
expect(countertop.state).toBe(_constants.countertopStates.ERRORED);
});
});
describe('updateTopology', () => {
it('should return a CountertopTopology when run with no appliances', () => {
const countertop = new _Countertop.default();
expect(countertop.updateTopology()).toBeInstanceOf(_CountertopTopology.default);
});
it('should error when run on a started countertop', () => {
const countertop = new _Countertop.default();
countertop.state = _constants.countertopStates.STARTED;
expect(() => countertop.updateTopology()).toThrow();
});
});
});