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); }); });
describe('TasmotaHandler - disconnect', () => { const tasmotaHandler = new TasmotaHandler({}, 'service-uuid-random'); tasmotaHandler.mqttService = mqttService; beforeEach(() => { sinon.reset(); }); it('disconnect with unsubscription', () => { tasmotaHandler.disconnect(); assert.calledWith(mqttService.device.unsubscribe, 'stat/+/+'); assert.calledWith(mqttService.device.unsubscribe, 'tele/+/+'); }); });
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('get /api/v1/service/caldav/sync', () => { it('should sync', async () => { caldavService.syncUserCalendars.resolves({}); const caldavController = CaldavController(caldavService); const req = { user: { id: userId, }, }; await caldavController['get /api/v1/service/caldav/sync'].controller(req, res); assert.calledWith(caldavService.syncUserCalendars, userId); }); });
describe('TasmotaHandler - handle new state Color Channel', () => { const tasmotaHandler = new TasmotaHandler(gladys, serviceId); beforeEach(() => { sinon.reset(); }); it('decode RESULT message', () => { tasmotaHandler.handleMqttMessage('stat/tasmota-device-topic/RESULT', '{ "Channel": [100,100,100] }'); const expectedEvent = { device_feature_external_id: `tasmota:tasmota-device-topic:Channel`, state: 16777215, }; assert.calledWith(gladys.event.emit, EVENTS.DEVICE.NEW_STATE, expectedEvent); }); });
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('Light', () => { it('should turnOff the light', async () => { const stateManager = new StateManager(event); const deviceManager = new Device(event, {}, stateManager, service); await deviceManager.lightManager.turnOff(device, deviceFeature); assert.calledWith(testService.device.setValue, device, deviceFeature, 0); }); });
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); }); });
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('Light', () => { it('should turnOn the light', async () => { const stateManager = new StateManager(event); const deviceManager = new Device(event, {}, stateManager, service); await deviceManager.lightManager.turnOn(device, deviceFeature); assert.calledWith(testService.device.setValue, device, deviceFeature, 1); }); });
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('GET /service/philips-hue/scene', () => { it('should get scenes', async () => { const philipsHueController = PhilipsHueControllers(philipsHueLightService); await philipsHueController['get /api/v1/service/philips-hue/scene'].controller({}, res); assert.called(philipsHueLightService.getScenes); }); });
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); }); });
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('TasmotaHandler - handle new state Color speed', () => { const tasmotaHandler = new TasmotaHandler(gladys, serviceId); beforeEach(() => { sinon.reset(); }); it('decode RESULT message', () => { tasmotaHandler.handleMqttMessage('stat/tasmota-device-topic/RESULT', '{ "Speed": 11 }'); const expectedEvent = { device_feature_external_id: `tasmota:tasmota-device-topic:Speed`, state: 11, }; assert.calledWith(gladys.event.emit, EVENTS.DEVICE.NEW_STATE, expectedEvent); }); });