Skip to content

The open alternative to Salesforce, designed for AI.

Seed and prefill workflows in core only (#27884)

Thomas Trompette7ddeb0485b9c
diff --git a/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts b/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts
index 77008a9e9b8..66fb769f0f2 100644
--- a/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts
@@ -1200,7 +1200,6 @@ export class WorkspaceService {
await prefillWorkflows(
queryRunner.manager,
workspaceId,
- schemaName,
flatObjectMetadataMaps,
flatFieldMetadataMaps,
);
diff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-data.service.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-data.service.ts
index 789c05bd0b3..089b13e5494 100644
--- a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-data.service.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-data.service.ts
@@ -377,7 +377,6 @@ export class DevSeederDataService {
await prefillWorkflows(
entityManager,
workspaceId,
- schemaName,
flatObjectMetadataMaps,
flatFieldMetadataMaps,
);
diff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-workflow-pending-input.workspace-service.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-workflow-pending-input.workspace-service.ts
index b1643c0ba76..f7d7e46023d 100644
--- a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-workflow-pending-input.workspace-service.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/services/dev-seeder-workflow-pending-input.workspace-service.ts
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { type AskQuestionItem } from 'twenty-shared/ai';
-import { type ActorMetadata, FieldActorSource } from 'twenty-shared/types';
+import { FieldActorSource } from 'twenty-shared/types';
import { StepStatus, WorkflowActionType } from 'twenty-shared/workflow';
import { v5 } from 'uuid';
@@ -10,15 +10,12 @@ import {
WorkflowVersionStatus,
} from 'src/engine/core-modules/workflow/entities/workflow-version.entity';
import { WorkflowEntity } from 'src/engine/core-modules/workflow/entities/workflow.entity';
-import { WorkflowStatus } from 'src/engine/core-modules/workflow/enums/workflow-status.enum';
import { AgentRunConversationService } from 'src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service';
import { AgentRunSuspensionService } from 'src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-suspension.service';
import {
AiException,
AiExceptionCode,
} from 'src/engine/metadata-modules/ai/ai.exception';
-import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
-import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';
import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';
import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';
import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';
@@ -27,8 +24,6 @@ import { proposeEmailCall } from 'src/engine/workspace-manager/dev-seeder/data/u
import { type SeededEmail } from 'src/engine/workspace-manager/dev-seeder/data/utils/seeded-email.type';
import { type SeededToolCall } from 'src/engine/workspace-manager/dev-seeder/data/utils/seeded-tool-call.type';
import { WorkflowRunStatus } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
-import { type WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
-import { type WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import { buildWorkflowStepCaller } from 'src/modules/workflow/workflow-executor/utils/build-workflow-step-caller.util';
import { buildWorkflowAgentRunSpec } from 'src/modules/workflow/workflow-executor/workflow-actions/ai-agent/utils/build-workflow-agent-run-spec.util';
import { WorkflowAgentConversationWorkspaceService } from 'src/modules/workflow/workflow-executor/workflow-actions/ai-agent/services/workflow-agent-conversation.workspace-service';
@@ -48,13 +43,6 @@ const WORKFLOW_PENDING_INPUT_SEED_NAMESPACE =
const seedId = (name: string, workspaceId: string) =>
v5(`${name}:${workspaceId}`, WORKFLOW_PENDING_INPUT_SEED_NAMESPACE);
-const SYSTEM_ACTOR: ActorMetadata = {
- source: FieldActorSource.SYSTEM,
- workspaceMemberId: null,
- name: 'System',
- context: {},
-};
-
const INITIATORS = {
TIM: {
workspaceMemberId: WORKSPACE_MEMBER_DATA_SEED_IDS.TIM,
@@ -107,7 +95,6 @@ const RENEWAL_REMINDER_EMAIL: SeededEmail = {
type AgentWorkflowToSeed = {
key: string;
name: string;
- position: number;
icon: string;
stepKey: string;
stepName: string;
@@ -123,7 +110,6 @@ const AGENT_WORKFLOWS_TO_SEED: AgentWorkflowToSeed[] = [
{
key: 'qualifyInboundLead',
name: 'Qualify inbound lead',
- position: 3,
icon: 'IconUserCheck',
stepKey: 'agentStep',
stepName: 'Qualify the lead',
@@ -139,7 +125,6 @@ const AGENT_WORKFLOWS_TO_SEED: AgentWorkflowToSeed[] = [
{
key: 'draftRenewalReminder',
name: 'Draft renewal reminder',
- position: 4,
icon: 'IconMail',
stepKey: 'renewalAgentStep',
stepName: 'Draft the reminder',
@@ -160,8 +145,6 @@ const ERROR_HANDLING_OPTIONS = {
};
type SeededWorkflow = {
- workspaceWorkflowId: string;
- workspaceWorkflowVersionId: string;
coreWorkflowId: string;
coreWorkflowVersionId: string;
name: string;
@@ -176,7 +159,6 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
private readonly workflowAgentConversationService: WorkflowAgentConversationWorkspaceService,
private readonly agentRunConversationService: AgentRunConversationService,
private readonly agentRunSuspensionService: AgentRunSuspensionService,
- private readonly workspaceOrmManager: WorkspaceOrmManager,
@InjectWorkspaceScopedRepository(WorkflowEntity)
private readonly coreWorkflowRepository: WorkspaceScopedRepository<WorkflowEntity>,
@InjectWorkspaceScopedRepository(WorkflowVersionEntity)
@@ -211,7 +193,6 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
applicationId,
key: agentWorkflow.key,
name: agentWorkflow.name,
- position: agentWorkflow.position,
icon: agentWorkflow.icon,
step,
});
@@ -341,8 +322,8 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
workflowRunId,
coreWorkflowId: workflow.coreWorkflowId,
coreWorkflowVersionId: workflow.coreWorkflowVersionId,
- workspaceWorkflowId: workflow.workspaceWorkflowId,
- workspaceWorkflowVersionId: workflow.workspaceWorkflowVersionId,
+ workspaceWorkflowId: null,
+ workspaceWorkflowVersionId: null,
workflowName: workflow.name,
trigger: workflow.trigger,
steps: [workflow.step],
@@ -376,7 +357,6 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
applicationId,
key,
name,
- position,
icon,
step,
}: {
@@ -384,15 +364,9 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
applicationId: string;
key: string;
name: string;
- position: number;
icon: string;
step: WorkflowAction;
}): Promise<SeededWorkflow> {
- const workspaceWorkflowId = seedId(`workflow:${key}`, workspaceId);
- const workspaceWorkflowVersionId = seedId(
- `workflowVersion:${key}`,
- workspaceId,
- );
const coreWorkflowId = seedId(`coreWorkflow:${key}`, workspaceId);
const coreWorkflowVersionId = seedId(
`coreWorkflowVersion:${key}`,
@@ -410,42 +384,6 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
nextStepIds: [step.id],
};
- await this.workspaceOrmManager.executeInWorkspaceContext(async () => {
- await this.workspaceOrmManager
- .getRepository<WorkflowWorkspaceEntity>(
- 'workflow',
- { shouldBypassPermissionChecks: true },
- { shouldSkipEventEmission: true },
- )
- .insert({
- id: workspaceWorkflowId,
- name,
- lastPublishedVersionId: workspaceWorkflowVersionId,
- statuses: [WorkflowStatus.ACTIVE],
- position,
- createdBy: SYSTEM_ACTOR,
- updatedBy: SYSTEM_ACTOR,
- coreWorkflowId,
- });
-
- await this.workspaceOrmManager
- .getRepository<WorkflowVersionWorkspaceEntity>(
- 'workflowVersion',
- { shouldBypassPermissionChecks: true },
- { shouldSkipEventEmission: true },
- )
- .insert({
- id: workspaceWorkflowVersionId,
- name: 'v1',
- trigger,
- steps: [step],
- status: WorkflowVersionStatus.ACTIVE,
- position: 1,
- workflowId: workspaceWorkflowId,
- coreWorkflowVersionId,
- });
- }, buildSystemAuthContext(workspaceId));
-
await this.coreWorkflowRepository.insert(workspaceId, {
id: coreWorkflowId,
universalIdentifier: seedId(
@@ -454,8 +392,6 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
),
applicationId,
name,
- lastPublishedVersionId: workspaceWorkflowVersionId,
- workspaceWorkflowId,
lastPublishedCoreWorkflowVersionId: coreWorkflowVersionId,
});
@@ -469,14 +405,10 @@ export class DevSeederWorkflowPendingInputWorkspaceService {
triggers: [trigger],
steps: [step],
status: WorkflowVersionStatus.ACTIVE,
- workflowId: workspaceWorkflowId,
coreWorkflowId,
- workspaceWorkflowVersionId,
});
return {
- workspaceWorkflowId,
- workspaceWorkflowVersionId,
coreWorkflowId,
coreWorkflowVersionId,
name,
diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util.ts
index f68f688c11d..6d5891040ef 100644
--- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util.ts
@@ -46,8 +46,7 @@ export const prefillWorkflowCommandMenuItems = async ({
const now = new Date().toISOString();
- const { quickLeadWorkflowVersionId, coreQuickLeadWorkflowVersionId } =
- getWorkflowPrefillIds(workspaceId);
+ const { coreQuickLeadWorkflowVersionId } = getWorkflowPrefillIds(workspaceId);
const quickLeadFlatCommandMenuItem: FlatCommandMenuItem = {
id: v4(),
@@ -56,7 +55,7 @@ export const prefillWorkflowCommandMenuItems = async ({
applicationUniversalIdentifier:
workspaceCustomFlatApplication.universalIdentifier,
workspaceId,
- workflowVersionId: quickLeadWorkflowVersionId,
+ workflowVersionId: null,
coreWorkflowVersionId: coreQuickLeadWorkflowVersionId,
frontComponentId: null,
frontComponentUniversalIdentifier: null,
diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflows.util.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflows.util.ts
index 5fab88d2352..4a5e7873154 100644
--- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflows.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflows.util.ts
@@ -1,4 +1,3 @@
-import { FieldActorSource } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { IF_ELSE_BRANCH_POSITION_OFFSETS } from 'twenty-shared/workflow';
import { type EntityManager } from 'typeorm';
@@ -19,26 +18,6 @@ import { getCreateCompanyWhenAddingNewPersonCodeStepLogicFunctionIds } from 'src
const WORKFLOW_PREFILL_ID_NAMESPACE = '8b213cac-a68b-4ffe-817a-3ec994e9932d';
export const getWorkflowPrefillIds = (workspaceId: string) => ({
- quickLeadWorkflowId: v5(
- `quickLeadWorkflow:${workspaceId}`,
- WORKFLOW_PREFILL_ID_NAMESPACE,
- ),
- quickLeadWorkflowVersionId: v5(
- `quickLeadWorkflowVersion:${workspaceId}`,
- WORKFLOW_PREFILL_ID_NAMESPACE,
- ),
- createCompanyWorkflowId: v5(
- `createCompanyWorkflow:${workspaceId}`,
- WORKFLOW_PREFILL_ID_NAMESPACE,
- ),
- createCompanyWorkflowVersionId: v5(
- `createCompanyWorkflowVersion:${workspaceId}`,
- WORKFLOW_PREFILL_ID_NAMESPACE,
- ),
- createCompanyAutomatedTriggerId: v5(
- `createCompanyAutomatedTrigger:${workspaceId}`,
- WORKFLOW_PREFILL_ID_NAMESPACE,
- ),
coreQuickLeadWorkflowId: v5(
`coreQuickLeadWorkflow:${workspaceId}`,
WORKFLOW_PREFILL_ID_NAMESPACE,
@@ -76,17 +55,11 @@ export const getWorkflowPrefillIds = (workspaceId: string) => ({
export const prefillWorkflows = async (
entityManager: EntityManager,
workspaceId: string,
- schemaName: string,
flatObjectMetadataMaps: FlatEntityMaps<FlatObjectMetadata>,
flatFieldMetadataMaps: FlatEntityMaps<FlatFieldMetadata>,
applicationIdParam?: string,
) => {
const {
- quickLeadWorkflowId,
- quickLeadWorkflowVersionId,
- createCompanyWorkflowId,
- createCompanyWorkflowVersionId,
- createCompanyAutomatedTriggerId,
coreQuickLeadWorkflowId,
coreCreateCompanyWorkflowId,
coreQuickLeadWorkflowVersionId,
@@ -176,60 +149,6 @@ export const prefillWorkflows = async (
createdByFieldMetadataId: personCreatedByFieldMetadata.id,
});
- await entityManager
- .createQueryBuilder()
- .insert()
- .into(`${schemaName}.workflow`, [
- 'id',
- 'name',
- 'lastPublishedVersionId',
- 'statuses',
- 'position',
- 'createdBySource',
- 'createdByWorkspaceMemberId',
- 'createdByName',
- 'createdByContext',
- 'updatedBySource',
- 'updatedByWorkspaceMemberId',
- 'updatedByName',
- 'coreWorkflowId',
- ])
- .orIgnore()
- .values([
- {
- id: quickLeadWorkflowId,
- name: 'Quick Lead',
- lastPublishedVersionId: quickLeadWorkflowVersionId,
- statuses: ['ACTIVE'],
- position: 1,
- createdBySource: FieldActorSource.SYSTEM,
- createdByWorkspaceMemberId: null,
- createdByName: 'System',
- createdByContext: {},
- updatedBySource: FieldActorSource.SYSTEM,
- updatedByWorkspaceMemberId: null,
- updatedByName: 'System',
- coreWorkflowId: coreQuickLeadWorkflowId,
- },
- {
- id: createCompanyWorkflowId,
- name: 'Create company when adding a new person',
- lastPublishedVersionId: createCompanyWorkflowVersionId,
- statuses: ['ACTIVE'],
- position: 2,
- createdBySource: FieldActorSource.SYSTEM,
- createdByWorkspaceMemberId: null,
- createdByName: 'System',
- createdByContext: {},
- updatedBySource: FieldActorSource.SYSTEM,
- updatedByWorkspaceMemberId: null,
- updatedByName: 'System',
- coreWorkflowId: coreCreateCompanyWorkflowId,
- },
- ])
- .returning('*')
- .execute();
-
await entityManager
.createQueryBuilder()
.insert()
@@ -242,8 +161,6 @@ export const prefillWorkflows = async (
universalIdentifier: quickLeadWorkflowUniversalIdentifier,
applicationId,
name: 'Quick Lead',
- lastPublishedVersionId: quickLeadWorkflowVersionId,
- workspaceWorkflowId: quickLeadWorkflowId,
lastPublishedCoreWorkflowVersionId: coreQuickLeadWorkflowVersionId,
},
{
@@ -252,8 +169,6 @@ export const prefillWorkflows = async (
universalIdentifier: createCompanyWorkflowUniversalIdentifier,
applicationId,
name: 'Create company when adding a new person',
- lastPublishedVersionId: createCompanyWorkflowVersionId,
- workspaceWorkflowId: createCompanyWorkflowId,
lastPublishedCoreWorkflowVersionId: coreCreateCompanyWorkflowVersionId,
},
])
@@ -835,45 +750,6 @@ export const prefillWorkflows = async (
},
]);
- await entityManager
- .createQueryBuilder()
- .insert()
- .into(`${schemaName}.workflowVersion`, [
- 'id',
- 'name',
- 'trigger',
- 'steps',
- 'status',
- 'position',
- 'workflowId',
- 'coreWorkflowVersionId',
- ])
- .orIgnore()
- .values([
- {
- id: quickLeadWorkflowVersionId,
- name: 'v1',
- trigger: JSON.stringify(quickLeadTrigger),
- steps: quickLeadSteps,
- status: 'ACTIVE',
- position: 1,
- workflowId: quickLeadWorkflowId,
- coreWorkflowVersionId: coreQuickLeadWorkflowVersionId,
- },
- {
- id: createCompanyWorkflowVersionId,
- name: 'v1',
- trigger: JSON.stringify(createCompanyTrigger),
- steps: createCompanySteps,
- status: 'ACTIVE',
- position: 2,
- workflowId: createCompanyWorkflowId,
- coreWorkflowVersionId: coreCreateCompanyWorkflowVersionId,
- },
- ])
- .returning('*')
- .execute();
-
await entityManager
.createQueryBuilder()
.insert()
@@ -885,9 +761,7 @@ export const prefillWorkflows = async (
'triggers',
'steps',
'status',
- 'workflowId',
'coreWorkflowId',
- 'workspaceWorkflowVersionId',
])
.orIgnore()
.values([
@@ -899,9 +773,7 @@ export const prefillWorkflows = async (
triggers: [quickLeadTrigger],
steps: JSON.parse(quickLeadSteps),
status: 'ACTIVE',
- workflowId: quickLeadWorkflowId,
coreWorkflowId: coreQuickLeadWorkflowId,
- workspaceWorkflowVersionId: quickLeadWorkflowVersionId,
},
{
id: coreCreateCompanyWorkflowVersionId,
@@ -911,33 +783,7 @@ export const prefillWorkflows = async (
triggers: [createCompanyTrigger],
steps: JSON.parse(createCompanySteps),
status: 'ACTIVE',
- workflowId: createCompanyWorkflowId,
coreWorkflowId: coreCreateCompanyWorkflowId,
- workspaceWorkflowVersionId: createCompanyWorkflowVersionId,
- },
- ])
- .execute();
-
- await entityManager
- .createQueryBuilder()
- .insert()
- .into(`${schemaName}.workflowAutomatedTrigger`, [
- 'id',
- 'workflowId',
- 'type',
- 'settings',
- ])
- .orIgnore()
- .values([
- {
- id: createCompanyAutomatedTriggerId,
- workflowId: createCompanyWorkflowId,
- type: 'DATABASE_EVENT',
- settings: {
- eventName: 'person.upserted',
- fields: ['emails'],
- filter: personSyncSourceFilter,
- },
},
])
.execute();
diff --git a/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts b/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts
index e8c7bbce89f..a72c46517a2 100644
--- a/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts
+++ b/packages/twenty-server/test/integration/constants/workflow-gql-fields.constants.ts
@@ -7,5 +7,6 @@ export const WORKFLOW_RUN_GQL_FIELDS = `
createdAt
updatedAt
workflowVersionId
+ coreWorkflowVersionId
state
`;
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 7114db0303c..d6dd9e99e9d 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
@@ -2539,7 +2539,7 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
}
});
- it('provisions a fresh workspace with synchronous parent and version mappings', async () => {
+ it('provisions a fresh workspace with core-only workflows and nullable run relations', async () => {
const services = global.workflowTestServices;
const freshWorkspaceId = randomUUID();
const applicationId = randomUUID();
@@ -2589,22 +2589,26 @@ describe('core workflow execution and queue compatibility (e2e)', () => {
},
workspace,
);
- const versions = await global.testDataSource.query(
- `SELECT wv.id, wv."coreWorkflowVersionId", cv."workspaceWorkflowVersionId", cv."coreWorkflowId", cw."workspaceWorkflowId", cw."lastPublishedCoreWorkflowVersionId", wv."workflowId"
- FROM "${freshSchema}"."workflowVersion" wv
- LEFT JOIN core."workflowVersion" cv ON cv.id = wv."coreWorkflowVersionId" AND cv."workspaceId" = $1
- LEFT JOIN core.workflow cw ON cw.id = cv."coreWorkflowId" AND cw."workspaceId" = $1`,
+ const coreVersions = await global.testDataSource.query(
+ `SELECT cv.id, cv."workspaceWorkflowVersionId", cv."workflowId", cw."workspaceWorkflowId", cw."lastPublishedCoreWorkflowVersionId"
+ FROM core."workflowVersion" cv
+ JOIN core.workflow cw ON cw.id = cv."coreWorkflowId" AND cw."workspaceId" = $1
+ WHERE cv."workspaceId" = $1`,
[freshWorkspaceId],
);
- expect(versions).toHaveLength(2);
- for (const version of versions) {
- expect(version.workspaceWorkflowVersionId).toBe(version.id);
- expect(version.workspaceWorkflowId).toBe(version.workflowId);
- expect(version.lastPublishedCoreWorkflowVersionId).toBe(
- version.coreWorkflowVersionId,
- );
- expect(version.coreWorkflowId).toBeTruthy();
+ expect(coreVersions).toHaveLength(2);
+ for (const coreVersion of coreVersions) {
+ expect(coreVersion).toMatchObject({
+ workspaceWorkflowVersionId: null,
+ workflowId: null,
+ workspaceWorkflowId: null,
+ lastPublishedCoreWorkflowVersionId: coreVersion.id,
+ });
}
+ const [{ workspaceWorkflowCount }] = await global.testDataSource.query(
+ `SELECT (SELECT count(*) FROM "${freshSchema}"."workflow")::int + (SELECT count(*) FROM "${freshSchema}"."workflowVersion")::int AS "workspaceWorkflowCount"`,
+ );
+ expect(workspaceWorkflowCount).toBe(0);
const relationFields = await global.testDataSource.query(
`SELECT f.name, f."isNullable" FROM core."fieldMetadata" f JOIN core."objectMetadata" o ON o.id = f."objectMetadataId" WHERE o."workspaceId" = $1 AND o."nameSingular" = 'workflowRun' AND f.name IN ('workflow', 'workflowVersion')`,
[freshWorkspaceId],
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 a992e78836a..b741564b7f4 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,5 +1,9 @@
import request from 'supertest';
-import { runCoreWorkflowVersion } from 'test/integration/graphql/suites/workflow/utils/core-workflow.util';
+import {
+ coreWorkflowGraphqlRequest,
+ findCoreWorkflowVersion,
+ 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,
@@ -16,8 +20,7 @@ import { getWorkflowPrefillIds } from 'src/engine/workspace-manager/standard-obj
const client = request(`http://localhost:${APP_PORT}`);
const {
- quickLeadWorkflowId: QUICK_LEAD_WORKFLOW_ID,
- quickLeadWorkflowVersionId: QUICK_LEAD_WORKFLOW_VERSION_ID,
+ coreQuickLeadWorkflowId: QUICK_LEAD_CORE_WORKFLOW_ID,
coreQuickLeadWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
} = getWorkflowPrefillIds(SEED_APPLE_WORKSPACE_ID);
const FORM_STEP_ID = '6e089bc9-aabd-435f-865f-f31c01c8f4a7';
@@ -33,93 +36,67 @@ describe('Quick Lead Workflow (e2e)', () => {
describe('Workflow triggering', () => {
it('should verify Quick Lead workflow exists and is active', async () => {
- const response = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- query FindWorkflow {
- workflow(filter: { id: { eq: "${QUICK_LEAD_WORKFLOW_ID}" } }) {
- id
- name
- lastPublishedVersionId
- statuses
- }
+ const { coreWorkflowById } = await coreWorkflowGraphqlRequest<{
+ coreWorkflowById: {
+ id: string;
+ name: string;
+ statuses: string[];
+ lastPublishedCoreWorkflowVersionId: string | null;
+ };
+ }>({
+ query: `
+ query FindCoreWorkflow($coreWorkflowId: UUID!) {
+ coreWorkflowById(coreWorkflowId: $coreWorkflowId) {
+ id
+ name
+ statuses
+ lastPublishedCoreWorkflowVersionId
}
- `,
- });
+ }
+ `,
+ variables: { coreWorkflowId: QUICK_LEAD_CORE_WORKFLOW_ID },
+ });
- expect(response.status).toBe(200);
- expect(response.body.errors).toBeUndefined();
- expect(response.body.data.workflow).toBeDefined();
- expect(response.body.data.workflow.id).toBe(QUICK_LEAD_WORKFLOW_ID);
- expect(response.body.data.workflow.name).toBe('Quick Lead');
- expect(response.body.data.workflow.lastPublishedVersionId).toBe(
- QUICK_LEAD_WORKFLOW_VERSION_ID,
+ expect(coreWorkflowById.id).toBe(QUICK_LEAD_CORE_WORKFLOW_ID);
+ expect(coreWorkflowById.name).toBe('Quick Lead');
+ expect(coreWorkflowById.lastPublishedCoreWorkflowVersionId).toBe(
+ QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
);
- expect(response.body.data.workflow.statuses).toContain('ACTIVE');
+ expect(coreWorkflowById.statuses).toContain('ACTIVE');
});
it('should verify Quick Lead workflow version has correct structure', async () => {
- const response = await client
- .post('/graphql')
- .set('Authorization', `Bearer ${APPLE_JANE_ADMIN_ACCESS_TOKEN}`)
- .send({
- query: `
- query FindWorkflowVersion {
- workflowVersion(filter: { id: { eq: "${QUICK_LEAD_WORKFLOW_VERSION_ID}" } }) {
- id
- name
- status
- trigger
- steps
- }
- }
- `,
- });
-
- expect(response.status).toBe(200);
- expect(response.body.errors).toBeUndefined();
-
- const workflowVersion = response.body.data.workflowVersion;
+ const workflowVersion = await findCoreWorkflowVersion({
+ coreWorkflowVersionId: QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
+ });
- expect(workflowVersion).toBeDefined();
expect(workflowVersion.status).toBe('ACTIVE');
- const trigger = workflowVersion.trigger;
-
- expect(trigger.type).toBe('MANUAL');
- expect(trigger.nextStepIds).toContain(FORM_STEP_ID);
+ expect(workflowVersion.trigger?.type).toBe('MANUAL');
+ expect(workflowVersion.trigger?.nextStepIds).toContain(FORM_STEP_ID);
- const steps = workflowVersion.steps;
+ const steps = workflowVersion.steps ?? [];
expect(steps).toHaveLength(3);
-
- const formStep = steps.find(
- (step: { id: string }) => step.id === FORM_STEP_ID,
- );
-
- expect(formStep).toBeDefined();
- expect(formStep.type).toBe('FORM');
- expect(formStep.name).toBe('Quick Lead Form');
-
- const createCompanyStep = steps.find(
- (step: { id: string }) =>
- step.id === '0715b6cd-7cc1-4b98-971b-00f54dfe643b',
+ expect(steps).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ id: FORM_STEP_ID,
+ type: 'FORM',
+ name: 'Quick Lead Form',
+ }),
+ expect.objectContaining({
+ id: '0715b6cd-7cc1-4b98-971b-00f54dfe643b',
+ type: 'CREATE_RECORD',
+ name: 'Create Company',
+ }),
+ expect.objectContaining({
+ id: '6f553ea7-b00e-4371-9d88-d8298568a246',
+ type: 'CREATE_RECORD',
+ name: 'Create Person',
+ }),
+ ]),
);
-
- expect(createCompanyStep).toBeDefined();
- expect(createCompanyStep.type).toBe('CREATE_RECORD');
- expect(createCompanyStep.name).toBe('Create Company');
-
- const createPersonStep = steps.find(
- (step: { id: string }) =>
- step.id === '6f553ea7-b00e-4371-9d88-d8298568a246',
- );
-
- expect(createPersonStep).toBeDefined();
- expect(createPersonStep.type).toBe('CREATE_RECORD');
- expect(createPersonStep.name).toBe('Create Person');
});
it('should trigger Quick Lead workflow and create workflow run', async () => {
@@ -138,8 +115,8 @@ describe('Quick Lead Workflow (e2e)', () => {
);
expect(workflowRun).toBeDefined();
- expect(workflowRun?.workflowVersionId).toBe(
- QUICK_LEAD_WORKFLOW_VERSION_ID,
+ expect(workflowRun?.coreWorkflowVersionId).toBe(
+ QUICK_LEAD_CORE_WORKFLOW_VERSION_ID,
);
expect(workflowRun?.status).toBe('RUNNING');
expect(workflowRun?.state).toBeDefined();
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/workflow-run-test.util.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/workflow-run-test.util.ts
index 10c9bceeefa..e8bfc99d08d 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/utils/workflow-run-test.util.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/utils/workflow-run-test.util.ts
@@ -39,7 +39,8 @@ export type WorkflowRunResponse = {
id: string;
status: WorkflowRunStatusType;
state: WorkflowRunState;
- workflowVersionId: string;
+ workflowVersionId: string | null;
+ coreWorkflowVersionId: string | null;
};
export const getWorkflowRun = async (