test: Fix telemetry tests (#3804)

* 🧪 Set telemetry env vars

* 🔥 Remove logging

* 🎨 Format with Prettier
This commit is contained in:
Iván Ovejero 2022-08-01 22:37:59 +02:00 committed by GitHub
parent 3de062202d
commit 231cfaa24d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
import { Telemetry } from '../../src/telemetry';
import config from '../../config';
jest.spyOn(Telemetry.prototype as any, 'createTelemetryClient').mockImplementation(() => {
return {
@ -18,9 +19,13 @@ describe('Telemetry', () => {
const testDateTime = new Date('2022-01-01 00:00:00');
beforeAll(() => {
startPulseSpy = jest.spyOn(Telemetry.prototype as any, 'startPulse').mockImplementation(() => {});
startPulseSpy = jest
.spyOn(Telemetry.prototype as any, 'startPulse')
.mockImplementation(() => {});
jest.useFakeTimers();
jest.setSystemTime(testDateTime);
config.set('diagnostics.enabled', true);
config.set('deployment.type', 'n8n-testing');
});
afterAll(() => {
@ -56,7 +61,7 @@ describe('Telemetry', () => {
workflow_id: '1',
is_manual: true,
success: true,
error_node_type: 'custom-nodes-base.node-type'
error_node_type: 'custom-nodes-base.node-type',
};
payload.is_manual = true;
@ -106,7 +111,7 @@ describe('Telemetry', () => {
workflow_id: '1',
is_manual: true,
success: false,
error_node_type: 'custom-nodes-base.node-type'
error_node_type: 'custom-nodes-base.node-type',
};
const execTime1 = fakeJestSystemTime('2022-01-01 12:00:00');
@ -141,7 +146,7 @@ describe('Telemetry', () => {
workflow_id: '1',
is_manual: false,
success: true,
error_node_type: 'node_type'
error_node_type: 'node_type',
};
// successful execution
@ -266,7 +271,7 @@ describe('Telemetry', () => {
afterEach(() => {
pulseSpy.mockClear();
})
});
test('should trigger pulse in intervals', () => {
expect(pulseSpy).toBeCalledTimes(0);
@ -296,7 +301,7 @@ describe('Telemetry', () => {
workflow_id: '1',
is_manual: true,
success: true,
error_node_type: 'custom-nodes-base.node-type'
error_node_type: 'custom-nodes-base.node-type',
};
await telemetry.trackWorkflowExecution(payload);
@ -330,7 +335,6 @@ describe('Telemetry', () => {
expect(pulseSpy).toBeCalledTimes(1);
expect(spyTrack).toHaveBeenCalledTimes(3);
console.log(spyTrack.getMockImplementation());
expect(spyTrack).toHaveBeenNthCalledWith(1, 'Workflow execution count', {
event_version: '2',
workflow_id: '1',
@ -349,7 +353,7 @@ describe('Telemetry', () => {
prod_success: {
count: 2,
first: testDateTime,
}
},
});
expect(spyTrack).toHaveBeenNthCalledWith(2, 'Workflow execution count', {
event_version: '2',
@ -357,7 +361,7 @@ describe('Telemetry', () => {
prod_error: {
count: 2,
first: testDateTime,
}
},
});
expect(spyTrack).toHaveBeenNthCalledWith(3, 'pulse');
expect(Object.keys(execBuffer).length).toBe(0);
@ -378,4 +382,4 @@ const fakeJestSystemTime = (dateTime: string | Date): Date => {
const dt = new Date(dateTime);
jest.setSystemTime(dt);
return dt;
}
};