Skip to content

Commit

Permalink
fix: sdk generation error caused by incorrect swagger decorator (#1455)
Browse files Browse the repository at this point in the history
* fix: use @ApiBody decorator for body parameters

* add pending_registration status by default for published-data.schema

* include api test for the change
  • Loading branch information
Junjiequan authored Oct 23, 2024
1 parent 30dc21e commit 473d23d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/published-data/published-data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "./dto/update-published-data.dto";
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
Expand Down Expand Up @@ -76,10 +77,7 @@ export class PublishedDataController {
async create(
@Body() createPublishedDataDto: CreatePublishedDataDto,
): Promise<PublishedData> {
return this.publishedDataService.create({
...createPublishedDataDto,
status: "pending_registration",
});
return this.publishedDataService.create(createPublishedDataDto);
}

// GET /publisheddata
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/published-data/schemas/published-data.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
18 changes: 17 additions & 1 deletion test/PublishedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let accessTokenAdminIngestor = null,
doi = null;

const publishedData = { ...TestData.PublishedData };
const defaultStatus = "pending_registration";

const origDataBlock = { ...TestData.OrigDataBlockCorrect1 };

Expand All @@ -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"],
Expand All @@ -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)
Expand Down

0 comments on commit 473d23d

Please sign in to comment.