Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/published-data/dto/update-published-data.v4.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class UpdatePublishedDataV4Dto {
*/
@IsObject()
@IsOptional()
readonly metadata?: Record<string, unknown>;
readonly metadata?: Record<string, unknown> = {};
Comment thread
fpotier marked this conversation as resolved.
Outdated
}

export class PartialUpdatePublishedDataV4Dto extends PartialType(
Expand Down
3 changes: 3 additions & 0 deletions src/published-data/published-data.v4.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class PublishedDataV4Controller {
async create(
@Body() createPublishedDataDto: CreatePublishedDataV4Dto,
): Promise<PublishedData> {
await this.validatorService.validate(createPublishedDataDto);
return this.publishedDataService.create(createPublishedDataDto);
}

Expand Down Expand Up @@ -390,6 +391,7 @@ export class PublishedDataV4Controller {
}
}

await this.validatorService.validate(updatePublishedDataDto);
return this.publishedDataService.update(
{ doi: id },
updatePublishedDataDto,
Expand Down Expand Up @@ -715,6 +717,7 @@ export class PublishedDataV4Controller {
);
}

await this.validatorService.validate(data);
await this.publishedDataService.update({ doi: id }, data);

return returnValue;
Expand Down
61 changes: 61 additions & 0 deletions test/PublishedDataV4.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,65 @@ describe("1600: PublishedDataV4: Test of access to published data v4 endpoints",
.expect(TestData.NotFoundStatusCode)
.expect("Content-Type", /json/);
});

describe("Ajv extensions are executed on create/save", () => {
const { metadata, ...strippedPublishedData } = publishedData;
const expectedPublicationYear = new Date().getFullYear();
Comment thread
fpotier marked this conversation as resolved.
let id;

it("should set 'metadata.publicationYear' on create", async () => {
return request(appUrl)
.post("/api/v4/PublishedData")
.send(strippedPublishedData)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.EntryCreatedStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("metadata");
res.body.metadata.should.have
.property("publicationYear")
.and.equal(expectedPublicationYear);
id = encodeURIComponent(res.body.doi);
});
});

it("should set 'metadata.publicationYear' on patch", async () => {
return request(appUrl)
.patch(`/api/v4/PublishedData/${id}`)
.send(strippedPublishedData)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.EntryValidStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("metadata");
res.body.metadata.should.have
.property("publicationYear")
.and.equal(expectedPublicationYear);
});
});

it("should set 'metadata.publicationYear' on resync", async () => {
request(appUrl)
.post(`/api/v4/PublishedData/${id}/resync`)
.send(strippedPublishedData)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.EntryCreatedStatusCode);
Comment thread
fpotier marked this conversation as resolved.

return request(appUrl)
.get(`/api/v4/PublishedData/${id}`)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.EntryValidStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("metadata");
res.body.metadata.should.have
.property("publicationYear")
.and.equal(expectedPublicationYear);
});
});
});
});
Loading