From 36bc011ae91abbfbcaa3360c58c0118ee21b0dda Mon Sep 17 00:00:00 2001 From: Eugene Molodkin Date: Fri, 29 Nov 2024 14:35:57 +0100 Subject: [PATCH] wip: Addressing PR comments --- .../src/evaluation/test-runs.controller.ee.ts | 5 ++- .../evaluation/test-runs.api.test.ts | 39 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/evaluation/test-runs.controller.ee.ts b/packages/cli/src/evaluation/test-runs.controller.ee.ts index 9c115dc308..744c420fc0 100644 --- a/packages/cli/src/evaluation/test-runs.controller.ee.ts +++ b/packages/cli/src/evaluation/test-runs.controller.ee.ts @@ -14,8 +14,9 @@ export class TestRunsController { private readonly testRunRepository: TestRunRepository, ) {} - // This method is used in multiple places in the controller to get the test definition - // (or just check that it exists and the user has access to it). + /** This method is used in multiple places in the controller to get the test definition + * (or just check that it exists and the user has access to it). + */ private async getTestDefinition( req: TestRunsRequest.GetOne | TestRunsRequest.GetMany | TestRunsRequest.Delete, ) { diff --git a/packages/cli/test/integration/evaluation/test-runs.api.test.ts b/packages/cli/test/integration/evaluation/test-runs.api.test.ts index 852f2106d1..4942f7868b 100644 --- a/packages/cli/test/integration/evaluation/test-runs.api.test.ts +++ b/packages/cli/test/integration/evaluation/test-runs.api.test.ts @@ -10,6 +10,7 @@ import { createWorkflow } from '@test-integration/db/workflows'; import * as testDb from '@test-integration/test-db'; import type { SuperAgentTest } from '@test-integration/types'; import * as utils from '@test-integration/utils'; +import { ProjectRepository } from '@/databases/repositories/project.repository'; let authOwnerAgent: SuperAgentTest; let workflowUnderTest: WorkflowEntity; @@ -18,7 +19,10 @@ let testDefinition: TestDefinition; let otherTestDefinition: TestDefinition; let ownerShell: User; -const testServer = utils.setupTestServer({ endpointGroups: ['evaluation'] }); +const testServer = utils.setupTestServer({ + endpointGroups: ['workflows', 'evaluation'], + enabledFeatures: ['feat:sharing'], +}); beforeAll(async () => { ownerShell = await createUserShell('global:owner'); @@ -26,7 +30,7 @@ beforeAll(async () => { }); beforeEach(async () => { - await testDb.truncate(['TestDefinition', 'TestRun']); + await testDb.truncate(['TestDefinition', 'TestRun', 'Workflow', 'SharedWorkflow']); workflowUnderTest = await createWorkflow({ name: 'workflow-under-test' }, ownerShell); @@ -165,6 +169,37 @@ describe('GET /evaluation/test-definitions/:testDefinitionId/runs/:id', () => { expect(resp.statusCode).toBe(404); }); + + test('should retrieve test run for a test definition of a shared workflow', async () => { + const memberShell = await createUserShell('global:member'); + const memberAgent = testServer.authAgentFor(memberShell); + const memberPersonalProject = await Container.get( + ProjectRepository, + ).getPersonalProjectForUserOrFail(memberShell.id); + + // Share workflow with a member + const sharingResponse = await authOwnerAgent + .put(`/workflows/${workflowUnderTest.id}/share`) + .send({ shareWithIds: [memberPersonalProject.id] }); + + expect(sharingResponse.statusCode).toBe(200); + + // Create a test run for the shared workflow + const testRunRepository = Container.get(TestRunRepository); + const testRun = await testRunRepository.createTestRun(testDefinition.id); + + // Check if member can retrieve the test run of a shared workflow + const resp = await memberAgent.get( + `/evaluation/test-definitions/${testDefinition.id}/runs/${testRun.id}`, + ); + + expect(resp.statusCode).toBe(200); + expect(resp.body.data).toEqual( + expect.objectContaining({ + id: testRun.id, + }), + ); + }); }); describe('DELETE /evaluation/test-definitions/:testDefinitionId/runs/:id', () => {