Skip to content

Commit

Permalink
feat: add tests for udpate public-projects endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvalave authored and hotzevzl committed Apr 29, 2022
1 parent 0157be5 commit 5acea48
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/apps/api/test/project/projects.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ export const getFixtures = async () => {
expect(response.body.data.length).toEqual(1);
expect(response.body.data[0].id).toEqual(publicProjectId);
},
ThenPublicProjectIsUpdated: (
publicProjectId: string,
response: request.Response,
) => {
expect(response.status).toEqual(200);
expect(response.body.data.id).toEqual(publicProjectId);
expect(response.body.data.type).toEqual('published_projects');
expect(response.body.data.attributes.name).toEqual('Updated Name');
expect(response.body.data.attributes.description).toEqual(
'Updated Description',
);
expect(response.body.data.attributes.location).toEqual(
'Updated Location',
);
},
ThenPublicProjectWithUnderModerationStatusIsAvailable: (
publicProjectId: string,
response: request.Response,
Expand Down Expand Up @@ -288,6 +303,24 @@ export const getFixtures = async () => {
featuredScenarioId: scenarioId,
})
.set('Authorization', `Bearer ${randomUserToken}`),
WhenUpdatingAPublicProject: async (projectId: string) =>
await request(app.getHttpServer())
.patch(`/api/v1/projects/published-projects/${projectId}`)
.send({
name: 'Updated Name',
description: 'Updated Description',
location: 'Updated Location',
})
.set('Authorization', `Bearer ${randomUserToken}`),
WhenUpdatingAPublicProjectAsNotIncludedUser: async (projectId: string) =>
await request(app.getHttpServer())
.patch(`/api/v1/projects/published-projects/${projectId}`)
.send({
name: 'Updated Name',
description: 'Updated Description',
location: 'Updated Location',
})
.set('Authorization', `Bearer ${notIncludedUserToken}`),
WhenUnpublishingAProjectAsProjectOwner: async (projectId: string) =>
await request(app.getHttpServer())
.post(`/api/v1/projects/${projectId}/unpublish`)
Expand Down
20 changes: 20 additions & 0 deletions api/apps/api/test/project/public-projects.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ test(`when unpublishing a public project that is under moderation as a platform
fixtures.ThenNoProjectIsAvailable(response);
});

test(`when updating a public project as the project owner`, async () => {
const projectId = await fixtures.GivenPrivateProjectWasCreated();
const scenarioId = await fixtures.GivenScenarioWasCreated(projectId);
let response = await fixtures.WhenPublishingAProject(projectId, scenarioId);
fixtures.ThenCreatedIsReturned(response);
response = await fixtures.WhenUpdatingAPublicProject(projectId);
fixtures.ThenPublicProjectIsUpdated(projectId, response);
});

test(`when updating a public project as not project owner`, async () => {
const projectId = await fixtures.GivenPrivateProjectWasCreated();
const scenarioId = await fixtures.GivenScenarioWasCreated(projectId);
let response = await fixtures.WhenPublishingAProject(projectId, scenarioId);
fixtures.ThenCreatedIsReturned(response);
response = await fixtures.WhenUpdatingAPublicProjectAsNotIncludedUser(
projectId,
);
fixtures.ThenForbiddenIsReturned(response);
});

test(`when cloning a project that does not belong to the requesting user, it should import the public project`, async () => {
const projectId = await fixtures.GivenPublicProjectWasCreated();
const exportId = await fixtures.GivenProjectHasAnExportPrepared(projectId);
Expand Down

0 comments on commit 5acea48

Please sign in to comment.