From bf4c29b621644fac5d3e10080a763ce8e27bb88e Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 18 Apr 2024 13:49:08 +0200 Subject: [PATCH] chore: add enterprise extension point to enable change requests on project creation (#6881) This PR adds an optional function parameter to the `createProject` function that is intended to enable change requests for the newly created project. The assumption is that all the logic within will be decided in the enterprise impl. The only thing we want to verify here is that it is called after the project has been created. --- .../features/project/project-service.test.ts | 39 +++++++++++++++++++ src/lib/features/project/project-service.ts | 3 ++ 2 files changed, 42 insertions(+) create mode 100644 src/lib/features/project/project-service.test.ts diff --git a/src/lib/features/project/project-service.test.ts b/src/lib/features/project/project-service.test.ts new file mode 100644 index 00000000000..4dc601dadba --- /dev/null +++ b/src/lib/features/project/project-service.test.ts @@ -0,0 +1,39 @@ +import { createTestConfig } from '../../../test/config/test-config'; +import { RoleName } from '../../types'; +import { createFakeProjectService } from './createProjectService'; + +describe('enterprise extension: enable change requests', () => { + test('it calls the change request enablement function', async () => { + expect.assertions(1); + + const config = createTestConfig(); + const service = createFakeProjectService(config); + + // @ts-expect-error: if we don't set this up, the test will fail due to a missing role. + service.accessService.createRole({ + name: RoleName.OWNER, + description: 'Project owner', + createdByUserId: -1, + }); + + const projectId = 'fake-project-id'; + await service.createProject( + { + id: projectId, + name: 'fake-project-name', + }, + { + id: 5, + permissions: [], + isAPI: false, + }, + async () => { + // @ts-expect-error: we want to verify that the project /has/ + // been created when calling the function. + const project = await service.projectStore.get(projectId); + + expect(project).toBeTruthy(); + }, + ); + }); +}); diff --git a/src/lib/features/project/project-service.ts b/src/lib/features/project/project-service.ts index 793783d46d6..7fa036cf2d7 100644 --- a/src/lib/features/project/project-service.ts +++ b/src/lib/features/project/project-service.ts @@ -283,6 +283,7 @@ export default class ProjectService { async createProject( newProject: CreateProject, user: IUser, + enableChangeRequestsForSpecifiedEnvironments: () => Promise = async () => {}, ): Promise { await this.validateProjectEnvironments(newProject.environments); @@ -308,6 +309,8 @@ export default class ProjectService { }), ); + await enableChangeRequestsForSpecifiedEnvironments(); + await this.accessService.createDefaultProjectRoles(user, data.id); await this.eventService.storeEvent({