diff --git a/packages/frontend-2/lib/common/generated/gql/graphql.ts b/packages/frontend-2/lib/common/generated/gql/graphql.ts index d6d479111..b276ee427 100644 --- a/packages/frontend-2/lib/common/generated/gql/graphql.ts +++ b/packages/frontend-2/lib/common/generated/gql/graphql.ts @@ -1825,6 +1825,7 @@ export type ProjectAutomationMutations = { create: Automation; createRevision: AutomationRevision; createTestAutomation: Automation; + createTestAutomationRun: TestAutomationRun; /** * Trigger an automation with a fake "version created" trigger. The "version created" will * just refer to the last version of the model. @@ -1849,6 +1850,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = { }; +export type ProjectAutomationMutationsCreateTestAutomationRunArgs = { + automationId: Scalars['ID']; +}; + + export type ProjectAutomationMutationsTriggerArgs = { automationId: Scalars['ID']; }; @@ -3030,6 +3036,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = { target: ViewerUpdateTrackingTarget; }; +export type TestAutomationRun = { + __typename?: 'TestAutomationRun'; + automationRunId: Scalars['String']; + functionRunId: Scalars['String']; + triggers: Array; +}; + +export type TestAutomationRunTrigger = { + __typename?: 'TestAutomationRunTrigger'; + payload: TestAutomationRunTriggerPayload; + triggerType: Scalars['String']; +}; + +export type TestAutomationRunTriggerPayload = { + __typename?: 'TestAutomationRunTriggerPayload'; + modelId: Scalars['String']; + versionId: Scalars['String']; +}; + export type TokenResourceIdentifier = { __typename?: 'TokenResourceIdentifier'; id: Scalars['String']; diff --git a/packages/server/assets/automate/typedefs/automate.graphql b/packages/server/assets/automate/typedefs/automate.graphql index 6b8dda90d..35427967b 100644 --- a/packages/server/assets/automate/typedefs/automate.graphql +++ b/packages/server/assets/automate/typedefs/automate.graphql @@ -297,7 +297,7 @@ type ProjectAutomationMutations { """ trigger(automationId: ID!): Boolean! createTestAutomation(input: ProjectTestAutomationCreateInput!): Automation! - createTestAutomationRun(automationId: ID!): String! + createTestAutomationRun(automationId: ID!): TestAutomationRun! } extend type ProjectMutations { @@ -388,3 +388,19 @@ extend type Subscription { """ projectAutomationsUpdated(projectId: String!): ProjectAutomationsUpdatedMessage! } + +type TestAutomationRun { + automationRunId: String! + functionRunId: String! + triggers: [TestAutomationRunTrigger!]! +} + +type TestAutomationRunTrigger { + payload: TestAutomationRunTriggerPayload! + triggerType: String! +} + +type TestAutomationRunTriggerPayload { + modelId: String! + versionId: String! +} diff --git a/packages/server/modules/automate/graph/resolvers/automate.ts b/packages/server/modules/automate/graph/resolvers/automate.ts index 3631404c3..737b8a879 100644 --- a/packages/server/modules/automate/graph/resolvers/automate.ts +++ b/packages/server/modules/automate/graph/resolvers/automate.ts @@ -13,7 +13,9 @@ import { getAutomationRunsItems, getAutomationRunsTotalCount, getAutomationTriggerDefinitions, + getFullAutomationRevisionMetadata, getFunctionRun, + getLatestAutomationRevision, getLatestVersionAutomationRuns, getProjectAutomationsItems, getProjectAutomationsTotalCount, @@ -61,6 +63,7 @@ import { getBranchesByIds } from '@/modules/core/repositories/branches' import { + createTestAutomationRun, manuallyTriggerAutomation, triggerAutomationRevisionRun } from '@/modules/automate/services/trigger' @@ -520,6 +523,23 @@ export = (FF_AUTOMATE_MODULE_ENABLED userId: ctx.userId!, userResourceAccessRules: ctx.resourceAccessRules }) + }, + async createTestAutomationRun(parent, { automationId }, ctx) { + const create = createTestAutomationRun({ + getEncryptionKeyPairFor, + getFunctionInputDecryptor: getFunctionInputDecryptor({ + buildDecryptor + }), + getAutomation, + getLatestAutomationRevision, + getFullAutomationRevisionMetadata + }) + + return await create({ + projectId: parent.projectId, + automationId, + userId: ctx.userId! + }) } }, Query: { diff --git a/packages/server/modules/automate/services/trigger.ts b/packages/server/modules/automate/services/trigger.ts index 187bfbde3..b08dd2dea 100644 --- a/packages/server/modules/automate/services/trigger.ts +++ b/packages/server/modules/automate/services/trigger.ts @@ -511,13 +511,15 @@ export type CreateTestAutomationRunDeps = { export const createTestAutomationRun = (deps: CreateTestAutomationRunDeps) => - async (params: { automationId: string; userId: string }) => { + async (params: { projectId: string; automationId: string; userId: string }) => { const { getAutomation, getLatestAutomationRevision, getFullAutomationRevisionMetadata } = deps - const { automationId, userId } = params + const { projectId, automationId, userId } = params + + await validateStreamAccess(userId, projectId, Roles.Stream.Owner) const automationRecord = await getAutomation({ automationId }) @@ -531,8 +533,6 @@ export const createTestAutomationRun = ) } - await validateStreamAccess(userId, automationRecord.projectId, Roles.Stream.Owner) - const { id: automationRevisionId } = (await getLatestAutomationRevision({ automationId })) ?? {} @@ -579,6 +579,7 @@ export const createTestAutomationRun = }) await upsertAutomationRun(automationRunRecord) + // TODO: Test functions only support one function run per automation const functionRunId = automationRunRecord.functionRuns[0].id return { diff --git a/packages/server/modules/core/graph/generated/graphql.ts b/packages/server/modules/core/graph/generated/graphql.ts index 22a912d0e..ee17931eb 100644 --- a/packages/server/modules/core/graph/generated/graphql.ts +++ b/packages/server/modules/core/graph/generated/graphql.ts @@ -1839,6 +1839,7 @@ export type ProjectAutomationMutations = { create: Automation; createRevision: AutomationRevision; createTestAutomation: Automation; + createTestAutomationRun: TestAutomationRun; /** * Trigger an automation with a fake "version created" trigger. The "version created" will * just refer to the last version of the model. @@ -1863,6 +1864,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = { }; +export type ProjectAutomationMutationsCreateTestAutomationRunArgs = { + automationId: Scalars['ID']; +}; + + export type ProjectAutomationMutationsTriggerArgs = { automationId: Scalars['ID']; }; @@ -3044,6 +3050,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = { target: ViewerUpdateTrackingTarget; }; +export type TestAutomationRun = { + __typename?: 'TestAutomationRun'; + automationRunId: Scalars['String']; + functionRunId: Scalars['String']; + triggers: Array; +}; + +export type TestAutomationRunTrigger = { + __typename?: 'TestAutomationRunTrigger'; + payload: TestAutomationRunTriggerPayload; + triggerType: Scalars['String']; +}; + +export type TestAutomationRunTriggerPayload = { + __typename?: 'TestAutomationRunTriggerPayload'; + modelId: Scalars['String']; + versionId: Scalars['String']; +}; + export type TokenResourceIdentifier = { __typename?: 'TokenResourceIdentifier'; id: Scalars['String']; @@ -3734,6 +3759,9 @@ export type ResolversTypes = { StreamUpdatePermissionInput: StreamUpdatePermissionInput; String: ResolverTypeWrapper; Subscription: ResolverTypeWrapper<{}>; + TestAutomationRun: ResolverTypeWrapper; + TestAutomationRunTrigger: ResolverTypeWrapper; + TestAutomationRunTriggerPayload: ResolverTypeWrapper; TokenResourceIdentifier: ResolverTypeWrapper; TokenResourceIdentifierInput: TokenResourceIdentifierInput; TokenResourceIdentifierType: TokenResourceIdentifierType; @@ -3938,6 +3966,9 @@ export type ResolversParentTypes = { StreamUpdatePermissionInput: StreamUpdatePermissionInput; String: Scalars['String']; Subscription: {}; + TestAutomationRun: TestAutomationRun; + TestAutomationRunTrigger: TestAutomationRunTrigger; + TestAutomationRunTriggerPayload: TestAutomationRunTriggerPayload; TokenResourceIdentifier: TokenResourceIdentifier; TokenResourceIdentifierInput: TokenResourceIdentifierInput; TriggeredAutomationsStatus: TriggeredAutomationsStatusGraphQLReturn; @@ -4702,6 +4733,7 @@ export type ProjectAutomationMutationsResolvers>; createRevision?: Resolver>; createTestAutomation?: Resolver>; + createTestAutomationRun?: Resolver>; trigger?: Resolver>; update?: Resolver>; __isTypeOf?: IsTypeOfResolverFn; @@ -5072,6 +5104,25 @@ export type SubscriptionResolvers>; }; +export type TestAutomationRunResolvers = { + automationRunId?: Resolver; + functionRunId?: Resolver; + triggers?: Resolver, ParentType, ContextType>; + __isTypeOf?: IsTypeOfResolverFn; +}; + +export type TestAutomationRunTriggerResolvers = { + payload?: Resolver; + triggerType?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + +export type TestAutomationRunTriggerPayloadResolvers = { + modelId?: Resolver; + versionId?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type TokenResourceIdentifierResolvers = { id?: Resolver; type?: Resolver; @@ -5346,6 +5397,9 @@ export type Resolvers = { StreamCollaborator?: StreamCollaboratorResolvers; StreamCollection?: StreamCollectionResolvers; Subscription?: SubscriptionResolvers; + TestAutomationRun?: TestAutomationRunResolvers; + TestAutomationRunTrigger?: TestAutomationRunTriggerResolvers; + TestAutomationRunTriggerPayload?: TestAutomationRunTriggerPayloadResolvers; TokenResourceIdentifier?: TokenResourceIdentifierResolvers; TriggeredAutomationsStatus?: TriggeredAutomationsStatusResolvers; User?: UserResolvers; diff --git a/packages/server/modules/cross-server-sync/graph/generated/graphql.ts b/packages/server/modules/cross-server-sync/graph/generated/graphql.ts index c8187e57e..eec2b91b1 100644 --- a/packages/server/modules/cross-server-sync/graph/generated/graphql.ts +++ b/packages/server/modules/cross-server-sync/graph/generated/graphql.ts @@ -1828,6 +1828,7 @@ export type ProjectAutomationMutations = { create: Automation; createRevision: AutomationRevision; createTestAutomation: Automation; + createTestAutomationRun: TestAutomationRun; /** * Trigger an automation with a fake "version created" trigger. The "version created" will * just refer to the last version of the model. @@ -1852,6 +1853,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = { }; +export type ProjectAutomationMutationsCreateTestAutomationRunArgs = { + automationId: Scalars['ID']; +}; + + export type ProjectAutomationMutationsTriggerArgs = { automationId: Scalars['ID']; }; @@ -3033,6 +3039,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = { target: ViewerUpdateTrackingTarget; }; +export type TestAutomationRun = { + __typename?: 'TestAutomationRun'; + automationRunId: Scalars['String']; + functionRunId: Scalars['String']; + triggers: Array; +}; + +export type TestAutomationRunTrigger = { + __typename?: 'TestAutomationRunTrigger'; + payload: TestAutomationRunTriggerPayload; + triggerType: Scalars['String']; +}; + +export type TestAutomationRunTriggerPayload = { + __typename?: 'TestAutomationRunTriggerPayload'; + modelId: Scalars['String']; + versionId: Scalars['String']; +}; + export type TokenResourceIdentifier = { __typename?: 'TokenResourceIdentifier'; id: Scalars['String']; diff --git a/packages/server/test/graphql/generated/graphql.ts b/packages/server/test/graphql/generated/graphql.ts index e60b39c6d..83903eebe 100644 --- a/packages/server/test/graphql/generated/graphql.ts +++ b/packages/server/test/graphql/generated/graphql.ts @@ -1829,6 +1829,7 @@ export type ProjectAutomationMutations = { create: Automation; createRevision: AutomationRevision; createTestAutomation: Automation; + createTestAutomationRun: TestAutomationRun; /** * Trigger an automation with a fake "version created" trigger. The "version created" will * just refer to the last version of the model. @@ -1853,6 +1854,11 @@ export type ProjectAutomationMutationsCreateTestAutomationArgs = { }; +export type ProjectAutomationMutationsCreateTestAutomationRunArgs = { + automationId: Scalars['ID']; +}; + + export type ProjectAutomationMutationsTriggerArgs = { automationId: Scalars['ID']; }; @@ -3034,6 +3040,25 @@ export type SubscriptionViewerUserActivityBroadcastedArgs = { target: ViewerUpdateTrackingTarget; }; +export type TestAutomationRun = { + __typename?: 'TestAutomationRun'; + automationRunId: Scalars['String']; + functionRunId: Scalars['String']; + triggers: Array; +}; + +export type TestAutomationRunTrigger = { + __typename?: 'TestAutomationRunTrigger'; + payload: TestAutomationRunTriggerPayload; + triggerType: Scalars['String']; +}; + +export type TestAutomationRunTriggerPayload = { + __typename?: 'TestAutomationRunTriggerPayload'; + modelId: Scalars['String']; + versionId: Scalars['String']; +}; + export type TokenResourceIdentifier = { __typename?: 'TokenResourceIdentifier'; id: Scalars['String'];