diff --git a/api/apps/api/test/projects/crud/project-get.e2e-spec.ts b/api/apps/api/test/projects/crud/project-get.e2e-spec.ts index ad30adb5db..66ba34be2e 100644 --- a/api/apps/api/test/projects/crud/project-get.e2e-spec.ts +++ b/api/apps/api/test/projects/crud/project-get.e2e-spec.ts @@ -32,3 +32,9 @@ test(`getting a project where the user is not in project`, async () => { ); fixtures.ThenForbiddenIsReturned(response); }); + +test(`if a project was created with malformed grid data and not GC'ed yet, it should not be included in project listings`, async () => { + const projectId = await fixtures.GivenPrivateProjectWithMalformedGridDataWasCreated(); + const response = await fixtures.WhenGettingUserProjects(); + fixtures.ThenProjectIsNotIncludedInProjectsList(projectId, response); +}); diff --git a/api/apps/api/test/projects/projects.fixtures.ts b/api/apps/api/test/projects/projects.fixtures.ts index 968f53ceed..b833354095 100644 --- a/api/apps/api/test/projects/projects.fixtures.ts +++ b/api/apps/api/test/projects/projects.fixtures.ts @@ -25,6 +25,7 @@ import { bootstrapApplication } from '../utils/api-application'; import { EventBusTestUtils } from '../utils/event-bus.test.utils'; import { ScenariosTestUtils } from '../utils/scenarios.test.utils'; import { ScenarioType } from '@marxan-api/modules/scenarios/scenario.api.entity'; +import { Project } from '@marxan-api/modules/projects/project.api.entity'; export const getFixtures = async () => { const app = await bootstrapApplication([CqrsModule], [EventBusTestUtils]); @@ -35,6 +36,9 @@ export const getFixtures = async () => { const publishedProjectsRepo: Repository = app.get( getRepositoryToken(PublishedProject), ); + const projectsRepo: Repository = app.get( + getRepositoryToken(Project), + ); const cleanups: (() => Promise)[] = []; const apiEvents = app.get(ApiEventsService); @@ -100,6 +104,23 @@ export const getFixtures = async () => { cleanups.push(cleanup); return projectId; }, + GivenPrivateProjectWithMalformedGridDataWasCreated: async () => { + const { cleanup, projectId } = await GivenProjectExists( + app, + randomUserToken, + ); + cleanups.push(cleanup); + projectsRepo.update( + { id: projectId }, + { + countryId: undefined, + adminAreaLevel1Id: undefined, + adminAreaLevel2Id: undefined, + planningAreaId: undefined, + }, + ); + return projectId; + }, GivenScenarioWasCreated: async (projectId: string, name?: string) => { const result = await ScenariosTestUtils.createScenario( app, @@ -336,10 +357,23 @@ export const getFixtures = async () => { ThenForbiddenIsReturned: (response: request.Response) => { expect(response.status).toEqual(403); }, + ThenProjectIsNotIncludedInProjectsList: ( + projectId: string, + response: request.Response, + ) => { + const allIdsOfProjectsInResponse = response.body.data.map( + (project: { id: string }) => project.id, + ); + expect(allIdsOfProjectsInResponse).not.toContain(projectId); + }, WhenGettingProject: async (projectId: string) => await request(app.getHttpServer()) .get(`/api/v1/projects/${projectId}`) .set('Authorization', `Bearer ${randomUserToken}`), + WhenGettingUserProjects: async () => + await request(app.getHttpServer()) + .get(`/api/v1/projects`) + .set('Authorization', `Bearer ${randomUserToken}`), WhenGettingProjectAsNotIncludedUser: async (projectId: string) => await request(app.getHttpServer()) .get(`/api/v1/projects/${projectId}`)