Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch dataset #1461

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ export class DatasetsController {
@Req() request: Request,
@Param("pid") pid: string,
@Body()
updateDatasetDto:
updateDatasetObsoleteDto:
| PartialUpdateRawDatasetObsoleteDto
| PartialUpdateDerivedDatasetObsoleteDto,
): Promise<OutputDatasetObsoleteDto | null> {
Expand All @@ -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 =
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/DatasetAuthorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
48 changes: 48 additions & 0 deletions test/RawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Loading