Skip to content

Commit

Permalink
define friendly name to spammer test devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanfmartinez committed Sep 27, 2024
1 parent 4653723 commit d678819
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/receive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ describe('Receive', () => {

it('Should ignore multiple messages from spamming devices', async () => {
const device = zigbeeHerdsman.devices.SPAMMER1;
const start = Date.now();
const min_elapsed_for_testing = 500;
settings.set(['device_options', 'min_elapsed'], min_elapsed_for_testing);
settings.set(['device_options', 'retain'], true);
settings.set(['devices', device.ieeeAddr, 'friendly_name'], 'spammer1');
const data1 = {measuredValue: 1};
const payload1 = {
data: data1,
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('Receive', () => {
expect(MQTT.publish).toHaveBeenCalledTimes(1);
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledTimes(1);
expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/' + device.ieeeAddr);
expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/spammer1');
expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({temperature: 0.01});
expect(MQTT.publish.mock.calls[0][2]).toStrictEqual({qos: 0, retain: true});

Expand All @@ -406,17 +406,17 @@ describe('Receive', () => {
await zigbeeHerdsman.events.message(payload3);
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledTimes(2);
expect(MQTT.publish.mock.calls[1][0]).toStrictEqual('zigbee2mqtt/' + device.ieeeAddr);
expect(MQTT.publish.mock.calls[1][0]).toStrictEqual('zigbee2mqtt/spammer1');
expect(JSON.parse(MQTT.publish.mock.calls[1][1])).toStrictEqual({elapsed: timeshift, temperature: 0.03});
expect(MQTT.publish.mock.calls[1][2]).toStrictEqual({qos: 0, retain: true});
});

it('Should ignore multiple messages from spamming devices defined by description', async () => {
const device = zigbeeHerdsman.devices.SPAMMER2;
const start = Date.now();
const min_elapsed_for_testing = 50000;
settings.set(['device_options', 'retain'], true);
settings.set(['devices', device.ieeeAddr, 'description'], 'this is a SPAMMER device');
settings.set(['devices', device.ieeeAddr, 'friendly_name'], 'spammer2');
const data1 = {measuredValue: 1};
const payload1 = {
data: data1,
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('Receive', () => {
expect(MQTT.publish).toHaveBeenCalledTimes(1);
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledTimes(1);
expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/' + device.ieeeAddr);
expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/spammer2');
expect(JSON.parse(MQTT.publish.mock.calls[0][1])).toStrictEqual({temperature: 0.01});
expect(MQTT.publish.mock.calls[0][2]).toStrictEqual({qos: 0, retain: true});

Expand All @@ -462,7 +462,7 @@ describe('Receive', () => {
await zigbeeHerdsman.events.message(payload3);
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledTimes(2);
expect(MQTT.publish.mock.calls[1][0]).toStrictEqual('zigbee2mqtt/' + device.ieeeAddr);
expect(MQTT.publish.mock.calls[1][0]).toStrictEqual('zigbee2mqtt/spammer2');
expect(JSON.parse(MQTT.publish.mock.calls[1][1])).toStrictEqual({elapsed: timeshift, temperature: 0.03});
expect(MQTT.publish.mock.calls[1][2]).toStrictEqual({qos: 0, retain: true});
});
Expand Down

0 comments on commit d678819

Please sign in to comment.