Skip to content

Commit

Permalink
added tests and fixed failing one
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrosx committed Oct 25, 2024
1 parent e7f8537 commit 8bf7c94
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,12 +1233,15 @@ export class DatasetsController {
}

// NOTE: Default validation pipe does not validate union types. So we need custom validation.
await this.validateDatasetObsolete(
updateDatasetObsoleteDto,
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 @@ -1257,12 +1260,13 @@ export class DatasetsController {
}

const updateDatasetDto = this.convertObsoleteToCurrentSchema(
updateDatasetObsoleteDto,
validatedUpdateDatasetObsoleteDto,
) as UpdateDatasetDto;

return this.convertCurrentToObsoleteSchema(
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
34 changes: 33 additions & 1 deletion test/RawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,39 @@ describe("1900: RawDataset: Raw Datasets", () => {
res.body.should.have.property("proposalId").and.be.string;
res.body.should.have
.property("proposalId")
.and.be.equal(TestData.PatchProposal1["proposal"]);
.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"]);
});
});

Expand Down
8 changes: 8 additions & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,14 @@ const TestData = {
proposalId: "10.540.16635/20240124",
},

PatchInstrument1: {
instrumentId: "fb0f3b58-92c9-11ef-9aeb-632c6e2960a1",
},

PatchSample1: {
sampleId: "f3cfc114-92c9-11ef-8ed4-f3b97158e36b",
},

PatchComment: {
comment: "test",
},
Expand Down

0 comments on commit 8bf7c94

Please sign in to comment.