2024-02-09 01:41:01 -08:00
|
|
|
import { VariablesService } from '@/environments/variables/variables.service.ee';
|
2023-11-10 06:04:26 -08:00
|
|
|
import { mockInstance } from '../shared/mocking';
|
2024-02-09 01:41:01 -08:00
|
|
|
import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus';
|
|
|
|
import { getBase } from '@/WorkflowExecuteAdditionalData';
|
|
|
|
import Container from 'typedi';
|
|
|
|
import { CredentialsHelper } from '@/CredentialsHelper';
|
|
|
|
import { SecretsHelper } from '@/SecretsHelpers';
|
2023-03-23 10:07:46 -07:00
|
|
|
|
|
|
|
describe('WorkflowExecuteAdditionalData', () => {
|
2024-02-09 01:41:01 -08:00
|
|
|
const messageEventBus = mockInstance(MessageEventBus);
|
|
|
|
const variablesService = mockInstance(VariablesService);
|
|
|
|
variablesService.getAllCached.mockResolvedValue([]);
|
|
|
|
const credentialsHelper = mockInstance(CredentialsHelper);
|
|
|
|
const secretsHelper = mockInstance(SecretsHelper);
|
|
|
|
Container.set(MessageEventBus, messageEventBus);
|
|
|
|
Container.set(VariablesService, variablesService);
|
|
|
|
Container.set(CredentialsHelper, credentialsHelper);
|
|
|
|
Container.set(SecretsHelper, secretsHelper);
|
2023-09-05 00:13:30 -07:00
|
|
|
|
2024-02-09 01:41:01 -08:00
|
|
|
test('logAiEvent should call MessageEventBus', async () => {
|
|
|
|
const additionalData = await getBase('user-id');
|
|
|
|
|
|
|
|
const eventName = 'n8n.ai.memory.get.messages';
|
|
|
|
const payload = {
|
|
|
|
msg: 'test message',
|
|
|
|
executionId: '123',
|
|
|
|
nodeName: 'n8n-memory',
|
|
|
|
workflowId: 'workflow-id',
|
|
|
|
workflowName: 'workflow-name',
|
|
|
|
nodeType: 'n8n-memory',
|
2023-03-23 10:07:46 -07:00
|
|
|
};
|
|
|
|
|
2024-02-09 01:41:01 -08:00
|
|
|
await additionalData.logAiEvent(eventName, payload);
|
2023-03-23 10:07:46 -07:00
|
|
|
|
2024-02-09 01:41:01 -08:00
|
|
|
expect(messageEventBus.sendAiNodeEvent).toHaveBeenCalledTimes(1);
|
|
|
|
expect(messageEventBus.sendAiNodeEvent).toHaveBeenCalledWith({
|
|
|
|
eventName,
|
|
|
|
payload,
|
|
|
|
});
|
2023-03-23 10:07:46 -07:00
|
|
|
});
|
|
|
|
});
|