Skip to content

Commit

Permalink
Add test to debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed May 3, 2024
1 parent 136e5ce commit dc4451d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/test/services/mqtt/lib/handleNewMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sinon = require('sinon');

const { assert, fake } = sinon;
const { EVENTS } = require('../../../../utils/constants');
const { EVENTS, WEBSOCKET_MESSAGE_TYPES } = require('../../../../utils/constants');
const { MockedMqttClient } = require('../mocks.test');

const gladys = {
Expand Down Expand Up @@ -31,6 +31,7 @@ describe('Mqtt handle message', () => {

afterEach(() => {
mqttHandler.disconnect();
mqttHandler.debugMode = false;
});

it('should not do anything, topic not found', () => {
Expand Down Expand Up @@ -86,7 +87,19 @@ describe('Mqtt handle message', () => {

assert.notCalled(gladys.event.emit);
});
it('handle device with custom topic and debug mode', () => {
mqttHandler.debugMode = true;
mqttHandler.deviceFeatureCustomMqttTopics = [];
mqttHandler.handleNewMessage('custom_mqtt_topic/test/test', '12');

assert.calledWith(gladys.event.emit, EVENTS.WEBSOCKET.SEND_ALL, {
type: WEBSOCKET_MESSAGE_TYPES.MQTT.DEBUG_NEW_MQTT_MESSAGE,
payload: {
topic: 'custom_mqtt_topic/test/test',
message: '12',
},
});
});
it('handle device with custom topic', () => {
mqttHandler.deviceFeatureCustomMqttTopics = [
{
Expand Down

0 comments on commit dc4451d

Please sign in to comment.