mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(MQTT Node): Refactor, fix duplicate triggers, and add Unit tests (#9847)
Co-authored-by: Elias Meire <elias@meire.dev>
This commit is contained in:
committed by
GitHub
parent
e51de9d391
commit
164ec72c0d
38
packages/nodes-base/nodes/MQTT/test/GenericFunctions.test.ts
Normal file
38
packages/nodes-base/nodes/MQTT/test/GenericFunctions.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { MqttClient } from 'mqtt';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
import { createClient, type MqttCredential } from '../GenericFunctions';
|
||||
|
||||
describe('createClient', () => {
|
||||
const mockConnect = jest.spyOn(MqttClient.prototype, 'connect').mockImplementation(function (
|
||||
this: MqttClient,
|
||||
) {
|
||||
setImmediate(() => this.emit('connect', mock()));
|
||||
return this;
|
||||
});
|
||||
|
||||
beforeEach(() => jest.clearAllMocks());
|
||||
|
||||
it('should create a client with minimal credentials', async () => {
|
||||
const credentials = mock<MqttCredential>({
|
||||
protocol: 'mqtt',
|
||||
host: 'localhost',
|
||||
port: 1883,
|
||||
clean: true,
|
||||
clientId: 'testClient',
|
||||
ssl: false,
|
||||
});
|
||||
const client = await createClient(credentials);
|
||||
|
||||
expect(mockConnect).toBeCalledTimes(1);
|
||||
expect(client).toBeDefined();
|
||||
expect(client).toBeInstanceOf(MqttClient);
|
||||
expect(client.options).toMatchObject({
|
||||
protocol: 'mqtt',
|
||||
host: 'localhost',
|
||||
port: 1883,
|
||||
clean: true,
|
||||
clientId: 'testClient',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user