Skip to content

Commit

Permalink
add test: do not include malformed projects in project lists
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Oct 12, 2023
1 parent 0c7a2f9 commit 1f032f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/apps/api/test/projects/crud/project-get.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
34 changes: 34 additions & 0 deletions api/apps/api/test/projects/projects.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -35,6 +36,9 @@ export const getFixtures = async () => {
const publishedProjectsRepo: Repository<PublishedProject> = app.get(
getRepositoryToken(PublishedProject),
);
const projectsRepo: Repository<Project> = app.get(
getRepositoryToken(Project),
);
const cleanups: (() => Promise<void>)[] = [];

const apiEvents = app.get(ApiEventsService);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit 1f032f5

Please sign in to comment.