From dc27ff83e0be65b50b0ed09f2c45664b3a9b6f5a Mon Sep 17 00:00:00 2001 From: Eugene Molodkin Date: Thu, 28 Nov 2024 11:01:35 +0100 Subject: [PATCH] wip: Added tests for test run delete --- .../evaluation/test-runs.api.test.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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 00e85bcd78..852f2106d1 100644 --- a/packages/cli/test/integration/evaluation/test-runs.api.test.ts +++ b/packages/cli/test/integration/evaluation/test-runs.api.test.ts @@ -166,3 +166,39 @@ describe('GET /evaluation/test-definitions/:testDefinitionId/runs/:id', () => { expect(resp.statusCode).toBe(404); }); }); + +describe('DELETE /evaluation/test-definitions/:testDefinitionId/runs/:id', () => { + test('should delete test run for a test definition', async () => { + const testRunRepository = Container.get(TestRunRepository); + const testRun = await testRunRepository.createTestRun(testDefinition.id); + + const resp = await authOwnerAgent.delete( + `/evaluation/test-definitions/${testDefinition.id}/runs/${testRun.id}`, + ); + + expect(resp.statusCode).toBe(200); + expect(resp.body.data).toEqual({ success: true }); + + const testRunAfterDelete = await testRunRepository.findOne({ where: { id: testRun.id } }); + expect(testRunAfterDelete).toBeNull(); + }); + + test('should retrieve 404 if test run does not exist', async () => { + const resp = await authOwnerAgent.delete( + `/evaluation/test-definitions/${testDefinition.id}/runs/123`, + ); + + expect(resp.statusCode).toBe(404); + }); + + test('should retrieve 404 if user does not have access to test definition', async () => { + const testRunRepository = Container.get(TestRunRepository); + const testRun = await testRunRepository.createTestRun(otherTestDefinition.id); + + const resp = await authOwnerAgent.delete( + `/evaluation/test-definitions/${otherTestDefinition.id}/runs/${testRun.id}`, + ); + + expect(resp.statusCode).toBe(404); + }); +});