diff --git a/src/datasets/datasets.controller.ts b/src/datasets/datasets.controller.ts index 2f9491244..1c1e9a969 100644 --- a/src/datasets/datasets.controller.ts +++ b/src/datasets/datasets.controller.ts @@ -1222,7 +1222,7 @@ export class DatasetsController { @Req() request: Request, @Param("pid") pid: string, @Body() - updateDatasetDto: + updateDatasetObsoleteDto: | PartialUpdateRawDatasetObsoleteDto | PartialUpdateDerivedDatasetObsoleteDto, ): Promise { @@ -1233,12 +1233,15 @@ export class DatasetsController { } // NOTE: Default validation pipe does not validate union types. So we need custom validation. - await this.validateDatasetObsolete( - updateDatasetDto, - foundDataset.type === "raw" - ? PartialUpdateRawDatasetObsoleteDto - : PartialUpdateDerivedDatasetObsoleteDto, - ); + const validatedUpdateDatasetObsoleteDto = + (await this.validateDatasetObsolete( + updateDatasetObsoleteDto, + foundDataset.type === "raw" + ? PartialUpdateRawDatasetObsoleteDto + : PartialUpdateDerivedDatasetObsoleteDto, + )) as + | PartialUpdateRawDatasetObsoleteDto + | PartialUpdateDerivedDatasetObsoleteDto; // NOTE: We need DatasetClass instance because casl module can not recognize the type from dataset mongo database model. If other fields are needed can be added later. const datasetInstance = @@ -1256,9 +1259,14 @@ export class DatasetsController { throw new ForbiddenException("Unauthorized to update this dataset"); } - return this.convertCurrentToObsoleteSchema( + const updateDatasetDto = this.convertObsoleteToCurrentSchema( + validatedUpdateDatasetObsoleteDto, + ) as UpdateDatasetDto; + + const res = this.convertCurrentToObsoleteSchema( await this.datasetsService.findByIdAndUpdate(pid, updateDatasetDto), ); + return res; } // PUT /datasets/:id diff --git a/test/DatasetAuthorization.js b/test/DatasetAuthorization.js index 3aeb7f749..ed0ef342f 100644 --- a/test/DatasetAuthorization.js +++ b/test/DatasetAuthorization.js @@ -504,7 +504,11 @@ describe("0300: DatasetAuthorization: Test access to dataset", () => { .set("Accept", "application/json") .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) .expect(TestData.SuccessfulPatchStatusCode) - .expect("Content-Type", /json/); + .expect("Content-Type", /json/) + .then((res) => { + res.body["pid"].should.be.equal(datasetPid2); + res.body["isPublished"].should.be.equal(true); + }); }); it("0350: full query for datasets for User 2", async () => { diff --git a/test/RawDataset.js b/test/RawDataset.js index 6e9fcd748..a59ab67ef 100644 --- a/test/RawDataset.js +++ b/test/RawDataset.js @@ -276,6 +276,54 @@ describe("1900: RawDataset: Raw Datasets", () => { ); }); + it("0125: should update proposal of the dataset", async () => { + return request(appUrl) + .patch("/api/v3/datasets/" + pid) + .send(TestData.PatchProposal1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulPatchStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("proposalId").and.be.string; + res.body.should.have + .property("proposalId") + .and.be.equal(TestData.PatchProposal1["proposalId"]); + }); + }); + + it("0126: should update instrument of the dataset", async () => { + return request(appUrl) + .patch("/api/v3/datasets/" + pid) + .send(TestData.PatchInstrument1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulPatchStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("instrumentId").and.be.string; + res.body.should.have + .property("instrumentId") + .and.be.equal(TestData.PatchInstrument1["instrumentId"]); + }); + }); + + it("0127: should update sample of the dataset", async () => { + return request(appUrl) + .patch("/api/v3/datasets/" + pid) + .send(TestData.PatchSample1) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.SuccessfulPatchStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("sampleId").and.be.string; + res.body.should.have + .property("sampleId") + .and.be.equal(TestData.PatchSample1["sampleId"]); + }); + }); + it("0130: should update comment of the dataset", async () => { return request(appUrl) .patch("/api/v3/datasets/" + pid) diff --git a/test/TestData.js b/test/TestData.js index 801a45768..49385e4dd 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -834,6 +834,18 @@ const TestData = { name: "ESS-wrong", }, + PatchProposal1: { + proposalId: "10.540.16635/20240124", + }, + + PatchInstrument1: { + instrumentId: "fb0f3b58-92c9-11ef-9aeb-632c6e2960a1", + }, + + PatchSample1: { + sampleId: "f3cfc114-92c9-11ef-8ed4-f3b97158e36b", + }, + PatchComment: { comment: "test", },