describe('get /api/v1/service/caldav/cleanup', () => { it('should cleanup caldav data', async () => { const caldavController = CaldavController(caldavService); const req = { user: { id: userId, }, }; await caldavController['get /api/v1/service/caldav/cleanup'].controller(req, res); assert.calledWith(caldavService.cleanUp, userId); }); });
test('.build() checks if already built, and returns early if true', () => { const mockContext = { built: true, initExtensions: sinon.spy(), }; WebGLKernel.prototype.build.apply(mockContext); assert.equal(mockContext.initExtensions.callCount, 0); });
beforeEach(done => { const tailor = createTailorInstance({ pipeDefinition: () => Buffer.from('') }); mockContext.returns(Promise.resolve({})); server = http.createServer(tailor.requestHandler); server.listen(8080, 'localhost', done); });
Object.assign(event, { disconnected: true, subscribe: fake.resolves(null), unsubscribe: fake.resolves(null), publish: fake.yieldsAsync(null), internalEnd: fake.resolves(null), end: () => { mqttApi.disconnected = true; mqttApi.internalEnd(); }, })
describe('corsMiddleware', () => { it('should send response directly', async () => { const req = new MockExpressRequest({ method: 'OPTIONS', }); corsMiddleware(req, res, () => { throw new Error('next should not be calld'); }); assert.called(res.header); assert.calledOnce(res.send); }); });
describe('gateway.getLatestGladysVersion', () => { it('should return gladys version', async () => { const variable = { getValue: fake.resolves('key'), setValue: fake.resolves(null), }; const gateway = new Gateway(variable, event, system, sequelize, config); const version = await gateway.getLatestGladysVersion(); expect(version).to.have.property('name'); expect(version).to.have.property('created_at'); }); });
describe('GET /service/philips-hue/bridge', () => { it('should get bridges', async () => { const philipsHueController = PhilipsHueControllers(philipsHueLightService); await philipsHueController['get /api/v1/service/philips-hue/bridge'].controller({}, res); assert.calledOnce(philipsHueLightService.getBridges); }); });
describe('GET /service/philips-hue/light', () => { it('should get lights', async () => { const philipsHueController = PhilipsHueControllers(philipsHueLightService); await philipsHueController['get /api/v1/service/philips-hue/light'].controller({}, res); assert.called(philipsHueLightService.getLights); }); });
test('.build() checks if already built, and returns early if true', () => { const mockContext = { built: true, setupConstants: sinon.spy(), }; CPUKernel.prototype.build.apply(mockContext); assert.equal(mockContext.setupConstants.callCount, 0); });
describe('GET /api/v1/service/xiaomi/sensor', () => { it('should get sensors', async () => { const xiaomiController = XiaomiController({ getSensors }); const req = {}; await xiaomiController['get /api/v1/service/xiaomi/sensor'].controller(req, res); assert.calledOnce(getSensors); }); });
describe('get /api/v1/service/caldav/config', () => { it('should return new config', async () => { const caldavController = CaldavController(caldavService); const req = { user: { id: userId, }, }; await caldavController['get /api/v1/service/caldav/config'].controller(req, res); assert.calledWith(caldavService.config, userId); }); });
describe('POST /service/philips-hue/bridge/configure', () => { it('should configure bridge', async () => { const philipsHueController = PhilipsHueControllers(philipsHueLightService); const req = { body: { serial: '12345', }, }; await philipsHueController['post /api/v1/service/philips-hue/bridge/configure'].controller(req, res); assert.calledWith(philipsHueLightService.configureBridge, '12345'); }); });
describe('GET /api/v1/service/usb/port', () => { it('should configure bridge', async () => { const usbController = UsbController({ list }); const req = {}; await usbController['get /api/v1/service/usb/port'].controller(req, res); assert.calledOnce(list); }); });