From 5acea489e242ab28aba41a48b62fceec84f4ab8d Mon Sep 17 00:00:00 2001 From: Ruben Vallejo Date: Thu, 28 Apr 2022 12:44:32 +0200 Subject: [PATCH] feat: add tests for udpate public-projects endpoint --- .../api/test/project/projects.fixtures.ts | 33 +++++++++++++++++++ .../test/project/public-projects.e2e-spec.ts | 20 +++++++++++ 2 files changed, 53 insertions(+) diff --git a/api/apps/api/test/project/projects.fixtures.ts b/api/apps/api/test/project/projects.fixtures.ts index 41a24b41f4..c6e081cb7b 100644 --- a/api/apps/api/test/project/projects.fixtures.ts +++ b/api/apps/api/test/project/projects.fixtures.ts @@ -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, @@ -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`) diff --git a/api/apps/api/test/project/public-projects.e2e-spec.ts b/api/apps/api/test/project/public-projects.e2e-spec.ts index 25c18d9dd0..b2a02e9de3 100644 --- a/api/apps/api/test/project/public-projects.e2e-spec.ts +++ b/api/apps/api/test/project/public-projects.e2e-spec.ts @@ -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);