Skip to content

Commit 3bb795a

Browse files
authored
fix: remove default values in DTOs that cause value overwrite on update (#1802)
<!-- Follow semantic-release guidelines for the PR title, which is used in the changelog. Title should follow the format `<type>(<scope>): <subject>`, where - Type is one of: build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|BREAKING CHANGE - Scope (optional) describes the place of the change (eg a particular milestone) and is usually omitted - subject should be a non-capitalized one-line description in present imperative tense and not ending with a period See https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines for more details. --> ## Description This PR aims to fix the `size` and `numberOfFiles` fields overwrite in the partial update of a dataset. ## Motivation `size` and `numberOfFiles` fields were overwritten every time when a partial update on a dataset was performed. ## Fixes <!-- Please provide a list of the issues fixed by this PR --> * #1688 ## Changes: <!-- Please provide a list of the changes implemented by this PR --> * changes made ## Tests included - [x] Included for each change/fix? - [x] Passing? <!-- Merge will not be approved unless tests pass --> ## Documentation - [ ] swagger documentation updated (required for API changes) - [ ] official documentation updated ### official documentation info <!-- If you have updated the official documentation, please provide PR # and URL of the updated pages -->
2 parents 0d2bc2a + 693b504 commit 3bb795a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/datasets/dto/update-dataset-obsolete.dto.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
9696
})
9797
@IsOptional()
9898
@IsInt()
99-
readonly size?: number = 0;
99+
readonly size?: number;
100100

101101
@ApiProperty({
102102
type: Number,
@@ -107,7 +107,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
107107
})
108108
@IsOptional()
109109
@IsInt()
110-
readonly packedSize?: number = 0;
110+
readonly packedSize?: number;
111111

112112
@ApiProperty({
113113
type: Number,
@@ -118,7 +118,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
118118
})
119119
@IsOptional()
120120
@IsInt()
121-
readonly numberOfFiles?: number = 0;
121+
readonly numberOfFiles?: number;
122122

123123
@ApiProperty({
124124
type: Number,
@@ -128,7 +128,7 @@ export class UpdateDatasetObsoleteDto extends OwnableDto {
128128
})
129129
@IsOptional()
130130
@IsInt()
131-
readonly numberOfFilesArchived?: number = 0;
131+
readonly numberOfFilesArchived?: number;
132132

133133
@ApiProperty({
134134
type: Date,

src/proposals/dto/update-proposal.dto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class UpdateProposalDto extends OwnableDto {
9696
*/
9797
@IsOptional()
9898
@IsObject()
99-
readonly metadata?: Record<string, unknown> = {};
99+
readonly metadata?: Record<string, unknown>;
100100

101101
/**
102102
* Parent proposal id.

test/RawDatasetDatablock.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("1800: RawDatasetDatablock: Test Datablocks and their relation to raw D
1313
before(() => {
1414
db.collection("Dataset").deleteMany({});
1515
});
16-
beforeEach(async() => {
16+
beforeEach(async () => {
1717
accessTokenAdminIngestor = await utils.getToken(appUrl, {
1818
username: "adminIngestor",
1919
password: TestData.Accounts["adminIngestor"]["password"],
@@ -59,6 +59,27 @@ describe("1800: RawDatasetDatablock: Test Datablocks and their relation to raw D
5959
});
6060
});
6161

62+
it("0021: partial update of the dataset should not overwrite the size and number of files", () => {
63+
return request(appUrl)
64+
.patch(`/api/v3/datasets/${datasetPid}`)
65+
.send(TestData.PatchInstrument1)
66+
.set("Accept", "application/json")
67+
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
68+
.expect(TestData.SuccessfulPatchStatusCode)
69+
.expect("Content-Type", /json/)
70+
.then((res) => {
71+
res.body.should.have
72+
.property("instrumentId")
73+
.and.be.equal(TestData.PatchInstrument1["instrumentId"]);
74+
res.body.should.have
75+
.property("size")
76+
.and.equal(TestData.DataBlockCorrect.size);
77+
res.body.should.have
78+
.property("numberOfFiles")
79+
.and.equal(TestData.DataBlockCorrect.dataFileList.length);
80+
});
81+
});
82+
6283
it("0030: adds the same datablock again which should fail because it is already stored", async () => {
6384
return request(appUrl)
6485
.post(`/api/v3/datasets/${datasetPid}/Datablocks`)

0 commit comments

Comments
 (0)