diff --git a/packages/cli/src/databases/repositories/execution.repository.ts b/packages/cli/src/databases/repositories/execution.repository.ts index b37d118f3c478..280e6a5bca9cf 100644 --- a/packages/cli/src/databases/repositories/execution.repository.ts +++ b/packages/cli/src/databases/repositories/execution.repository.ts @@ -981,7 +981,7 @@ export class ExecutionRepository extends Repository { if (projectId) { qb.innerJoin(WorkflowEntity, 'w', 'w.id = execution.workflowId') .innerJoin(SharedWorkflow, 'sw', 'sw.workflowId = w.id') - .where('sw.projectId = :projectId', { projectId }); + .andWhere('sw.projectId = :projectId', { projectId }); } return qb; diff --git a/packages/cli/test/integration/execution.service.integration.test.ts b/packages/cli/test/integration/execution.service.integration.test.ts index 4d7144cd4d620..8435abf5bdc3b 100644 --- a/packages/cli/test/integration/execution.service.integration.test.ts +++ b/packages/cli/test/integration/execution.service.integration.test.ts @@ -327,6 +327,36 @@ describe('ExecutionService', () => { }); }); + test('should filter executions by `projectId` and expected `status`', async () => { + const firstProject = await createTeamProject(); + const secondProject = await createTeamProject(); + + const firstWorkflow = await createWorkflow(undefined, firstProject); + const secondWorkflow = await createWorkflow(undefined, secondProject); + + await createExecution({ status: 'success' }, firstWorkflow); + await createExecution({ status: 'error' }, firstWorkflow); + await createExecution({ status: 'success' }, secondWorkflow); + + const query: ExecutionSummaries.RangeQuery = { + kind: 'range', + range: { limit: 20 }, + accessibleWorkflowIds: [firstWorkflow.id], + projectId: firstProject.id, + status: ['error'], + }; + + const output = await executionService.findRangeWithCount(query); + + expect(output).toEqual({ + count: 1, + estimated: false, + results: expect.arrayContaining([ + expect.objectContaining({ workflowId: firstWorkflow.id, status: 'error' }), + ]), + }); + }); + test('should exclude executions by inaccessible `workflowId`', async () => { const accessibleWorkflow = await createWorkflow(); const inaccessibleWorkflow = await createWorkflow();