From 1adb730599ae543472cb37805496b698d1011f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 26 Nov 2024 10:27:01 +0100 Subject: [PATCH] test(core): Expand coverage for execution filters (#11890) --- .../execution.service.integration.test.ts | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/packages/cli/test/integration/execution.service.integration.test.ts b/packages/cli/test/integration/execution.service.integration.test.ts index 8435abf5bd..27163b3bea 100644 --- a/packages/cli/test/integration/execution.service.integration.test.ts +++ b/packages/cli/test/integration/execution.service.integration.test.ts @@ -357,6 +357,65 @@ describe('ExecutionService', () => { }); }); + test.each([ + { + name: 'waitTill', + filter: { waitTill: true }, + matchingParams: { waitTill: new Date() }, + nonMatchingParams: { waitTill: undefined }, + }, + { + name: 'metadata', + filter: { metadata: [{ key: 'testKey', value: 'testValue' }] }, + matchingParams: { metadata: [{ key: 'testKey', value: 'testValue' }] }, + nonMatchingParams: { metadata: [{ key: 'otherKey', value: 'otherValue' }] }, + }, + { + name: 'startedAfter', + filter: { startedAfter: '2023-01-01' }, + matchingParams: { startedAt: new Date('2023-06-01') }, + nonMatchingParams: { startedAt: new Date('2022-01-01') }, + }, + { + name: 'startedBefore', + filter: { startedBefore: '2023-12-31' }, + matchingParams: { startedAt: new Date('2023-06-01') }, + nonMatchingParams: { startedAt: new Date('2024-01-01') }, + }, + ])( + 'should filter executions by `projectId` and expected `$name`', + async ({ filter, matchingParams, nonMatchingParams }) => { + const firstProject = await createTeamProject(); + const secondProject = await createTeamProject(); + + const firstWorkflow = await createWorkflow(undefined, firstProject); + const secondWorkflow = await createWorkflow(undefined, secondProject); + + await Promise.all([ + createExecution(matchingParams, firstWorkflow), + createExecution(nonMatchingParams, secondWorkflow), + ]); + + const query: ExecutionSummaries.RangeQuery = { + kind: 'range', + range: { limit: 20 }, + accessibleWorkflowIds: [firstWorkflow.id], + projectId: firstProject.id, + ...filter, + }; + + const output = await executionService.findRangeWithCount(query); + + expect(output).toEqual({ + count: 1, + estimated: false, + results: expect.arrayContaining([ + expect.objectContaining({ workflowId: firstWorkflow.id }), + ]), + }); + }, + ); + test('should exclude executions by inaccessible `workflowId`', async () => { const accessibleWorkflow = await createWorkflow(); const inaccessibleWorkflow = await createWorkflow();