refactor(editor): Refactor usePushConnection and introduce new queueing system (#14529)

This commit is contained in:
Alex Grozav
2025-04-30 15:36:43 +03:00
committed by GitHub
parent 442cd094ee
commit 833d8e3c18
49 changed files with 1525 additions and 1262 deletions

View File

@@ -25,9 +25,9 @@ import { usePushConnectionStore } from '@/stores/pushConnection.store';
import { createTestNode, createTestWorkflow } from '@/__tests__/mocks';
import { waitFor } from '@testing-library/vue';
vi.mock('@/stores/workflows.store', async () => {
vi.mock('@/stores/workflows.store', () => {
const storeState: Partial<ReturnType<typeof useWorkflowsStore>> & {
activeExecutionId: string | null;
activeExecutionId: string | null | undefined;
} = {
allNodes: [],
runWorkflow: vi.fn(),
@@ -35,8 +35,8 @@ vi.mock('@/stores/workflows.store', async () => {
getWorkflowRunData: null,
workflowExecutionData: null,
setWorkflowExecutionData: vi.fn(),
activeExecutionId: null,
previousExecutionId: null,
activeExecutionId: undefined,
previousExecutionId: undefined,
nodesIssuesExist: false,
executionWaitingForWebhook: false,
getCurrentWorkflow: vi.fn().mockReturnValue({ id: '123' }),
@@ -49,7 +49,7 @@ vi.mock('@/stores/workflows.store', async () => {
incomingConnectionsByNodeName: vi.fn(),
outgoingConnectionsByNodeName: vi.fn(),
markExecutionAsStopped: vi.fn(),
setActiveExecutionId: vi.fn((id: string | null) => {
setActiveExecutionId: vi.fn((id: string | null | undefined) => {
storeState.activeExecutionId = id;
}),
};
@@ -123,7 +123,7 @@ describe('useRunWorkflow({ router })', () => {
let workflowHelpers: ReturnType<typeof useWorkflowHelpers>;
let settingsStore: ReturnType<typeof useSettingsStore>;
beforeAll(() => {
beforeEach(() => {
const pinia = createTestingPinia({ stubActions: false });
setActivePinia(pinia);
@@ -137,8 +137,8 @@ describe('useRunWorkflow({ router })', () => {
workflowHelpers = useWorkflowHelpers({ router });
});
beforeEach(() => {
uiStore.activeActions = [];
afterEach(() => {
vi.mocked(workflowsStore).setActiveExecutionId(undefined);
vi.clearAllMocks();
});
@@ -160,14 +160,13 @@ describe('useRunWorkflow({ router })', () => {
const mockResponse = { executionId: '123', waitingForWebhook: false };
vi.mocked(workflowsStore).runWorkflow.mockResolvedValue(mockResponse);
vi.mocked(workflowsStore).setActiveExecutionId('123');
const response = await runWorkflowApi({} as IStartRunData);
expect(response).toEqual(mockResponse);
expect(workflowsStore.activeExecutionId).toBe('123');
expect(workflowsStore.setActiveExecutionId).toHaveBeenNthCalledWith(1, null);
expect(workflowsStore.setActiveExecutionId).toHaveBeenNthCalledWith(2, '123');
expect(workflowsStore.executionWaitingForWebhook).toBe(false);
expect(uiStore.addActiveAction).toHaveBeenCalledWith('workflowRunning');
});
it('should prevent running a webhook-based workflow that has issues', async () => {
@@ -192,7 +191,7 @@ describe('useRunWorkflow({ router })', () => {
vi.mocked(workflowsStore).runWorkflow.mockRejectedValue(new Error('Failed to run workflow'));
await expect(runWorkflowApi({} as IStartRunData)).rejects.toThrow('Failed to run workflow');
expect(uiStore.removeActiveAction).toHaveBeenCalledWith('workflowRunning');
expect(workflowsStore.setActiveExecutionId).toHaveBeenCalledWith(undefined);
});
it('should set waitingForWebhook if response indicates waiting', async () => {
@@ -207,6 +206,7 @@ describe('useRunWorkflow({ router })', () => {
expect(response).toEqual(mockResponse);
expect(workflowsStore.executionWaitingForWebhook).toBe(true);
});
it('should prevent execution and show error message when workflow is active with single webhook trigger', async () => {
const pinia = createTestingPinia({ stubActions: false });
setActivePinia(pinia);
@@ -292,7 +292,7 @@ describe('useRunWorkflow({ router })', () => {
describe('runWorkflow()', () => {
it('should return undefined if UI action "workflowRunning" is active', async () => {
const { runWorkflow } = useRunWorkflow({ router });
uiStore.addActiveAction('workflowRunning');
vi.mocked(workflowsStore).setActiveExecutionId('123');
const result = await runWorkflow({});
expect(result).toBeUndefined();
});