Skip to content

fix: remove default values in DTOs that cause value overwrite on update #1802

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions src/datasets/dto/update-dataset-obsolete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
})
@IsOptional()
@IsInt()
readonly size?: number = 0;
readonly size?: number;

@ApiProperty({
type: Number,
Expand All @@ -107,7 +107,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
})
@IsOptional()
@IsInt()
readonly packedSize?: number = 0;
readonly packedSize?: number;

@ApiProperty({
type: Number,
Expand All @@ -118,7 +118,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
})
@IsOptional()
@IsInt()
readonly numberOfFiles?: number = 0;
readonly numberOfFiles?: number;

@ApiProperty({
type: Number,
Expand All @@ -128,7 +128,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
})
@IsOptional()
@IsInt()
readonly numberOfFilesArchived?: number = 0;
readonly numberOfFilesArchived?: number;

@ApiProperty({
type: Date,
Expand Down
2 changes: 1 addition & 1 deletion src/proposals/dto/update-proposal.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class UpdateProposalDto extends OwnableDto {
*/
@IsOptional()
@IsObject()
readonly metadata?: Record<string, unknown> = {};
readonly metadata?: Record<string, unknown>;

/**
* Parent proposal id.
Expand Down
23 changes: 22 additions & 1 deletion test/RawDatasetDatablock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("1800: RawDatasetDatablock: Test Datablocks and their relation to raw D
before(() => {
db.collection("Dataset").deleteMany({});
});
beforeEach(async() => {
beforeEach(async () => {
accessTokenAdminIngestor = await utils.getToken(appUrl, {
username: "adminIngestor",
password: TestData.Accounts["adminIngestor"]["password"],
Expand Down Expand Up @@ -59,6 +59,27 @@ describe("1800: RawDatasetDatablock: Test Datablocks and their relation to raw D
});
});

it("0021: partial update of the dataset should not overwrite the size and number of files", () => {
return request(appUrl)
.patch(`/api/v3/datasets/${datasetPid}`)
.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.equal(TestData.PatchInstrument1["instrumentId"]);
res.body.should.have
.property("size")
.and.equal(TestData.DataBlockCorrect.size);
res.body.should.have
.property("numberOfFiles")
.and.equal(TestData.DataBlockCorrect.dataFileList.length);
});
});

it("0030: adds the same datablock again which should fail because it is already stored", async () => {
return request(appUrl)
.post(`/api/v3/datasets/${datasetPid}/Datablocks`)
Expand Down