This commit is contained in:
Koen Kanters
2021-10-03 12:29:54 +02:00
parent fb96551beb
commit 45a4978ca8
3 changed files with 13 additions and 35 deletions
-12
View File
@@ -94,18 +94,6 @@ describe('Bridge', () => {
expect(logger.info).toHaveBeenCalledTimes(1);
});
it('Shouldnt log to MQTT when not connected', async () => {
logger.setTransportsEnabled(true);
MQTT.mock.reconnecting = true;
MQTT.publish.mockClear();
logger.info.mockClear();
logger.error.mockClear();
logger.info("this is a test");
expect(MQTT.publish).toHaveBeenCalledTimes(0);
expect(logger.info).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledTimes(0);
});
it('Should publish groups on startup', async () => {
await resetExtension();
logger.setTransportsEnabled(true);
+4 -6
View File
@@ -150,18 +150,16 @@ describe('Controller', () => {
controller.mqtt.client.reconnecting = false;
});
it('Dont publish to mqtt when client is unavailable', async () => {
it('Log when MQTT publish fails', async () => {
await controller.start();
await flushPromises();
logger.error.mockClear();
controller.mqtt.client.reconnecting = true;
MQTT.mock.publish.mockImplementationOnce((topic, message, options, cb) => cb(true));
const device = controller.zigbee.resolveEntity('bulb');
await controller.publishEntityState(device, {state: 'ON', brightness: 50, color_temp: 370, color: {r: 100, g: 50, b: 10}, dummy: {1: 'yes', 2: 'no'}});
await flushPromises();
expect(logger.error).toHaveBeenCalledTimes(2);
expect(logger.error).toHaveBeenCalledWith("Not connected to MQTT server!");
expect(logger.error).toHaveBeenCalledWith("Cannot send message: topic: 'zigbee2mqtt/bulb', payload: '{\"brightness\":50,\"color\":{\"b\":10,\"g\":50,\"r\":100},\"color_temp\":370,\"dummy\":{\"1\":\"yes\",\"2\":\"no\"},\"linkquality\":99,\"state\":\"ON\"}");
controller.mqtt.client.reconnecting = false;
expect(logger.error).toHaveBeenCalledTimes(1);
expect(logger.error).toHaveBeenCalledWith("MQTT failed to publish: topic: 'zigbee2mqtt/bulb', payload: '{\"brightness\":50,\"color\":{\"b\":10,\"g\":50,\"r\":100},\"color_temp\":370,\"dummy\":{\"1\":\"yes\",\"2\":\"no\"},\"linkquality\":99,\"state\":\"ON\"}");
});
it('Load empty state when state file does not exist', async () => {