Skip to content

The open alternative to Salesforce, designed for AI.

Move workflow execution integration tests to the core workflow API (#27848)

Thomas Trompette6433429f8e8c
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/code-step-prebuilt-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/code-step-prebuilt-workflow.integration-spec.ts
index 359e72103a2..b9cdb6f049a 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/code-step-prebuilt-workflow.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/code-step-prebuilt-workflow.integration-spec.ts
@@ -1,18 +1,22 @@
import gql from 'graphql-tag';
-import request from 'supertest';
+import {
+ activateCoreWorkflowVersion,
+ createCoreWorkflow,
+ createCoreWorkflowVersionStep,
+ deleteCoreWorkflows,
+ runCoreWorkflowVersion,
+ updateCoreWorkflowVersionStep,
+ updateCoreWorkflowVersionTrigger,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import {
destroyWorkflowRun,
- runWorkflowVersion,
waitForWorkflowCompletion,
} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';
import { updateLogicFunctionSource } from 'test/integration/metadata/suites/logic-function/utils/update-logic-function-source.util';
import { makeMetadataApiRequest } from 'test/integration/metadata/suites/utils/make-metadata-api-request.util';
import { LogicFunctionExecutionMode } from 'src/engine/metadata-modules/logic-function/logic-function.entity';
-const client = request(`http://localhost:${APP_PORT}`);
-
const EXTERNAL_PACKAGES_FUNCTION_CODE = `import groupBy from 'lodash.groupby';
export const main = async (params: { items: Array<{ category: string; name: string }> }): Promise<object> => {
@@ -24,55 +28,19 @@ export const main = async (params: { items: Array<{ category: string; name: stri
};`;
describe('Code step workflow with PREBUILT logic function (e2e)', () => {
- let createdWorkflowId: string | null = null;
- let createdWorkflowVersionId: string | null = null;
+ let coreWorkflowId: string | null = null;
+ let coreWorkflowVersionId: string | null = null;
let codeStepId: string | null = null;
let codeStepLogicFunctionId: string | null = null;
let createdWorkflowRunId: string | null = null;
beforeAll(async () => {
- const createWorkflowResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- mutation CreateWorkflow {
- createWorkflow(data: {
- name: "Code Step PREBUILT Test"
- }) {
- id
- }
- }
- `,
- });
-
- expect(createWorkflowResponse.body.errors).toBeUndefined();
- createdWorkflowId = createWorkflowResponse.body.data.createWorkflow.id;
-
- const getWorkflowResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- query GetWorkflow($id: UUID!) {
- workflow(filter: { id: { eq: $id } }) {
- id
- versions {
- edges {
- node {
- id
- }
- }
- }
- }
- }
- `,
- variables: { id: createdWorkflowId },
- });
+ const createdCoreWorkflow = await createCoreWorkflow({
+ name: 'Code Step PREBUILT Test',
+ });
- expect(getWorkflowResponse.body.errors).toBeUndefined();
- createdWorkflowVersionId =
- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;
+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;
+ coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;
const manualTrigger = {
name: 'Manual Trigger',
@@ -86,94 +54,36 @@ describe('Code step workflow with PREBUILT logic function (e2e)', () => {
position: { x: 0, y: 0 },
};
- const updateTriggerResponse = await updateWorkflowVersionTrigger({
- workflowVersionId: createdWorkflowVersionId!,
+ await updateCoreWorkflowVersionTrigger({
+ coreWorkflowVersionId,
trigger: manualTrigger,
});
- expect(updateTriggerResponse.body.errors).toBeUndefined();
-
- const createCodeStepResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- mutation CreateWorkflowVersionStep($input: CreateWorkflowVersionStepInput!) {
- createWorkflowVersionStep(input: $input) {
- stepsDiff
- }
- }
- `,
- variables: {
- input: {
- workflowVersionId: createdWorkflowVersionId,
- stepType: 'CODE',
- parentStepId: 'trigger',
- position: { x: 200, y: 0 },
- },
- },
- });
-
- expect(createCodeStepResponse.body.errors).toBeUndefined();
-
- const getStepsResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- query GetWorkflowVersion($id: UUID!) {
- workflowVersion(filter: { id: { eq: $id } }) {
- id
- steps
- }
- }
- `,
- variables: { id: createdWorkflowVersionId },
- });
-
- expect(getStepsResponse.body.errors).toBeUndefined();
-
- const codeStep = getStepsResponse.body.data.workflowVersion.steps.find(
- (step: { type: string }) => step.type === 'CODE',
- );
+ const codeStep = await createCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ stepType: 'CODE',
+ });
- expect(codeStep).toBeDefined();
codeStepId = codeStep.id;
- const logicFunctionId = codeStep.settings.input.logicFunctionId;
+ const logicFunctionId = codeStep.settings.input.logicFunctionId as string;
expect(logicFunctionId).toBeDefined();
codeStepLogicFunctionId = logicFunctionId;
- const updateStepResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- mutation UpdateWorkflowVersionStep($input: UpdateWorkflowVersionStepInput!) {
- updateWorkflowVersionStep(input: $input) {
- id
- }
- }
- `,
- variables: {
+ await updateCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ step: {
+ ...codeStep,
+ settings: {
+ ...codeStep.settings,
input: {
- workflowVersionId: createdWorkflowVersionId,
- step: {
- ...codeStep,
- settings: {
- ...codeStep.settings,
- input: {
- ...codeStep.settings.input,
- logicFunctionInput: { items: '{{trigger.items}}' },
- },
- },
- },
+ ...codeStep.settings.input,
+ logicFunctionInput: { items: '{{trigger.items}}' },
},
},
- });
-
- expect(updateStepResponse.body.errors).toBeUndefined();
+ },
+ });
const updateSourceResponse = await updateLogicFunctionSource({
input: {
@@ -187,20 +97,7 @@ describe('Code step workflow with PREBUILT logic function (e2e)', () => {
expect(updateSourceResponse.errors).toBeUndefined();
- const activateResponse = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {
- activateWorkflowVersion(workflowVersionId: $workflowVersionId)
- }
- `,
- variables: { workflowVersionId: createdWorkflowVersionId },
- });
-
- expect(activateResponse.body.errors).toBeUndefined();
- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);
+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });
});
afterAll(async () => {
@@ -208,20 +105,8 @@ describe('Code step workflow with PREBUILT logic function (e2e)', () => {
await destroyWorkflowRun(createdWorkflowRunId);
}
- if (createdWorkflowId) {
- await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- mutation DestroyWorkflow($id: ID!) {
- destroyWorkflow(id: $id) {
- id
- }
- }
- `,
- variables: { id: createdWorkflowId },
- });
+ if (coreWorkflowId) {
+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });
}
});
@@ -249,8 +134,8 @@ describe('Code step workflow with PREBUILT logic function (e2e)', () => {
});
it('runs the code step from its prebuilt bundle and resolves bare imports', async () => {
- createdWorkflowRunId = await runWorkflowVersion({
- workflowVersionId: createdWorkflowVersionId!,
+ createdWorkflowRunId = await runCoreWorkflowVersion({
+ coreWorkflowVersionId: coreWorkflowVersionId!,
payload: {
items: [
{ category: 'fruit', name: 'apple' },
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
index 82f5f296323..60d9ca6e9c2 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts
@@ -4,7 +4,7 @@ import { randomUUID } from 'node:crypto';
import { USER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-users.util';
import request from 'supertest';
-import { FeatureFlagKey, FieldMetadataType } from 'twenty-shared/types';
+import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
import { type UserEntity } from 'src/engine/core-modules/user/user.entity';
@@ -22,16 +22,22 @@ import { getQueueToken } from 'src/engine/core-modules/message-queue/utils/get-q
import { RUN_WORKFLOW_JOB_NAME } from 'src/modules/workflow/workflow-runner/constants/run-workflow-job-name';
import { type RunWorkflowJobData } from 'src/modules/workflow/workflow-runner/types/run-workflow-job-data.type';
import { buildRunWorkflowJobOptions } from 'src/modules/workflow/workflow-runner/utils/build-run-workflow-job-options.util';
-import { type DeleteWorkflowRunsDeferredActionHandlerWorkspaceService } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-runner/deferred-action-handlers/services/delete-workflow-runs-deferred-action-handler.workspace-service';
import { type CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
import { answerToolCall } from 'test/integration/graphql/suites/workflow/utils/answer-tool-call.util';
+import {
+ activateCoreWorkflowVersion,
+ coreWorkflowGraphqlRequest,
+ createCoreWorkflow,
+ deleteCoreWorkflows,
+ runCoreWorkflowVersion,
+ updateCoreWorkflowVersionTrigger,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import { submitFormStep } from 'test/integration/graphql/suites/workflow/utils/submit-form-step.util';
import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';
-import { expectEventually } from 'test/integration/utils/expect-eventually.util';
import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';
import { type AgentChatService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service';
import { type AgentChatThreadService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service';
@@ -91,8 +97,8 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
steps?: WorkflowAction[];
triggerNextStepIds?: string[];
} = {}): Promise<Fixture> => {
- let coreWorkflowId = randomUUID();
- let coreWorkflowVersionId = randomUUID();
+ let coreWorkflowId: string = randomUUID();
+ let coreWorkflowVersionId: string = randomUUID();
let workflowId: string | null = null;
let workflowVersionId: string | null = null;
const trigger = {
@@ -132,24 +138,19 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
],
);
} else {
- const response = await workflowGraphqlRequest(
- 'mutation { createWorkflow(data: { name: "B-Async execution" }) { id coreWorkflowId } }',
- );
+ const coreWorkflow = await createCoreWorkflow({
+ name: 'B-Async execution',
+ });
- expect(response.body.errors).toBeUndefined();
- workflowId = response.body.data.createWorkflow.id;
+ coreWorkflowId = coreWorkflow.coreWorkflowId;
+ coreWorkflowVersionId = coreWorkflow.coreWorkflowVersionId;
+ workflowId = coreWorkflow.workspaceWorkflowId;
const [version] = await global.testDataSource.query(
- `SELECT id, "coreWorkflowVersionId" FROM "${schema}"."workflowVersion" WHERE "workflowId" = $1`,
- [workflowId],
- );
- const [workflow] = await global.testDataSource.query(
- `SELECT "coreWorkflowId" FROM "${schema}".workflow WHERE id = $1`,
- [workflowId],
+ `SELECT "workspaceWorkflowVersionId" FROM core."workflowVersion" WHERE id = $1`,
+ [coreWorkflowVersionId],
);
- workflowVersionId = version.id;
- coreWorkflowId = workflow.coreWorkflowId;
- coreWorkflowVersionId = version.coreWorkflowVersionId;
+ workflowVersionId = version.workspaceWorkflowVersionId;
await global.testDataSource.query(
`UPDATE core."workflowVersion" SET triggers = $2, steps = $3, status = 'ACTIVE' WHERE id = $1`,
[
@@ -212,25 +213,16 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
expect((await getRun(runId))?.status).toBe(status);
};
- const runFixture = async (fixture: Fixture, legacy = false) => {
+ const runFixture = async (fixture: Fixture) => {
const workflowRunId = randomUUID();
- const response = await workflowGraphqlRequest(
- legacy
- ? 'mutation Run($input: RunWorkflowVersionInput!) { runWorkflowVersion(input: $input) { workflowRunId } }'
- : 'mutation Run($input: RunCoreWorkflowVersionInput!) { runCoreWorkflowVersion(input: $input) { workflowRunId } }',
- {
- input: {
- ...(legacy
- ? { workflowVersionId: fixture.workflowVersionId }
- : { coreWorkflowVersionId: fixture.coreWorkflowVersionId }),
- workflowRunId,
- payload: { marker: 'B-Async payload' },
- },
- },
- );
- expect(response.body.errors).toBeUndefined();
- expect(Object.values(response.body.data)[0]).toEqual({ workflowRunId });
+ expect(
+ await runCoreWorkflowVersion({
+ coreWorkflowVersionId: fixture.coreWorkflowVersionId,
+ workflowRunId,
+ payload: { marker: 'B-Async payload' },
+ }),
+ ).toBe(workflowRunId);
return workflowRunId;
};
@@ -244,11 +236,9 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
[fixture.coreWorkflowId],
);
if (fixture.workflowId) {
- const response = await workflowGraphqlRequest(
- 'mutation Destroy($id: UUID!) { destroyWorkflow(id: $id) { id } }',
- { id: fixture.workflowId },
- );
- expect(response.body.errors).toBeUndefined();
+ await deleteCoreWorkflows({
+ coreWorkflowIds: [fixture.coreWorkflowId],
+ });
}
await global.testDataSource.query(
'DELETE FROM core."workflowVersion" WHERE "coreWorkflowId" = $1',
@@ -282,7 +272,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
expect(run.createdByWorkspaceMemberId).toBeTruthy();
});
- it('executes the same core definition from both APIs despite divergent workspace content', async () => {
+ it('executes the core definition despite divergent workspace content', async () => {
const fixture = await createFixture();
await global.testDataSource.query(
@@ -290,27 +280,15 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
[fixture.workflowVersionId],
);
- for (const legacy of [false, true]) {
- const run = await waitForRun(
- await runFixture(fixture, legacy),
- 'COMPLETED',
- );
+ const run = await waitForRun(await runFixture(fixture), 'COMPLETED');
- expect(run.coreWorkflowVersionId).toBe(fixture.coreWorkflowVersionId);
- expect(run.state.flow.steps).toEqual(fixture.steps);
- }
+ expect(run.coreWorkflowVersionId).toBe(fixture.coreWorkflowVersionId);
+ expect(run.state.flow.steps).toEqual(fixture.steps);
});
- it.each(
- Object.values(WorkflowActionType).flatMap((actionType) =>
- [false, true].map((isCoreEnabled) => ({ actionType, isCoreEnabled })),
- ),
- )(
- 'dispatches $actionType from the API selected with the core flag set to $isCoreEnabled',
- async ({ actionType, isCoreEnabled }) => {
- const flags = global.workflowTestServices.flags;
- const featureFlag = FeatureFlagKey.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED;
- const original = await flags.isFeatureEnabled(featureFlag, workspaceId);
+ it.each(Object.values(WorkflowActionType))(
+ 'dispatches %s from the core API',
+ async (actionType) => {
const step = {
id: randomUUID(),
name: `${actionType} dispatch marker`,
@@ -341,29 +319,13 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
jest.spyOn(actionFactory, 'get').mockReturnValue({ execute });
- try {
- await flags.upsertWorkspaceFeatureFlag({
- workspaceId,
- featureFlag,
- value: isCoreEnabled,
- });
- const fixture = await createFixture({ steps: [step] });
- const run = await waitForRun(
- await runFixture(fixture, !isCoreEnabled),
- 'COMPLETED',
- );
+ const fixture = await createFixture({ steps: [step] });
+ const run = await waitForRun(await runFixture(fixture), 'COMPLETED');
- expect(actionFactory.get).toHaveBeenCalledWith(actionType);
- expect(execute).toHaveBeenCalledTimes(1);
- expect(run.state.flow.steps[0].type).toBe(actionType);
- expect(run.state.stepInfos[step.id].status).toBe('SUCCESS');
- } finally {
- await flags.upsertWorkspaceFeatureFlag({
- workspaceId,
- featureFlag,
- value: original,
- });
- }
+ expect(actionFactory.get).toHaveBeenCalledWith(actionType);
+ expect(execute).toHaveBeenCalledTimes(1);
+ expect(run.state.flow.steps[0].type).toBe(actionType);
+ expect(run.state.stepInfos[step.id].status).toBe('SUCCESS');
},
);
@@ -1930,128 +1892,6 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
expect(retried.state.stepInfos[failedStep.id].status).toBe('FAILED');
});
- it('restores and relinks runs soft-deleted by a trash from before run cleanup, before retrying their captured snapshots', async () => {
- const failedStep: WorkflowAction = {
- ...emptyStep(),
- type: WorkflowActionType.DELAY,
- settings: {
- ...settings,
- input: {
- delayType: 'SCHEDULED_DATE',
- scheduledDateTime: '2000-01-01T00:00:00.000Z',
- },
- },
- };
- const fixture = await createFixture({ steps: [failedStep] });
- const originalCoreWorkflowId = fixture.coreWorkflowId;
- const runId = await runFixture(fixture);
-
- await waitForRun(runId, 'FAILED');
-
- const runCleanupSpy = jest
- .spyOn(
- getAppProviderByClassName<DeleteWorkflowRunsDeferredActionHandlerWorkspaceService>(
- 'DeleteWorkflowRunsDeferredActionHandlerWorkspaceService',
- ),
- 'execute',
- )
- .mockResolvedValue(undefined);
-
- try {
- const deleteResponse = await workflowGraphqlRequest(
- 'mutation Delete($id: UUID!) { deleteWorkflow(id: $id) { id } }',
- { id: fixture.workflowId },
- );
-
- expect(deleteResponse.body.errors).toBeUndefined();
-
- await expectEventually(() => {
- expect(runCleanupSpy).toHaveBeenCalledWith(
- expect.objectContaining({
- payload: { coreWorkflowId: originalCoreWorkflowId },
- }),
- );
- });
- } finally {
- runCleanupSpy.mockRestore();
- }
-
- await global.testDataSource.query(
- 'DELETE FROM core.workflow WHERE id = $1',
- [originalCoreWorkflowId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowRun" SET "deletedAt" = NOW() WHERE id = $1`,
- [runId],
- );
-
- const restoreResponse = await workflowGraphqlRequest(
- 'mutation Restore($id: UUID!) { restoreWorkflow(id: $id) { id } }',
- { id: fixture.workflowId },
- );
-
- expect(restoreResponse.body.errors).toBeUndefined();
-
- const [restoredMapping] = await global.testDataSource.query(
- `SELECT w."coreWorkflowId", wv."coreWorkflowVersionId"
- FROM "${schema}".workflow w
- JOIN "${schema}"."workflowVersion" wv ON wv.id = $2
- WHERE w.id = $1`,
- [fixture.workflowId, fixture.workflowVersionId],
- );
- const restoredRun = await getRun(runId);
-
- expect(restoredMapping.coreWorkflowId).not.toBe(originalCoreWorkflowId);
- expect(restoredRun.deletedAt).toBeNull();
- expect(restoredRun.coreWorkflowId).toBe(restoredMapping.coreWorkflowId);
- expect(restoredRun.coreWorkflowVersionId).toBe(
- restoredMapping.coreWorkflowVersionId,
- );
-
- fixture.coreWorkflowId = restoredMapping.coreWorkflowId;
- fixture.coreWorkflowVersionId = restoredMapping.coreWorkflowVersionId;
-
- const retryResponse = await workflowGraphqlRequest(
- 'mutation Retry($id: UUID!) { retryWorkflowRun(workflowRunId: $id) { id status } }',
- { id: runId },
- );
-
- expect(retryResponse.body.errors).toBeUndefined();
- await waitForRun(runId, 'FAILED');
- });
-
- it('restores historical versions that no longer validate against current metadata', async () => {
- const historicalStep: WorkflowAction = {
- ...emptyStep(),
- type: WorkflowActionType.CREATE_RECORD,
- settings: {
- ...settings,
- input: { objectName: 'unavailableObject', objectRecord: {} },
- },
- };
- const fixture = await createFixture({ steps: [historicalStep] });
- const deleteResponse = await workflowGraphqlRequest(
- 'mutation Delete($id: UUID!) { deleteWorkflow(id: $id) { id } }',
- { id: fixture.workflowId },
- );
-
- expect(deleteResponse.body.errors).toBeUndefined();
-
- const restoreResponse = await workflowGraphqlRequest(
- 'mutation Restore($id: UUID!) { restoreWorkflow(id: $id) { id } }',
- { id: fixture.workflowId },
- );
-
- expect(restoreResponse.body.errors).toBeUndefined();
-
- const [restoredVersion] = await global.testDataSource.query(
- 'SELECT steps FROM core."workflowVersion" WHERE id = $1',
- [fixture.coreWorkflowVersionId],
- );
-
- expect(restoredVersion.steps).toEqual([historicalStep]);
- });
-
it('records hard-throttled runs with their requested id and snapshot', async () => {
const fixture = await createFixture({ mirrorless: true });
jest
@@ -2134,322 +1974,241 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
expect(run.state.stepInfos[step.id].status).toBe('FAILED');
});
- it('edits, activates and executes through both APIs across flag ON / OFF / ON', async () => {
- const flags = global.workflowTestServices.flags;
- const featureFlag = FeatureFlagKey.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED;
- const original = await flags.isFeatureEnabled(featureFlag, workspaceId);
+ it('edits, activates and executes a new draft through the core API', async () => {
const fixture = await createFixture();
- try {
- for (const value of [true, false, true]) {
- await flags.upsertWorkspaceFeatureFlag({
- workspaceId,
- featureFlag,
- value,
- });
- const draftResponse = await workflowGraphqlRequest(
- value
- ? 'mutation Draft($input: CreateDraftFromCoreWorkflowVersionInput!) { createDraftFromCoreWorkflowVersion(input: $input) { id } }'
- : 'mutation Draft($input: CreateDraftFromWorkflowVersionInput!) { createDraftFromWorkflowVersion(input: $input) { id } }',
- {
- input: value
- ? {
- coreWorkflowId: fixture.coreWorkflowId,
- coreWorkflowVersionIdToCopy: fixture.coreWorkflowVersionId,
- }
- : {
- workflowId: fixture.workflowId,
- workflowVersionIdToCopy: fixture.workflowVersionId,
- },
- },
- );
- expect(draftResponse.body.errors).toBeUndefined();
- const [draft] = await global.testDataSource.query(
- `SELECT id, "workspaceWorkflowVersionId" FROM core."workflowVersion" WHERE "coreWorkflowId" = $1 AND status = 'DRAFT'`,
- [fixture.coreWorkflowId],
- );
- fixture.coreWorkflowVersionId = draft.id;
- fixture.workflowVersionId = draft.workspaceWorkflowVersionId;
- const editedTrigger = {
- ...fixture.trigger,
- name: `B-Async flag ${value}`,
- };
- const editResponse = await workflowGraphqlRequest(
- value
- ? 'mutation Edit($input: UpdateCoreWorkflowVersionTriggerInput!) { updateCoreWorkflowVersionTrigger(input: $input) { trigger } }'
- : 'mutation Edit($input: UpdateWorkflowVersionTriggerInput!) { updateWorkflowVersionTrigger(input: $input) { trigger } }',
- {
- input: {
- ...(value
- ? { coreWorkflowVersionId: draft.id }
- : { workflowVersionId: draft.workspaceWorkflowVersionId }),
- trigger: editedTrigger,
- },
- },
- );
- expect(editResponse.body.errors).toBeUndefined();
- const activateResponse = await workflowGraphqlRequest(
- value
- ? 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }'
- : 'mutation Activate($id: UUID!) { activateWorkflowVersion(workflowVersionId: $id) }',
- { id: value ? draft.id : draft.workspaceWorkflowVersionId },
- );
- expect(activateResponse.body.errors).toBeUndefined();
- for (const legacy of [false, true]) {
- const run = await waitForRun(
- await runFixture(fixture, legacy),
- 'COMPLETED',
- );
- expect(run.coreWorkflowVersionId).toBe(fixture.coreWorkflowVersionId);
- }
- }
- } finally {
- await flags.upsertWorkspaceFeatureFlag({
- workspaceId,
- featureFlag,
- value: original,
- });
- }
- });
-
- it.each(['core', 'legacy'] as const)(
- 'keeps the published version executable when replacement activation fails through the %s API',
- async (api) => {
- const fixture = await createFixture({
- triggerType: 'CRON',
- triggerSettings: { type: 'CUSTOM', pattern: '* * * * *' },
- });
- const triggerService =
- getAppProviderByClassName<AutomatedTriggerWorkspaceService>(
- 'AutomatedTriggerWorkspaceService',
- );
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
- const activateQuery =
- api === 'core'
- ? 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }'
- : 'mutation Activate($id: UUID!) { activateWorkflowVersion(workflowVersionId: $id) }';
- const firstActivation = await workflowGraphqlRequest(activateQuery, {
- id:
- api === 'core'
- ? fixture.coreWorkflowVersionId
- : fixture.workflowVersionId,
- });
- expect(firstActivation.body.errors).toBeUndefined();
- const cache = global.app.get<CacheStorageService>(
- CacheStorageNamespace.ModuleWorkflow,
- );
- const cronCacheKey = WORKFLOW_CRON_TRIGGER_CACHE_KEY;
- const originalCache = await cache.hashGetValues(cronCacheKey);
- const draftResponse = await workflowGraphqlRequest(
- 'mutation Draft($input: CreateDraftFromCoreWorkflowVersionInput!) { createDraftFromCoreWorkflowVersion(input: $input) { id workspaceWorkflowVersionId } }',
- {
+ const { createDraftFromCoreWorkflowVersion: draft } =
+ await coreWorkflowGraphqlRequest<{
+ createDraftFromCoreWorkflowVersion: { id: string };
+ }>({
+ query:
+ 'mutation Draft($input: CreateDraftFromCoreWorkflowVersionInput!) { createDraftFromCoreWorkflowVersion(input: $input) { id } }',
+ variables: {
input: {
coreWorkflowId: fixture.coreWorkflowId,
coreWorkflowVersionIdToCopy: fixture.coreWorkflowVersionId,
},
},
- );
- expect(draftResponse.body.errors).toBeUndefined();
- const draft = draftResponse.body.data.createDraftFromCoreWorkflowVersion;
- const failure = jest
- .spyOn(triggerService, 'addAutomatedTrigger')
- .mockRejectedValueOnce(new Error('Replacement trigger failure'));
- const response = await workflowGraphqlRequest(activateQuery, {
- id: api === 'core' ? draft.id : draft.workspaceWorkflowVersionId,
- });
- expect(response.body.errors).toBeDefined();
- expect(failure).toHaveBeenCalledTimes(1);
- failure.mockRestore();
- const [oldVersion] = await global.testDataSource.query(
- 'SELECT status FROM core."workflowVersion" WHERE id = $1',
- [fixture.coreWorkflowVersionId],
- );
- const [newVersion] = await global.testDataSource.query(
- 'SELECT status FROM core."workflowVersion" WHERE id = $1',
- [draft.id],
- );
- const [workflow] = await global.testDataSource.query(
- 'SELECT "lastPublishedCoreWorkflowVersionId" FROM core.workflow WHERE id = $1',
- [fixture.coreWorkflowId],
- );
- const [oldMirror] = await global.testDataSource.query(
- `SELECT status FROM "${schema}"."workflowVersion" WHERE id = $1`,
- [fixture.workflowVersionId],
- );
- const triggers = await global.testDataSource.query(
- `SELECT id FROM "${schema}"."workflowAutomatedTrigger" WHERE "workflowId" = $1`,
- [fixture.workflowId],
- );
- expect(oldVersion.status).toBe('ACTIVE');
- expect(oldMirror.status).toBe('ACTIVE');
- expect(newVersion.status).toBe('DRAFT');
- expect(workflow.lastPublishedCoreWorkflowVersionId).toBe(
- fixture.coreWorkflowVersionId,
- );
- expect(triggers).toHaveLength(1);
- expect(await cache.hashGetValues(cronCacheKey)).toEqual(originalCache);
- await waitForRun(await runFixture(fixture), 'COMPLETED');
- const retry = await workflowGraphqlRequest(activateQuery, {
- id: api === 'core' ? draft.id : draft.workspaceWorkflowVersionId,
});
- expect(retry.body.errors).toBeUndefined();
- const versions = await global.testDataSource.query(
- 'SELECT id, status FROM core."workflowVersion" WHERE "coreWorkflowId" = $1',
- [fixture.coreWorkflowId],
- );
- expect(versions).toEqual(
- expect.arrayContaining([
- { id: fixture.coreWorkflowVersionId, status: 'ARCHIVED' },
- { id: draft.id, status: 'ACTIVE' },
- ]),
- );
- },
- );
- it.each(['core', 'legacy'] as const)(
- 'rejects a draft edited while the %s API prepares activation',
- async (api) => {
- const fixture = await createFixture();
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
- const codeBuild = getAppProviderByClassName<CodeStepBuildService>(
- 'CodeStepBuildService',
+ await updateCoreWorkflowVersionTrigger({
+ coreWorkflowVersionId: draft.id,
+ trigger: { ...fixture.trigger, name: 'B-Async edited' },
+ });
+ await activateCoreWorkflowVersion({ coreWorkflowVersionId: draft.id });
+ fixture.coreWorkflowVersionId = draft.id;
+
+ const run = await waitForRun(await runFixture(fixture), 'COMPLETED');
+
+ expect(run.coreWorkflowVersionId).toBe(draft.id);
+ });
+
+ it('keeps the published version executable when replacement activation fails', async () => {
+ const fixture = await createFixture({
+ triggerType: 'CRON',
+ triggerSettings: { type: 'CUSTOM', pattern: '* * * * *' },
+ });
+ const triggerService =
+ getAppProviderByClassName<AutomatedTriggerWorkspaceService>(
+ 'AutomatedTriggerWorkspaceService',
);
- let notifyPreparing: () => void = () => {};
- let releasePreparation: () => void = () => {};
- const preparing = new Promise<void>((resolve) => {
- notifyPreparing = resolve;
- });
- const prepared = new Promise<void>((resolve) => {
- releasePreparation = resolve;
- });
- const buildSpy = jest
- .spyOn(codeBuild, 'switchCodeStepLogicFunctionsToPrebuilt')
- .mockImplementationOnce(async () => {
- notifyPreparing();
- await prepared;
- });
- const activation = workflowGraphqlRequest(
- api === 'core'
- ? 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }'
- : 'mutation Activate($id: UUID!) { activateWorkflowVersion(workflowVersionId: $id) }',
- {
- id:
- api === 'core'
- ? fixture.coreWorkflowVersionId
- : fixture.workflowVersionId,
+ await global.testDataSource.query(
+ `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.coreWorkflowVersionId],
+ );
+ await global.testDataSource.query(
+ `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.workflowVersionId],
+ );
+ const activateQuery =
+ 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }';
+ const firstActivation = await workflowGraphqlRequest(activateQuery, {
+ id: fixture.coreWorkflowVersionId,
+ });
+ expect(firstActivation.body.errors).toBeUndefined();
+ const cache = global.app.get<CacheStorageService>(
+ CacheStorageNamespace.ModuleWorkflow,
+ );
+ const cronCacheKey = WORKFLOW_CRON_TRIGGER_CACHE_KEY;
+ const originalCache = await cache.hashGetValues(cronCacheKey);
+ const draftResponse = await workflowGraphqlRequest(
+ 'mutation Draft($input: CreateDraftFromCoreWorkflowVersionInput!) { createDraftFromCoreWorkflowVersion(input: $input) { id } }',
+ {
+ input: {
+ coreWorkflowId: fixture.coreWorkflowId,
+ coreWorkflowVersionIdToCopy: fixture.coreWorkflowVersionId,
},
- ).then((response) => response);
- try {
- await preparing;
- const edit = await workflowGraphqlRequest(
- 'mutation Edit($input: UpdateCoreWorkflowVersionTriggerInput!) { updateCoreWorkflowVersionTrigger(input: $input) { trigger } }',
- {
- input: {
- coreWorkflowVersionId: fixture.coreWorkflowVersionId,
- trigger: { ...fixture.trigger, name: 'Edited during activation' },
- },
- },
- );
- expect(edit.body.errors).toBeUndefined();
- } finally {
- releasePreparation();
- buildSpy.mockRestore();
- }
- expect(JSON.stringify((await activation).body.errors)).toContain(
- 'changed',
- );
- const [core] = await global.testDataSource.query(
- 'SELECT status, triggers FROM core."workflowVersion" WHERE id = $1',
- [fixture.coreWorkflowVersionId],
- );
- expect(core.status).toBe('DRAFT');
- expect(core.triggers[0].name).toBe('Edited during activation');
- },
- );
+ },
+ );
+ expect(draftResponse.body.errors).toBeUndefined();
+ const draft = draftResponse.body.data.createDraftFromCoreWorkflowVersion;
+ const failure = jest
+ .spyOn(triggerService, 'addAutomatedTrigger')
+ .mockRejectedValueOnce(new Error('Replacement trigger failure'));
+ const response = await workflowGraphqlRequest(activateQuery, {
+ id: draft.id,
+ });
+ expect(response.body.errors).toBeDefined();
+ expect(failure).toHaveBeenCalledTimes(1);
+ failure.mockRestore();
+ const [oldVersion] = await global.testDataSource.query(
+ 'SELECT status FROM core."workflowVersion" WHERE id = $1',
+ [fixture.coreWorkflowVersionId],
+ );
+ const [newVersion] = await global.testDataSource.query(
+ 'SELECT status FROM core."workflowVersion" WHERE id = $1',
+ [draft.id],
+ );
+ const [workflow] = await global.testDataSource.query(
+ 'SELECT "lastPublishedCoreWorkflowVersionId" FROM core.workflow WHERE id = $1',
+ [fixture.coreWorkflowId],
+ );
+ const [oldMirror] = await global.testDataSource.query(
+ `SELECT status FROM "${schema}"."workflowVersion" WHERE id = $1`,
+ [fixture.workflowVersionId],
+ );
+ const triggers = await global.testDataSource.query(
+ `SELECT id FROM "${schema}"."workflowAutomatedTrigger" WHERE "workflowId" = $1`,
+ [fixture.workflowId],
+ );
+ expect(oldVersion.status).toBe('ACTIVE');
+ expect(oldMirror.status).toBe('ACTIVE');
+ expect(newVersion.status).toBe('DRAFT');
+ expect(workflow.lastPublishedCoreWorkflowVersionId).toBe(
+ fixture.coreWorkflowVersionId,
+ );
+ expect(triggers).toHaveLength(1);
+ expect(await cache.hashGetValues(cronCacheKey)).toEqual(originalCache);
+ await waitForRun(await runFixture(fixture), 'COMPLETED');
+ const retry = await workflowGraphqlRequest(activateQuery, {
+ id: draft.id,
+ });
+ expect(retry.body.errors).toBeUndefined();
+ const versions = await global.testDataSource.query(
+ 'SELECT id, status FROM core."workflowVersion" WHERE "coreWorkflowId" = $1',
+ [fixture.coreWorkflowId],
+ );
+ expect(versions).toEqual(
+ expect.arrayContaining([
+ { id: fixture.coreWorkflowVersionId, status: 'ARCHIVED' },
+ { id: draft.id, status: 'ACTIVE' },
+ ]),
+ );
+ });
- it.each(['core', 'legacy'] as const)(
- 'rebuilds cron dispatch after a cache publication failure through the %s API',
- async (api) => {
- const fixture = await createFixture({
- triggerType: 'CRON',
- triggerSettings: { type: 'CUSTOM', pattern: '* * * * *' },
- });
- await global.testDataSource.query(
- `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.coreWorkflowVersionId],
- );
- await global.testDataSource.query(
- `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
- [fixture.workflowVersionId],
- );
- const cache = global.app.get<CacheStorageService>(
- CacheStorageNamespace.ModuleWorkflow,
- );
- await cache.hashSet({
- key: WORKFLOW_CRON_TRIGGER_CACHE_KEY,
- field: 'b-async-rebuild-test',
- value: '{}',
+ it('rejects a draft edited while activation is being prepared', async () => {
+ const fixture = await createFixture();
+ await global.testDataSource.query(
+ `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.coreWorkflowVersionId],
+ );
+ await global.testDataSource.query(
+ `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.workflowVersionId],
+ );
+ const codeBuild = getAppProviderByClassName<CodeStepBuildService>(
+ 'CodeStepBuildService',
+ );
+ let notifyPreparing: () => void = () => {};
+ let releasePreparation: () => void = () => {};
+ const preparing = new Promise<void>((resolve) => {
+ notifyPreparing = resolve;
+ });
+ const prepared = new Promise<void>((resolve) => {
+ releasePreparation = resolve;
+ });
+ const buildSpy = jest
+ .spyOn(codeBuild, 'switchCodeStepLogicFunctionsToPrebuilt')
+ .mockImplementationOnce(async () => {
+ notifyPreparing();
+ await prepared;
});
- const publication = jest
- .spyOn(cache, 'hashSetIfExists')
- .mockRejectedValueOnce(new Error('Cron cache publication failure'));
- const response = await workflowGraphqlRequest(
- api === 'core'
- ? 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }'
- : 'mutation Activate($id: UUID!) { activateWorkflowVersion(workflowVersionId: $id) }',
+ const activation = workflowGraphqlRequest(
+ 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }',
+ { id: fixture.coreWorkflowVersionId },
+ ).then((response) => response);
+ try {
+ await preparing;
+ const edit = await workflowGraphqlRequest(
+ 'mutation Edit($input: UpdateCoreWorkflowVersionTriggerInput!) { updateCoreWorkflowVersionTrigger(input: $input) { trigger } }',
{
- id:
- api === 'core'
- ? fixture.coreWorkflowVersionId
- : fixture.workflowVersionId,
+ input: {
+ coreWorkflowVersionId: fixture.coreWorkflowVersionId,
+ trigger: { ...fixture.trigger, name: 'Edited during activation' },
+ },
},
);
- expect(response.body.errors).toBeUndefined();
- expect(publication).toHaveBeenCalledTimes(1);
- publication.mockRestore();
- expect(
- await cache.hashGetValues(WORKFLOW_CRON_TRIGGER_CACHE_KEY),
- ).toEqual([]);
- await global.workflowTestServices.cron.handle();
- const entries = await cache.hashGetValues(
- WORKFLOW_CRON_TRIGGER_CACHE_KEY,
- );
- expect(entries.map((entry) => JSON.parse(entry))).toEqual(
- expect.arrayContaining([
- expect.objectContaining({
- coreWorkflowVersionId: fixture.coreWorkflowVersionId,
- }),
- ]),
+ expect(edit.body.errors).toBeUndefined();
+ } finally {
+ releasePreparation();
+ buildSpy.mockRestore();
+ }
+ expect(JSON.stringify((await activation).body.errors)).toContain('changed');
+ const [core] = await global.testDataSource.query(
+ 'SELECT status, triggers FROM core."workflowVersion" WHERE id = $1',
+ [fixture.coreWorkflowVersionId],
+ );
+ expect(core.status).toBe('DRAFT');
+ expect(core.triggers[0].name).toBe('Edited during activation');
+ });
+
+ it('rebuilds cron dispatch after a cache publication failure', async () => {
+ const fixture = await createFixture({
+ triggerType: 'CRON',
+ triggerSettings: { type: 'CUSTOM', pattern: '* * * * *' },
+ });
+ await global.testDataSource.query(
+ `UPDATE core."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.coreWorkflowVersionId],
+ );
+ await global.testDataSource.query(
+ `UPDATE "${schema}"."workflowVersion" SET status = 'DRAFT' WHERE id = $1`,
+ [fixture.workflowVersionId],
+ );
+ const cache = global.app.get<CacheStorageService>(
+ CacheStorageNamespace.ModuleWorkflow,
+ );
+ await cache.hashSet({
+ key: WORKFLOW_CRON_TRIGGER_CACHE_KEY,
+ field: 'b-async-rebuild-test',
+ value: '{}',
+ });
+ const publication = jest
+ .spyOn(cache, 'hashSetIfExists')
+ .mockRejectedValueOnce(new Error('Cron cache publication failure'));
+ const response = await workflowGraphqlRequest(
+ 'mutation Activate($id: UUID!) { activateCoreWorkflowVersion(coreWorkflowVersionId: $id) }',
+ { id: fixture.coreWorkflowVersionId },
+ );
+ expect(response.body.errors).toBeUndefined();
+ expect(publication).toHaveBeenCalledTimes(1);
+ publication.mockRestore();
+ expect(await cache.hashGetValues(WORKFLOW_CRON_TRIGGER_CACHE_KEY)).toEqual(
+ [],
+ );
+ await global.workflowTestServices.cron.handle();
+ const entries = await cache.hashGetValues(WORKFLOW_CRON_TRIGGER_CACHE_KEY);
+ expect(entries.map((entry) => JSON.parse(entry))).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ coreWorkflowVersionId: fixture.coreWorkflowVersionId,
+ }),
+ ]),
+ );
+ for (let attempt = 0; attempt < 100; attempt++) {
+ const runs = await global.testDataSource.query(
+ `SELECT id FROM "${schema}"."workflowRun" WHERE "coreWorkflowId" = $1`,
+ [fixture.coreWorkflowId],
);
- for (let attempt = 0; attempt < 100; attempt++) {
- const runs = await global.testDataSource.query(
- `SELECT id FROM "${schema}"."workflowRun" WHERE "coreWorkflowId" = $1`,
- [fixture.coreWorkflowId],
- );
- if (runs.length > 0) {
- await waitForRun(runs[0].id, 'COMPLETED');
- return;
- }
- await new Promise((resolve) => setTimeout(resolve, 100));
+ if (runs.length > 0) {
+ await waitForRun(runs[0].id, 'COMPLETED');
+ return;
}
- throw new Error(
- 'Rebuilt cron cache did not dispatch the activated workflow',
- );
- },
- );
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ }
+ throw new Error(
+ 'Rebuilt cron cache did not dispatch the activated workflow',
+ );
+ });
it('rejects an overlapping builder edit without losing the successful edit and accepts a fresh retry', async () => {
const fixture = await createFixture();
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/database-event-trigger-filter.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/database-event-trigger-filter.integration-spec.ts
index f899d992e62..d75e000e9e0 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/database-event-trigger-filter.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/database-event-trigger-filter.integration-spec.ts
@@ -1,4 +1,11 @@
import request from 'supertest';
+import {
+ activateCoreWorkflowVersion,
+ createCoreWorkflow,
+ createCoreWorkflowVersionStep,
+ deleteCoreWorkflows,
+ updateCoreWorkflowVersionTrigger,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
const client = request(`http://localhost:${APP_PORT}`);
@@ -25,42 +32,18 @@ const graphql = (query: string, variables?: object) =>
.send({ query, variables });
describe('Database event trigger filter (e2e)', () => {
- let createdWorkflowId: string | null = null;
- let createdWorkflowVersionId: string | null = null;
+ let coreWorkflowId: string | null = null;
+ let workspaceWorkflowId: string | null = null;
beforeAll(async () => {
- const createWorkflowResponse = await graphql(`
- mutation CreateWorkflow {
- createWorkflow(data: { name: "DB Event Trigger Filter Test" }) {
- id
- }
- }
- `);
-
- expect(createWorkflowResponse.body.errors).toBeUndefined();
- createdWorkflowId = createWorkflowResponse.body.data.createWorkflow.id;
+ const createdCoreWorkflow = await createCoreWorkflow({
+ name: 'DB Event Trigger Filter Test',
+ });
- const getWorkflowResponse = await graphql(
- `
- query GetWorkflow($id: UUID!) {
- workflow(filter: { id: { eq: $id } }) {
- id
- versions {
- edges {
- node {
- id
- }
- }
- }
- }
- }
- `,
- { id: createdWorkflowId },
- );
+ coreWorkflowId = createdCoreWorkflow.coreWorkflowId;
+ workspaceWorkflowId = createdCoreWorkflow.workspaceWorkflowId;
- expect(getWorkflowResponse.body.errors).toBeUndefined();
- createdWorkflowVersionId =
- getWorkflowResponse.body.data.workflow.versions.edges[0].node.id;
+ const coreWorkflowVersionId = createdCoreWorkflow.coreWorkflowVersionId;
const databaseEventTrigger = {
name: 'Company is created',
@@ -88,73 +71,22 @@ describe('Database event trigger filter (e2e)', () => {
position: { x: 0, y: 0 },
};
- const updateTriggerResponse = await graphql(
- `
- mutation UpdateWorkflowVersionTrigger(
- $input: UpdateWorkflowVersionTriggerInput!
- ) {
- updateWorkflowVersionTrigger(input: $input) {
- trigger
- }
- }
- `,
- {
- input: {
- workflowVersionId: createdWorkflowVersionId,
- trigger: databaseEventTrigger,
- },
- },
- );
-
- expect(updateTriggerResponse.body.errors).toBeUndefined();
-
- const createStepResponse = await graphql(
- `
- mutation CreateWorkflowVersionStep(
- $input: CreateWorkflowVersionStepInput!
- ) {
- createWorkflowVersionStep(input: $input) {
- stepsDiff
- }
- }
- `,
- {
- input: {
- workflowVersionId: createdWorkflowVersionId,
- stepType: 'CODE',
- parentStepId: 'trigger',
- position: { x: 200, y: 0 },
- },
- },
- );
-
- expect(createStepResponse.body.errors).toBeUndefined();
+ await updateCoreWorkflowVersionTrigger({
+ coreWorkflowVersionId,
+ trigger: databaseEventTrigger,
+ });
- const activateResponse = await graphql(
- `
- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {
- activateWorkflowVersion(workflowVersionId: $workflowVersionId)
- }
- `,
- { workflowVersionId: createdWorkflowVersionId },
- );
+ await createCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ stepType: 'CODE',
+ });
- expect(activateResponse.body.errors).toBeUndefined();
- expect(activateResponse.body.data.activateWorkflowVersion).toBe(true);
+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });
});
afterAll(async () => {
- if (createdWorkflowId) {
- await graphql(
- `
- mutation DestroyWorkflow($id: ID!) {
- destroyWorkflow(id: $id) {
- id
- }
- }
- `,
- { id: createdWorkflowId },
- );
+ if (coreWorkflowId) {
+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });
}
});
@@ -175,7 +107,7 @@ describe('Database event trigger filter (e2e)', () => {
}
}
`,
- { workflowId: createdWorkflowId },
+ { workflowId: workspaceWorkflowId },
);
expect(response.body.errors).toBeUndefined();
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/quick-lead-workflow.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/quick-lead-workflow.integration-spec.ts
index d58dd0ea59a..a992e78836a 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/quick-lead-workflow.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/quick-lead-workflow.integration-spec.ts
@@ -1,9 +1,9 @@
import request from 'supertest';
+import { runCoreWorkflowVersion } from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import { submitFormStep } from 'test/integration/graphql/suites/workflow/utils/submit-form-step.util';
import {
destroyWorkflowRun,
getWorkflowRun,
- runWorkflowVersion,
waitForWorkflowCompletion,
waitForWorkflowRunStatus,
waitForWorkflowRunStepStatus,
@@ -18,6 +18,7 @@ const client = request(`http://localhost:${APP_PORT}`);
const {
quickLeadWorkflowId: QUICK_LEAD_WORKFLOW_ID,
quickLeadWorkflowVersionId: QUICK_LEAD_WORKFLOW_VERSION_ID,
+ coreQuickLeadWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
} = getWorkflowPrefillIds(SEED_APPLE_WORKSPACE_ID);
const FORM_STEP_ID = '6e089bc9-aabd-435f-865f-f31c01c8f4a7';
@@ -122,8 +123,8 @@ describe('Quick Lead Workflow (e2e)', () => {
});
it('should trigger Quick Lead workflow and create workflow run', async () => {
- const workflowRunId = await runWorkflowVersion({
- workflowVersionId: QUICK_LEAD_WORKFLOW_VERSION_ID,
+ const workflowRunId = await runCoreWorkflowVersion({
+ coreWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
});
createdWorkflowRunId = workflowRunId;
@@ -167,8 +168,8 @@ describe('Quick Lead Workflow (e2e)', () => {
});
it('should be able to stop a running workflow run', async () => {
- const workflowRunId = await runWorkflowVersion({
- workflowVersionId: QUICK_LEAD_WORKFLOW_VERSION_ID,
+ const workflowRunId = await runCoreWorkflowVersion({
+ coreWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
});
const stopResponse = await client
@@ -240,8 +241,8 @@ describe('Quick Lead Workflow (e2e)', () => {
});
it('should complete full workflow: trigger → submit form → create Company and Person', async () => {
- testWorkflowRunId = await runWorkflowVersion({
- workflowVersionId: QUICK_LEAD_WORKFLOW_VERSION_ID,
+ testWorkflowRunId = await runCoreWorkflowVersion({
+ coreWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
});
expect(testWorkflowRunId).toBeDefined();
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts
new file mode 100644
index 00000000000..7f817ade851
--- /dev/null
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/core-workflow.util.ts
@@ -0,0 +1,340 @@
+import request from 'supertest';
+import { isDefined } from 'twenty-shared/utils';
+
+const client = request(`http://localhost:${APP_PORT}`);
+
+type CoreWorkflowStep = {
+ id: string;
+ type: string;
+ name?: string;
+ settings: { input: Record<string, unknown> } & Record<string, unknown>;
+ nextStepIds?: string[] | null;
+} & Record<string, unknown>;
+
+export type CoreWorkflowVersion = {
+ id: string;
+ coreWorkflowId: string;
+ status: string;
+ trigger: Record<string, unknown> | null;
+ steps: CoreWorkflowStep[] | null;
+ workspaceWorkflowVersionId: string | null;
+};
+
+const CORE_WORKFLOW_VERSION_FIELDS = `
+ id
+ coreWorkflowId
+ status
+ trigger
+ steps
+ workspaceWorkflowVersionId
+`;
+
+export const coreWorkflowGraphqlRequest = async <TData>({
+ query,
+ variables,
+ token = APPLE_JANE_ADMIN_ACCESS_TOKEN,
+}: {
+ query: string;
+ variables?: object;
+ token?: string;
+}): Promise<TData> => {
+ const response = await client
+ .post('/graphql')
+ .set('Authorization', `Bearer ${token}`)
+ .send({ query, variables });
+
+ if (response.body.errors) {
+ throw new Error(
+ `Core workflow request failed: ${JSON.stringify(response.body.errors)}`,
+ );
+ }
+
+ return response.body.data;
+};
+
+export const createCoreWorkflow = async ({
+ name,
+ token,
+}: {
+ name: string;
+ token?: string;
+}): Promise<{
+ coreWorkflowId: string;
+ coreWorkflowVersionId: string;
+ workspaceWorkflowId: string | null;
+}> => {
+ const { createCoreWorkflow: coreWorkflow } =
+ await coreWorkflowGraphqlRequest<{
+ createCoreWorkflow: { id: string; workspaceWorkflowId: string | null };
+ }>({
+ query: `
+ mutation CreateCoreWorkflow($input: CreateCoreWorkflowInput!) {
+ createCoreWorkflow(input: $input) {
+ id
+ workspaceWorkflowId
+ }
+ }
+ `,
+ variables: { input: { name } },
+ token,
+ });
+
+ const [draftVersion] = await findCoreWorkflowVersions({
+ coreWorkflowId: coreWorkflow.id,
+ token,
+ });
+
+ return {
+ coreWorkflowId: coreWorkflow.id,
+ coreWorkflowVersionId: draftVersion.id,
+ workspaceWorkflowId: coreWorkflow.workspaceWorkflowId,
+ };
+};
+
+export const findCoreWorkflowVersions = async ({
+ coreWorkflowId,
+ token,
+}: {
+ coreWorkflowId: string;
+ token?: string;
+}): Promise<CoreWorkflowVersion[]> => {
+ const { coreWorkflowVersionsByCoreWorkflowId } =
+ await coreWorkflowGraphqlRequest<{
+ coreWorkflowVersionsByCoreWorkflowId: CoreWorkflowVersion[];
+ }>({
+ query: `
+ query CoreWorkflowVersions($coreWorkflowId: UUID!) {
+ coreWorkflowVersionsByCoreWorkflowId(coreWorkflowId: $coreWorkflowId) {
+ ${CORE_WORKFLOW_VERSION_FIELDS}
+ }
+ }
+ `,
+ variables: { coreWorkflowId },
+ token,
+ });
+
+ return coreWorkflowVersionsByCoreWorkflowId;
+};
+
+export const findCoreWorkflowVersion = async ({
+ coreWorkflowVersionId,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ token?: string;
+}): Promise<CoreWorkflowVersion> => {
+ const { coreWorkflowVersionById } = await coreWorkflowGraphqlRequest<{
+ coreWorkflowVersionById: CoreWorkflowVersion;
+ }>({
+ query: `
+ query CoreWorkflowVersion($coreWorkflowVersionId: UUID!) {
+ coreWorkflowVersionById(coreWorkflowVersionId: $coreWorkflowVersionId) {
+ ${CORE_WORKFLOW_VERSION_FIELDS}
+ }
+ }
+ `,
+ variables: { coreWorkflowVersionId },
+ token,
+ });
+
+ return coreWorkflowVersionById;
+};
+
+export const updateCoreWorkflowVersionTrigger = async ({
+ coreWorkflowVersionId,
+ trigger,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ trigger: object;
+ token?: string;
+}): Promise<void> => {
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation UpdateCoreWorkflowVersionTrigger(
+ $input: UpdateCoreWorkflowVersionTriggerInput!
+ ) {
+ updateCoreWorkflowVersionTrigger(input: $input) {
+ trigger
+ }
+ }
+ `,
+ variables: { input: { coreWorkflowVersionId, trigger } },
+ token,
+ });
+};
+
+export const createCoreWorkflowVersionStep = async ({
+ coreWorkflowVersionId,
+ stepType,
+ parentStepId = 'trigger',
+ position = { x: 200, y: 0 },
+ token,
+ ...rest
+}: {
+ coreWorkflowVersionId: string;
+ stepType: string;
+ parentStepId?: string;
+ position?: { x: number; y: number };
+ token?: string;
+ id?: string;
+ nextStepId?: string;
+ parentStepConnectionOptions?: object;
+ defaultSettings?: object;
+}): Promise<CoreWorkflowStep> => {
+ const { steps: previousSteps } = await findCoreWorkflowVersion({
+ coreWorkflowVersionId,
+ token,
+ });
+ const previousStepIds = new Set((previousSteps ?? []).map((step) => step.id));
+
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation CreateCoreWorkflowVersionStep(
+ $input: CreateCoreWorkflowVersionStepInput!
+ ) {
+ createCoreWorkflowVersionStep(input: $input) {
+ stepsDiff
+ }
+ }
+ `,
+ variables: {
+ input: {
+ coreWorkflowVersionId,
+ stepType,
+ parentStepId,
+ position,
+ ...rest,
+ },
+ },
+ token,
+ });
+
+ const { steps } = await findCoreWorkflowVersion({
+ coreWorkflowVersionId,
+ token,
+ });
+
+ const createdStep = (steps ?? []).find((step) =>
+ isDefined(rest.id)
+ ? step.id === rest.id
+ : step.type === stepType && !previousStepIds.has(step.id),
+ );
+
+ if (!isDefined(createdStep)) {
+ throw new Error(`Step of type ${stepType} was not created`);
+ }
+
+ return createdStep;
+};
+
+export const updateCoreWorkflowVersionStep = async ({
+ coreWorkflowVersionId,
+ step,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ step: object;
+ token?: string;
+}): Promise<void> => {
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation UpdateCoreWorkflowVersionStep(
+ $input: UpdateCoreWorkflowVersionStepInput!
+ ) {
+ updateCoreWorkflowVersionStep(input: $input) {
+ id
+ }
+ }
+ `,
+ variables: { input: { coreWorkflowVersionId, step } },
+ token,
+ });
+};
+
+export const activateCoreWorkflowVersion = async ({
+ coreWorkflowVersionId,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ token?: string;
+}): Promise<void> => {
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation ActivateCoreWorkflowVersion($coreWorkflowVersionId: UUID!) {
+ activateCoreWorkflowVersion(coreWorkflowVersionId: $coreWorkflowVersionId)
+ }
+ `,
+ variables: { coreWorkflowVersionId },
+ token,
+ });
+};
+
+export const deactivateCoreWorkflowVersion = async ({
+ coreWorkflowVersionId,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ token?: string;
+}): Promise<void> => {
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation DeactivateCoreWorkflowVersion($coreWorkflowVersionId: UUID!) {
+ deactivateCoreWorkflowVersion(
+ coreWorkflowVersionId: $coreWorkflowVersionId
+ )
+ }
+ `,
+ variables: { coreWorkflowVersionId },
+ token,
+ });
+};
+
+export const runCoreWorkflowVersion = async ({
+ coreWorkflowVersionId,
+ payload,
+ workflowRunId,
+ token,
+}: {
+ coreWorkflowVersionId: string;
+ payload?: object;
+ workflowRunId?: string;
+ token?: string;
+}): Promise<string> => {
+ const { runCoreWorkflowVersion: runResult } =
+ await coreWorkflowGraphqlRequest<{
+ runCoreWorkflowVersion: { workflowRunId: string };
+ }>({
+ query: `
+ mutation RunCoreWorkflowVersion($input: RunCoreWorkflowVersionInput!) {
+ runCoreWorkflowVersion(input: $input) {
+ workflowRunId
+ }
+ }
+ `,
+ variables: { input: { coreWorkflowVersionId, payload, workflowRunId } },
+ token,
+ });
+
+ return runResult.workflowRunId;
+};
+
+export const deleteCoreWorkflows = async ({
+ coreWorkflowIds,
+ token,
+}: {
+ coreWorkflowIds: string[];
+ token?: string;
+}): Promise<void> => {
+ await coreWorkflowGraphqlRequest({
+ query: `
+ mutation DeleteCoreWorkflows($input: DeleteCoreWorkflowsInput!) {
+ deleteCoreWorkflows(input: $input) {
+ id
+ }
+ }
+ `,
+ variables: { input: { coreWorkflowIds } },
+ token,
+ });
+};
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-webhook-triggered-action-step.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-webhook-triggered-action-step.util.ts
index 664bf886aca..88acf219d2d 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-webhook-triggered-action-step.util.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-webhook-triggered-action-step.util.ts
@@ -1,22 +1,21 @@
-import gql from 'graphql-tag';
import request from 'supertest';
-
-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ activateCoreWorkflowVersion,
+ createCoreWorkflow,
+ createCoreWorkflowVersionStep,
+ deleteCoreWorkflows,
+ updateCoreWorkflowVersionStep,
+ updateCoreWorkflowVersionTrigger,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import {
destroyWorkflowRun,
waitForWorkflowCompletion,
type WorkflowRunStatusType,
} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
-import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
-type WorkflowVersionStep = {
- id: string;
- type: string;
- settings: { input: Record<string, unknown> };
-};
-
export type WebhookTriggeredActionStepRun = {
status?: WorkflowRunStatusType;
stepStatus?: string;
@@ -33,51 +32,15 @@ export const runWebhookTriggeredActionStep = async ({
stepType: 'SEND_EMAIL' | 'DRAFT_EMAIL';
input: Record<string, unknown>;
}): Promise<WebhookTriggeredActionStepRun> => {
- const createWorkflowResponse = await makeGraphqlApiRequest({
- query: gql`
- mutation CreateWorkflow($name: String!) {
- createWorkflow(data: { name: $name }) {
- id
- }
- }
- `,
- variables: { name },
+ const { coreWorkflowId, coreWorkflowVersionId } = await createCoreWorkflow({
+ name,
});
- expect(createWorkflowResponse.body.errors).toBeUndefined();
-
- const workflowId = createWorkflowResponse.body.data.createWorkflow.id;
-
let workflowRunId: string | undefined;
try {
- const workflowVersionsResponse = await makeGraphqlApiRequest({
- query: gql`
- query FindDraftWorkflowVersion($workflowId: UUID!) {
- workflowVersions(
- filter: {
- workflowId: { eq: $workflowId }
- status: { in: ["DRAFT"] }
- }
- ) {
- edges {
- node {
- id
- }
- }
- }
- }
- `,
- variables: { workflowId },
- });
-
- expect(workflowVersionsResponse.body.errors).toBeUndefined();
-
- const workflowVersionId =
- workflowVersionsResponse.body.data.workflowVersions.edges[0].node.id;
-
- await updateWorkflowVersionTrigger({
- workflowVersionId,
+ await updateCoreWorkflowVersionTrigger({
+ coreWorkflowVersionId,
trigger: {
name: 'Webhook Trigger',
type: 'WEBHOOK',
@@ -91,88 +54,26 @@ export const runWebhookTriggeredActionStep = async ({
},
});
- const createStepResponse = await makeGraphqlApiRequest({
- query: gql`
- mutation CreateWorkflowVersionStep(
- $input: CreateWorkflowVersionStepInput!
- ) {
- createWorkflowVersionStep(input: $input) {
- stepsDiff
- }
- }
- `,
- variables: {
- input: {
- workflowVersionId,
- stepType,
- parentStepId: 'trigger',
- position: { x: 200, y: 0 },
- },
- },
+ const step = await createCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ stepType,
});
- expect(createStepResponse.body.errors).toBeUndefined();
-
- const stepsResponse = await makeGraphqlApiRequest({
- query: gql`
- query FindWorkflowVersionSteps($workflowVersionId: UUID!) {
- workflowVersion(filter: { id: { eq: $workflowVersionId } }) {
- steps
- }
- }
- `,
- variables: { workflowVersionId },
- });
-
- expect(stepsResponse.body.errors).toBeUndefined();
-
- const step: WorkflowVersionStep =
- stepsResponse.body.data.workflowVersion.steps.find(
- (workflowVersionStep: WorkflowVersionStep) =>
- workflowVersionStep.type === stepType,
- );
-
- expect(step).toBeDefined();
-
- const updateStepResponse = await makeGraphqlApiRequest({
- query: gql`
- mutation UpdateWorkflowVersionStep(
- $input: UpdateWorkflowVersionStepInput!
- ) {
- updateWorkflowVersionStep(input: $input) {
- id
- }
- }
- `,
- variables: {
- input: {
- workflowVersionId,
- step: {
- ...step,
- settings: {
- ...step.settings,
- input: { ...step.settings.input, ...input },
- },
- },
+ await updateCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ step: {
+ ...step,
+ settings: {
+ ...step.settings,
+ input: { ...step.settings.input, ...input },
},
},
});
- expect(updateStepResponse.body.errors).toBeUndefined();
-
- const activateResponse = await makeGraphqlApiRequest({
- query: gql`
- mutation ActivateWorkflowVersion($workflowVersionId: UUID!) {
- activateWorkflowVersion(workflowVersionId: $workflowVersionId)
- }
- `,
- variables: { workflowVersionId },
- });
-
- expect(activateResponse.body.errors).toBeUndefined();
+ await activateCoreWorkflowVersion({ coreWorkflowVersionId });
const webhookResponse = await request(`http://localhost:${APP_PORT}`).get(
- `/webhooks/workflows/${SEED_APPLE_WORKSPACE_ID}/${workflowId}`,
+ `/webhooks/workflows/${SEED_APPLE_WORKSPACE_ID}/${coreWorkflowId}`,
);
expect(webhookResponse.body.success).toBe(true);
@@ -189,19 +90,10 @@ export const runWebhookTriggeredActionStep = async ({
stepError: stepInfo?.error,
};
} finally {
- if (workflowRunId !== undefined) {
+ if (isDefined(workflowRunId)) {
await destroyWorkflowRun(workflowRunId);
}
- await makeGraphqlApiRequest({
- query: gql`
- mutation DestroyWorkflow($id: ID!) {
- destroyWorkflow(id: $id) {
- id
- }
- }
- `,
- variables: { id: workflowId },
- });
+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });
}
};
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts
index 3e3a7447f84..89bf960cae1 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util.ts
@@ -1,13 +1,17 @@
-import gql from 'graphql-tag';
-import { updateWorkflowVersionTrigger } from 'test/integration/graphql/suites/workflow/utils/update-workflow-version-trigger.util';
import { isDefined } from 'twenty-shared/utils';
+import {
+ createCoreWorkflow,
+ createCoreWorkflowVersionStep,
+ deleteCoreWorkflows,
+ runCoreWorkflowVersion,
+ updateCoreWorkflowVersionStep,
+ updateCoreWorkflowVersionTrigger,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import {
destroyWorkflowRun,
- runWorkflowVersion,
waitForWorkflowCompletion,
type WorkflowRunStatusType,
} from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
-import { makeGraphqlApiRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
type WorkflowActionStepType =
| 'SEND_EMAIL'
@@ -18,12 +22,6 @@ type WorkflowActionStepType =
| 'UPDATE_RECORD'
| 'CODE';
-type WorkflowVersionStep = {
- id: string;
- type: string;
- settings: { input: Record<string, unknown> };
-};
-
export type WorkflowActionStepRun = {
status?: WorkflowRunStatusType;
stepStatus?: string;
@@ -31,157 +29,6 @@ export type WorkflowActionStepRun = {
stepError?: string;
};
-const createWorkflow = async (name: string): Promise<string> => {
- const response = await makeGraphqlApiRequest({
- query: gql`
- mutation CreateWorkflow($name: String!) {
- createWorkflow(data: { name: $name }) {
- id
- }
- }
- `,
- variables: { name },
- });
-
- expect(response.body.errors).toBeUndefined();
-
- return response.body.data.createWorkflow.id;
-};
-
-const destroyWorkflow = async (workflowId: string): Promise<void> => {
- await makeGraphqlApiRequest({
- query: gql`
- mutation DestroyWorkflow($id: ID!) {
- destroyWorkflow(id: $id) {
- id
- }
- }
- `,
- variables: { id: workflowId },
- });
-};
-
-const findDraftWorkflowVersionId = async (
- workflowId: string,
-): Promise<string> => {
- const response = await makeGraphqlApiRequest({
- query: gql`
- query FindDraftWorkflowVersion($workflowId: UUID!) {
- workflowVersions(
- filter: { workflowId: { eq: $workflowId }, status: { in: ["DRAFT"] } }
- ) {
- edges {
- node {
- id
- }
- }
- }
- }
- `,
- variables: { workflowId },
- });
-
- expect(response.body.errors).toBeUndefined();
-
- return response.body.data.workflowVersions.edges[0].node.id;
-};
-
-const createWorkflowVersionStep = async ({
- workflowVersionId,
- stepType,
-}: {
- workflowVersionId: string;
- stepType: WorkflowActionStepType;
-}): Promise<void> => {
- const response = await makeGraphqlApiRequest({
- query: gql`
- mutation CreateWorkflowVersionStep(
- $input: CreateWorkflowVersionStepInput!
- ) {
- createWorkflowVersionStep(input: $input) {
- stepsDiff
- }
- }
- `,
- variables: {
- input: {
- workflowVersionId,
- stepType,
- parentStepId: 'trigger',
- position: { x: 200, y: 0 },
- },
- },
- });
-
- expect(response.body.errors).toBeUndefined();
-};
-
-const findWorkflowVersionStep = async ({
- workflowVersionId,
- stepType,
-}: {
- workflowVersionId: string;
- stepType: WorkflowActionStepType;
-}): Promise<WorkflowVersionStep> => {
- const response = await makeGraphqlApiRequest({
- query: gql`
- query FindWorkflowVersionSteps($workflowVersionId: UUID!) {
- workflowVersion(filter: { id: { eq: $workflowVersionId } }) {
- steps
- }
- }
- `,
- variables: { workflowVersionId },
- });
-
- expect(response.body.errors).toBeUndefined();
-
- const step = response.body.data.workflowVersion.steps.find(
- (workflowVersionStep: WorkflowVersionStep) =>
- workflowVersionStep.type === stepType,
- );
-
- expect(step).toBeDefined();
-
- return step;
-};
-
-const updateWorkflowVersionStepInput = async ({
- workflowVersionId,
- step,
- input,
-}: {
- workflowVersionId: string;
- step: WorkflowVersionStep;
- input: Record<string, unknown>;
-}): Promise<void> => {
- const response = await makeGraphqlApiRequest({
- query: gql`
- mutation UpdateWorkflowVersionStep(
- $input: UpdateWorkflowVersionStepInput!
- ) {
- updateWorkflowVersionStep(input: $input) {
- id
- }
- }
- `,
- variables: {
- input: {
- workflowVersionId,
- step: {
- ...step,
- settings: {
- ...step.settings,
- input: { ...step.settings.input, ...input },
- },
- },
- },
- },
- });
-
- expect(response.body.errors).toBeUndefined();
-};
-
export const runWorkflowActionStep = async ({
name,
stepType,
@@ -203,15 +50,15 @@ export const runWorkflowActionStep = async ({
stepId: string;
}) => Promise<unknown>;
}): Promise<WorkflowActionStepRun> => {
- const workflowId = await createWorkflow(name);
+ const { coreWorkflowId, coreWorkflowVersionId } = await createCoreWorkflow({
+ name,
+ });
let workflowRunId: string | undefined;
try {
- const workflowVersionId = await findDraftWorkflowVersionId(workflowId);
-
- await updateWorkflowVersionTrigger({
- workflowVersionId,
+ await updateCoreWorkflowVersionTrigger({
+ coreWorkflowVersionId,
trigger: {
name: 'Manual Trigger',
type: 'MANUAL',
@@ -221,16 +68,26 @@ export const runWorkflowActionStep = async ({
},
});
- await createWorkflowVersionStep({ workflowVersionId, stepType });
-
- const step = await findWorkflowVersionStep({ workflowVersionId, stepType });
+ const step = await createCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ stepType,
+ });
- await updateWorkflowVersionStepInput({ workflowVersionId, step, input });
+ await updateCoreWorkflowVersionStep({
+ coreWorkflowVersionId,
+ step: {
+ ...step,
+ settings: {
+ ...step.settings,
+ input: { ...step.settings.input, ...input },
+ },
+ },
+ });
await beforeRun?.(workflowVersionId);
- workflowRunId = await runWorkflowVersion({
- workflowVersionId,
+ workflowRunId = await runCoreWorkflowVersion({
+ coreWorkflowVersionId,
payload,
token: runToken,
});
@@ -251,6 +108,6 @@ export const runWorkflowActionStep = async ({
await destroyWorkflowRun(workflowRunId);
}
- await destroyWorkflow(workflowId);
+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });
}
};
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-send-chat-message.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-send-chat-message.integration-spec.ts
index 595db06887b..a857f9f90d0 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-send-chat-message.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/workflow-send-chat-message.integration-spec.ts
@@ -1,5 +1,9 @@
import gql from 'graphql-tag';
import { answerToolCall } from 'test/integration/graphql/suites/workflow/utils/answer-tool-call.util';
+import {
+ createCoreWorkflow,
+ deleteCoreWorkflows,
+} from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
import { runWorkflowActionStep } from 'test/integration/graphql/suites/workflow/utils/run-workflow-action-step.util';
import { workflowGraphqlRequest } from 'test/integration/graphql/suites/workflow/utils/workflow-graphql-request.util';
import { waitForWorkflowRunStepStatus } from 'test/integration/graphql/suites/workflow/utils/workflow-run-test.util';
@@ -630,48 +634,24 @@ describe('Send chat message workflow step', () => {
it('cannot be added to a workflow while the feature flag is off', async () => {
await setSendChatMessageEnabled(false);
- const workflowResponse = await makeGraphqlApiRequest({
- query: gql`
- mutation CreateWorkflow($name: String!) {
- createWorkflow(data: { name: $name }) {
- id
- }
- }
- `,
- variables: { name: 'Send chat message disabled' },
+ const { coreWorkflowId, coreWorkflowVersionId } = await createCoreWorkflow({
+ name: 'Send chat message disabled',
});
- const workflow = workflowResponse.body.data.createWorkflow;
try {
- const versionResponse = await makeGraphqlApiRequest({
- query: gql`
- query FindDraftWorkflowVersion($workflowId: UUID!) {
- workflowVersions(filter: { workflowId: { eq: $workflowId } }) {
- edges {
- node {
- id
- }
- }
- }
- }
- `,
- variables: { workflowId: workflow.id },
- });
-
const stepResponse = await makeGraphqlApiRequest({
query: gql`
- mutation CreateWorkflowVersionStep(
- $input: CreateWorkflowVersionStepInput!
+ mutation CreateCoreWorkflowVersionStep(
+ $input: CreateCoreWorkflowVersionStepInput!
) {
- createWorkflowVersionStep(input: $input) {
+ createCoreWorkflowVersionStep(input: $input) {
stepsDiff
}
}
`,
variables: {
input: {
- workflowVersionId:
- versionResponse.body.data.workflowVersions.edges[0].node.id,
+ coreWorkflowVersionId,
stepType: 'SEND_CHAT_MESSAGE',
parentStepId: 'trigger',
position: { x: 200, y: 0 },
@@ -683,16 +663,7 @@ describe('Send chat message workflow step', () => {
'is not enabled',
);
} finally {
- await makeGraphqlApiRequest({
- query: gql`
- mutation DestroyWorkflow($id: ID!) {
- destroyWorkflow(id: $id) {
- id
- }
- }
- `,
- variables: { id: workflow.id },
- });
+ await deleteCoreWorkflows({ coreWorkflowIds: [coreWorkflowId] });
}
}, 120000);
});