From 2d3b6f9f430f9f077c4eca87316216ecd332079c Mon Sep 17 00:00:00 2001 From: junjiequan Date: Wed, 23 Oct 2024 12:57:49 +0200 Subject: [PATCH 1/3] fix: use @ApiBody decorator for body parameters --- src/published-data/published-data.controller.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/published-data/published-data.controller.ts b/src/published-data/published-data.controller.ts index 0786e9a53..12dd71a5c 100644 --- a/src/published-data/published-data.controller.ts +++ b/src/published-data/published-data.controller.ts @@ -22,6 +22,7 @@ import { } from "./dto/update-published-data.dto"; import { ApiBearerAuth, + ApiBody, ApiOperation, ApiParam, ApiQuery, @@ -76,10 +77,7 @@ export class PublishedDataController { async create( @Body() createPublishedDataDto: CreatePublishedDataDto, ): Promise { - return this.publishedDataService.create({ - ...createPublishedDataDto, - status: "pending_registration", - }); + return this.publishedDataService.create(createPublishedDataDto); } // GET /publisheddata @@ -445,8 +443,7 @@ export class PublishedDataController { description: "The DOI of the published data.", type: String, }) - @ApiParam({ - name: "data", + @ApiBody({ description: "The edited data that will be updated in the database and with OAI Provider if defined.", type: UpdatePublishedDataDto, From 78cd1a7213ef5506c428d43c5413cf42e328c4b3 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Wed, 23 Oct 2024 12:58:36 +0200 Subject: [PATCH 2/3] add pending_registration status by default for published-data.schema --- src/published-data/schemas/published-data.schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/published-data/schemas/published-data.schema.ts b/src/published-data/schemas/published-data.schema.ts index d9e73a30c..d82baa3bf 100644 --- a/src/published-data/schemas/published-data.schema.ts +++ b/src/published-data/schemas/published-data.schema.ts @@ -188,7 +188,7 @@ export class PublishedData { description: "Indication of position in publication workflow e.g. doiRegistered", }) - @Prop({ type: String, required: false }) + @Prop({ type: String, required: false, default: "pending_registration" }) status: string; @ApiProperty({ From 4a2fac1e104881ae7fe0c10396c770a86d6d58a2 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Wed, 23 Oct 2024 13:52:40 +0200 Subject: [PATCH 3/3] include api test for the change --- test/PublishedData.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/PublishedData.js b/test/PublishedData.js index dccfbfcb1..a09c97b38 100644 --- a/test/PublishedData.js +++ b/test/PublishedData.js @@ -15,6 +15,7 @@ let accessTokenAdminIngestor = null, doi = null; const publishedData = { ...TestData.PublishedData }; +const defaultStatus = "pending_registration"; const origDataBlock = { ...TestData.OrigDataBlockCorrect1 }; @@ -38,7 +39,7 @@ describe("1600: PublishedData: Test of access to published data", () => { db.collection("Dataset").deleteMany({}); db.collection("PublishedData").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -65,10 +66,25 @@ describe("1600: PublishedData: Test of access to published data", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.have.property("publisher").and.be.string; + res.body.should.have.property("status").and.equal(defaultStatus); doi = encodeURIComponent(res.body["doi"]); }); }); + it("0015: adds a published data without specifying a status should assign the default status", async () => { + delete publishedData.status; + return request(appUrl) + .post("/api/v3/PublishedData") + .send(publishedData) + .set("Accept", "application/json") + .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) + .expect(TestData.EntryCreatedStatusCode) + .expect("Content-Type", /json/) + .then((res) => { + res.body.should.have.property("status").and.equal(defaultStatus); + }); + }); + it("0020: should fetch this new published data without authorization", async () => { return request(appUrl) .get("/api/v3/PublishedData/" + doi)