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 - 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 /api/v1/service/tasmota/discover', () => { let controller; beforeEach(() => { controller = TasmotaController(tasmotaHandler); }); it('Discover', () => { const res = { json: fake.returns(null), }; controller['get /api/v1/service/tasmota/discover'].controller(undefined, res); assert.calledOnce(tasmotaHandler.getDiscoveredDevices); assert.calledWith(res.json, discoveredDevices); }); });
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('Mqtt handle message', () => { const mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); beforeEach(async () => { sinon.reset(); }); it('should not publish, as not connected', () => { mqttHandler.publish('UNKNOWN_TOPIC', '{}'); assert.notCalled(mqttApi.publish); }); it('should publish message', async () => { await mqttHandler.connect({ mqttUrl: 'url' }); mqttHandler.publish('UNKNOWN_TOPIC', '{}'); assert.calledWith(mqttApi.publish, 'UNKNOWN_TOPIC', '{}', undefined, sinon.match.func); }); });
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 - 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('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('POST /api/v1/service/rtsp-camera/camera/test', () => { it('should return an image', async () => { const device = { params: [ { name: 'CAMERA_URL', value: 'test', }, ], }; const rtspCameraController = RtspCameraController(rtspCameraService); const req = { body: device, }; await rtspCameraController['post /api/v1/service/rtsp-camera/camera/test'].controller(req, res); assert.calledWith(rtspCameraService.getImage, device); }); });
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('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); }); });
describe('TasmotaHandler - handle new state Color Scheme', () => { const tasmotaHandler = new TasmotaHandler(gladys, serviceId); beforeEach(() => { sinon.reset(); }); it('decode RESULT message', () => { tasmotaHandler.handleMqttMessage('stat/tasmota-device-topic/RESULT', '{ "Scheme": 1 }'); const expectedEvent = { device_feature_external_id: `tasmota:tasmota-device-topic:Scheme`, state: 1, }; assert.calledWith(gladys.event.emit, EVENTS.DEVICE.NEW_STATE, expectedEvent); }); });
describe('TasmotaHandler - handle new state CT', () => { const tasmotaHandler = new TasmotaHandler(gladys, serviceId); beforeEach(() => { sinon.reset(); }); it('decode RESULT CT message', () => { tasmotaHandler.handleMqttMessage('stat/tasmota-device-topic/RESULT', '{ "CT": 125 }'); const expectedEvent = { device_feature_external_id: `tasmota:tasmota-device-topic:CT`, state: 125, }; assert.calledWith(gladys.event.emit, EVENTS.DEVICE.NEW_STATE, expectedEvent); }); });
describe('TasmotaHandler - handle new state Dimmer', () => { const tasmotaHandler = new TasmotaHandler(gladys, serviceId); beforeEach(() => { sinon.reset(); }); it('decode RESULT Dimmer message', () => { tasmotaHandler.handleMqttMessage('stat/tasmota-device-topic/RESULT', '{ "Dimmer": 125 }'); const expectedEvent = { device_feature_external_id: `tasmota:tasmota-device-topic:Dimmer`, state: 125, }; assert.calledWith(gladys.event.emit, EVENTS.DEVICE.NEW_STATE, expectedEvent); }); });