2023-05-23 17:01:45 -07:00
|
|
|
import type RudderStack from '@rudderstack/rudder-sdk-node';
|
2022-11-09 06:25:00 -08:00
|
|
|
import { Telemetry } from '@/telemetry';
|
|
|
|
import config from '@/config';
|
2022-12-20 01:52:01 -08:00
|
|
|
import { flushPromises } from './Helpers';
|
2023-02-21 00:35:35 -08:00
|
|
|
import { PostHogClient } from '@/posthog';
|
2023-03-16 07:34:13 -07:00
|
|
|
import { mock } from 'jest-mock-extended';
|
2022-12-20 01:52:01 -08:00
|
|
|
|
2023-01-04 00:47:48 -08:00
|
|
|
jest.unmock('@/telemetry');
|
2022-12-20 01:52:01 -08:00
|
|
|
jest.mock('@/license/License.service', () => {
|
|
|
|
return {
|
|
|
|
LicenseService: {
|
|
|
|
getActiveTriggerCount: async () => 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2023-02-21 00:35:35 -08:00
|
|
|
jest.mock('@/posthog');
|
2022-07-09 23:53:04 -07:00
|
|
|
|
|
|
|
describe('Telemetry', () => {
|
2022-08-01 13:37:59 -07:00
|
|
|
let startPulseSpy: jest.SpyInstance;
|
2022-12-20 01:52:01 -08:00
|
|
|
const spyTrack = jest.spyOn(Telemetry.prototype, 'track').mockName('track');
|
2022-08-01 13:37:59 -07:00
|
|
|
|
2023-05-23 17:01:45 -07:00
|
|
|
const mockRudderStack: Pick<RudderStack, 'flush' | 'identify' | 'track'> = {
|
|
|
|
flush: (resolve) => resolve?.(),
|
|
|
|
identify: (data, resolve) => resolve?.(),
|
|
|
|
track: (data, resolve) => resolve?.(),
|
|
|
|
};
|
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
let telemetry: Telemetry;
|
|
|
|
const instanceId = 'Telemetry unit test';
|
|
|
|
const testDateTime = new Date('2022-01-01 00:00:00');
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2023-05-23 17:01:45 -07:00
|
|
|
afterAll(async () => {
|
2022-08-01 13:37:59 -07:00
|
|
|
jest.clearAllTimers();
|
|
|
|
jest.useRealTimers();
|
|
|
|
startPulseSpy.mockRestore();
|
2023-05-23 17:01:45 -07:00
|
|
|
await telemetry.trackN8nStop();
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
|
|
|
|
2023-05-23 17:01:45 -07:00
|
|
|
beforeEach(async () => {
|
2022-08-01 13:37:59 -07:00
|
|
|
spyTrack.mockClear();
|
2023-02-21 00:35:35 -08:00
|
|
|
|
|
|
|
const postHog = new PostHogClient();
|
2023-05-23 17:01:45 -07:00
|
|
|
await postHog.init(instanceId);
|
2023-02-21 00:35:35 -08:00
|
|
|
|
2023-03-16 07:34:13 -07:00
|
|
|
telemetry = new Telemetry(postHog, mock());
|
2023-02-21 10:21:56 -08:00
|
|
|
telemetry.setInstanceId(instanceId);
|
2023-05-23 17:01:45 -07:00
|
|
|
(telemetry as any).rudderStack = mockRudderStack;
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
|
|
|
|
2023-05-23 17:01:45 -07:00
|
|
|
afterEach(async () => {
|
|
|
|
await telemetry.trackN8nStop();
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
|
|
|
describe('trackN8nStop', () => {
|
2023-05-23 17:01:45 -07:00
|
|
|
test('should call track method', async () => {
|
|
|
|
await telemetry.trackN8nStop();
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(1);
|
2022-07-09 23:53:04 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
describe('trackWorkflowExecution', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.setSystemTime(testDateTime);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should count executions correctly', async () => {
|
|
|
|
const payload = {
|
|
|
|
workflow_id: '1',
|
|
|
|
is_manual: true,
|
|
|
|
success: true,
|
|
|
|
error_node_type: 'custom-nodes-base.node-type',
|
|
|
|
};
|
|
|
|
|
|
|
|
payload.is_manual = true;
|
|
|
|
payload.success = true;
|
|
|
|
const execTime1 = fakeJestSystemTime('2022-01-01 12:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
payload.is_manual = false;
|
|
|
|
payload.success = true;
|
|
|
|
const execTime2 = fakeJestSystemTime('2022-01-01 13:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
payload.is_manual = true;
|
|
|
|
payload.success = false;
|
|
|
|
const execTime3 = fakeJestSystemTime('2022-01-01 14:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
payload.is_manual = false;
|
|
|
|
payload.success = false;
|
|
|
|
const execTime4 = fakeJestSystemTime('2022-01-01 15:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
const execBuffer = telemetry.getCountsBuffer();
|
|
|
|
|
|
|
|
expect(execBuffer['1'].manual_success?.count).toBe(2);
|
|
|
|
expect(execBuffer['1'].manual_success?.first).toEqual(execTime1);
|
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(2);
|
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime2);
|
|
|
|
expect(execBuffer['1'].manual_error?.count).toBe(2);
|
|
|
|
expect(execBuffer['1'].manual_error?.first).toEqual(execTime3);
|
|
|
|
expect(execBuffer['1'].prod_error?.count).toBe(2);
|
|
|
|
expect(execBuffer['1'].prod_error?.first).toEqual(execTime4);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fire "Workflow execution errored" event for failed executions', async () => {
|
|
|
|
const payload = {
|
|
|
|
workflow_id: '1',
|
|
|
|
is_manual: true,
|
|
|
|
success: false,
|
|
|
|
error_node_type: 'custom-nodes-base.node-type',
|
|
|
|
};
|
|
|
|
|
|
|
|
const execTime1 = fakeJestSystemTime('2022-01-01 12:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
let execBuffer = telemetry.getCountsBuffer();
|
|
|
|
|
|
|
|
// should not fire event for custom nodes
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
expect(execBuffer['1'].manual_error?.count).toBe(2);
|
|
|
|
expect(execBuffer['1'].manual_error?.first).toEqual(execTime1);
|
|
|
|
|
|
|
|
payload.error_node_type = 'n8n-nodes-base.node-type';
|
|
|
|
fakeJestSystemTime('2022-01-01 13:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
fakeJestSystemTime('2022-01-01 12:30:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
|
|
|
|
|
|
|
// should fire event for custom nodes
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(2);
|
|
|
|
expect(spyTrack).toHaveBeenCalledWith('Workflow execution errored', payload);
|
|
|
|
expect(execBuffer['1'].manual_error?.count).toBe(4);
|
|
|
|
expect(execBuffer['1'].manual_error?.first).toEqual(execTime1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should track production executions count correctly', async () => {
|
|
|
|
const payload = {
|
|
|
|
workflow_id: '1',
|
|
|
|
is_manual: false,
|
|
|
|
success: true,
|
|
|
|
error_node_type: 'node_type',
|
|
|
|
};
|
|
|
|
|
|
|
|
// successful execution
|
|
|
|
const execTime1 = fakeJestSystemTime('2022-01-01 12:00:00');
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
let execBuffer = telemetry.getCountsBuffer();
|
|
|
|
expect(execBuffer['1'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].prod_error).toBeUndefined();
|
|
|
|
|
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(1);
|
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime1);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
// successful execution n8n node
|
|
|
|
payload.error_node_type = 'n8n-nodes-base.merge';
|
|
|
|
payload.workflow_id = '2';
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
|
|
|
expect(execBuffer['1'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].prod_error).toBeUndefined();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(1);
|
|
|
|
expect(execBuffer['2'].prod_success?.count).toBe(1);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime1);
|
|
|
|
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
// additional successful execution
|
|
|
|
payload.error_node_type = 'n8n-nodes-base.merge';
|
|
|
|
payload.workflow_id = '2';
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
payload.error_node_type = 'n8n-nodes-base.merge';
|
|
|
|
payload.workflow_id = '1';
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['1'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].prod_error).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].prod_error).toBeUndefined();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(2);
|
|
|
|
expect(execBuffer['2'].prod_success?.count).toBe(2);
|
|
|
|
|
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime1);
|
|
|
|
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
|
|
|
|
|
|
|
|
// failed execution
|
|
|
|
const execTime2 = fakeJestSystemTime('2022-01-01 12:00:00');
|
|
|
|
payload.error_node_type = 'custom-package.custom-node';
|
|
|
|
payload.success = false;
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
|
|
|
|
|
|
|
expect(execBuffer['1'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].prod_error).toBeUndefined();
|
|
|
|
|
|
|
|
expect(execBuffer['1'].prod_error?.count).toBe(1);
|
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(2);
|
|
|
|
expect(execBuffer['2'].prod_success?.count).toBe(2);
|
|
|
|
|
|
|
|
expect(execBuffer['1'].prod_error?.first).toEqual(execTime2);
|
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime1);
|
|
|
|
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
|
|
|
|
|
|
|
|
// failed execution n8n node
|
|
|
|
payload.success = false;
|
|
|
|
payload.error_node_type = 'n8n-nodes-base.merge';
|
2023-05-28 03:08:46 -07:00
|
|
|
payload.is_manual = true;
|
2022-08-01 13:37:59 -07:00
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
|
|
|
|
2023-05-28 03:08:46 -07:00
|
|
|
expect(execBuffer['1'].manual_error?.count).toBe(1);
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['1'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_error).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].manual_success).toBeUndefined();
|
|
|
|
expect(execBuffer['2'].prod_error).toBeUndefined();
|
|
|
|
expect(execBuffer['1'].prod_success?.count).toBe(2);
|
2023-05-28 03:08:46 -07:00
|
|
|
expect(execBuffer['1'].prod_error?.count).toBe(1);
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(execBuffer['2'].prod_success?.count).toBe(2);
|
|
|
|
|
|
|
|
expect(execBuffer['1'].prod_error?.first).toEqual(execTime2);
|
|
|
|
expect(execBuffer['1'].prod_success?.first).toEqual(execTime1);
|
|
|
|
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
|
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
});
|
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
describe('pulse', () => {
|
|
|
|
let pulseSpy: jest.SpyInstance;
|
|
|
|
beforeAll(() => {
|
|
|
|
startPulseSpy.mockRestore();
|
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
beforeEach(() => {
|
|
|
|
fakeJestSystemTime(testDateTime);
|
2022-12-20 01:52:01 -08:00
|
|
|
pulseSpy = jest.spyOn(Telemetry.prototype as any, 'pulse').mockName('pulseSpy');
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
afterEach(() => {
|
|
|
|
pulseSpy.mockClear();
|
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
xtest('should trigger pulse in intervals', async () => {
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(pulseSpy).toBeCalledTimes(0);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
jest.advanceTimersToNextTimer();
|
2022-12-20 01:52:01 -08:00
|
|
|
await flushPromises();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(pulseSpy).toBeCalledTimes(1);
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(1);
|
2022-12-20 01:52:01 -08:00
|
|
|
expect(spyTrack).toHaveBeenCalledWith('pulse', {
|
|
|
|
plan_name_current: 'Community',
|
|
|
|
quota: -1,
|
|
|
|
usage: 0,
|
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
jest.advanceTimersToNextTimer();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
await flushPromises();
|
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(pulseSpy).toBeCalledTimes(2);
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(2);
|
2022-12-20 01:52:01 -08:00
|
|
|
expect(spyTrack).toHaveBeenCalledWith('pulse', {
|
|
|
|
plan_name_current: 'Community',
|
|
|
|
quota: -1,
|
|
|
|
usage: 0,
|
|
|
|
});
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
xtest('should track workflow counts correctly', async () => {
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(pulseSpy).toBeCalledTimes(0);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
let execBuffer = telemetry.getCountsBuffer();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
// expect clear counters on start
|
|
|
|
expect(Object.keys(execBuffer).length).toBe(0);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
const payload = {
|
|
|
|
workflow_id: '1',
|
|
|
|
is_manual: true,
|
|
|
|
success: true,
|
|
|
|
error_node_type: 'custom-nodes-base.node-type',
|
|
|
|
};
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
payload.is_manual = false;
|
|
|
|
payload.success = true;
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
payload.is_manual = true;
|
|
|
|
payload.success = false;
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
payload.is_manual = false;
|
|
|
|
payload.success = false;
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
payload.workflow_id = '2';
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
|
|
|
await telemetry.trackWorkflowExecution(payload);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(0);
|
|
|
|
expect(pulseSpy).toBeCalledTimes(0);
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
jest.advanceTimersToNextTimer();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
2022-07-09 23:53:04 -07:00
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
await flushPromises();
|
|
|
|
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(pulseSpy).toBeCalledTimes(1);
|
|
|
|
expect(spyTrack).toHaveBeenCalledTimes(3);
|
2022-12-06 06:55:40 -08:00
|
|
|
expect(spyTrack).toHaveBeenNthCalledWith(
|
|
|
|
1,
|
|
|
|
'Workflow execution count',
|
|
|
|
{
|
|
|
|
event_version: '2',
|
|
|
|
workflow_id: '1',
|
|
|
|
user_id: undefined,
|
|
|
|
manual_error: {
|
|
|
|
count: 2,
|
|
|
|
first: testDateTime,
|
|
|
|
},
|
|
|
|
manual_success: {
|
|
|
|
count: 2,
|
|
|
|
first: testDateTime,
|
|
|
|
},
|
|
|
|
prod_error: {
|
|
|
|
count: 2,
|
|
|
|
first: testDateTime,
|
|
|
|
},
|
|
|
|
prod_success: {
|
|
|
|
count: 2,
|
|
|
|
first: testDateTime,
|
|
|
|
},
|
2022-08-01 13:37:59 -07:00
|
|
|
},
|
2022-12-06 06:55:40 -08:00
|
|
|
{ withPostHog: true },
|
|
|
|
);
|
|
|
|
expect(spyTrack).toHaveBeenNthCalledWith(
|
|
|
|
2,
|
|
|
|
'Workflow execution count',
|
|
|
|
{
|
|
|
|
event_version: '2',
|
|
|
|
workflow_id: '2',
|
|
|
|
user_id: undefined,
|
|
|
|
prod_error: {
|
|
|
|
count: 2,
|
|
|
|
first: testDateTime,
|
|
|
|
},
|
2022-08-01 13:37:59 -07:00
|
|
|
},
|
2022-12-06 06:55:40 -08:00
|
|
|
{ withPostHog: true },
|
|
|
|
);
|
2022-12-20 01:52:01 -08:00
|
|
|
expect(spyTrack).toHaveBeenNthCalledWith(3, 'pulse', {
|
|
|
|
plan_name_current: 'Community',
|
|
|
|
quota: -1,
|
|
|
|
usage: 0,
|
|
|
|
});
|
2022-08-01 13:37:59 -07:00
|
|
|
expect(Object.keys(execBuffer).length).toBe(0);
|
|
|
|
|
2022-12-06 06:55:40 -08:00
|
|
|
// Adding a second step here because we believe PostHog may use timers for sending data
|
|
|
|
// and adding posthog to the above metric was causing the pulseSpy timer to not be ran
|
2022-08-01 13:37:59 -07:00
|
|
|
jest.advanceTimersToNextTimer();
|
|
|
|
|
|
|
|
execBuffer = telemetry.getCountsBuffer();
|
|
|
|
expect(Object.keys(execBuffer).length).toBe(0);
|
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
// @TODO: Flushing promises here is not working
|
|
|
|
|
|
|
|
// expect(pulseSpy).toBeCalledTimes(2);
|
|
|
|
// expect(spyTrack).toHaveBeenCalledTimes(4);
|
|
|
|
// expect(spyTrack).toHaveBeenNthCalledWith(4, 'pulse', {
|
|
|
|
// plan_name_current: 'Community',
|
|
|
|
// quota: -1,
|
|
|
|
// usage: 0,
|
|
|
|
// });
|
2022-08-01 13:37:59 -07:00
|
|
|
});
|
2022-07-09 23:53:04 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const fakeJestSystemTime = (dateTime: string | Date): Date => {
|
2022-08-01 13:37:59 -07:00
|
|
|
const dt = new Date(dateTime);
|
|
|
|
jest.setSystemTime(dt);
|
|
|
|
return dt;
|
|
|
|
};
|