Skip to content

Commit

Permalink
Merge pull request #1506 from SciCatProject/SWAP-4300-proposal-metadata
Browse files Browse the repository at this point in the history
feat: proposal metadata and tests
  • Loading branch information
martin-trajanovski authored Nov 19, 2024
2 parents 9df26bd + 7d57e8f commit 6773cdc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/proposals/schemas/proposal.schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { ApiProperty } from "@nestjs/swagger";
import { Document } from "mongoose";
import { Document, Schema as MongooseSchema } from "mongoose";

import { OwnableClass } from "src/common/schemas/ownable.schema";
import {
Expand All @@ -18,6 +18,7 @@ export type ProposalDocument = ProposalClass & Document;
getters: true,
},
timestamps: true,
minimize: false,
})
export class ProposalClass extends OwnableClass {
@ApiProperty({
Expand Down Expand Up @@ -163,12 +164,12 @@ export class ProposalClass extends OwnableClass {
MeasurementPeriodList?: MeasurementPeriodClass[];

@ApiProperty({
type: Object,
type: MongooseSchema.Types.Mixed,
required: false,
default: {},
description: "JSON object containing the proposal metadata.",
})
@Prop({ type: Object, required: false, default: {} })
@Prop({ type: MongooseSchema.Types.Mixed, required: false, default: {} })
metadata?: Record<string, unknown>;

@ApiProperty({
Expand Down
29 changes: 26 additions & 3 deletions test/Proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,10 @@ describe("1500: Proposal: Simple Proposal", () => {
});

it("0116: adds a new proposal with a type different than default", async () => {
const proposalType = "DOOR Proposal";
const proposalWithType = {
...TestData.ProposalCorrectComplete,
proposalId: faker.string.numeric(8),
type: proposalType,
type: "DOOR Proposal",
};

return request(appUrl)
Expand All @@ -261,7 +260,31 @@ describe("1500: Proposal: Simple Proposal", () => {
.then((res) => {
res.body.should.have.property("ownerGroup").and.be.string;
res.body.should.have.property("proposalId").and.be.string;
res.body.type.should.be.equal(proposalType);
res.body.type.should.be.equal(proposalWithType.type);
});
});

it("0117: adds a new proposal with metadata", async () => {
const proposalWithMetadata = {
...TestData.ProposalCorrectComplete,
proposalId: faker.string.numeric(8),
metadata: TestData.RawCorrectRandom.scientificMetadata,
};

return request(appUrl)
.post("/api/v3/Proposals")
.send(proposalWithMetadata)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenProposalIngestor}` })
.expect(TestData.EntryCreatedStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("ownerGroup").and.be.string;
res.body.should.have.property("proposalId").and.be.string;
res.body.should.have.property("metadata").and.be.an("object");
JSON.stringify(res.body.metadata).should.be.equal(
JSON.stringify(proposalWithMetadata.metadata),
);
});
});

Expand Down

0 comments on commit 6773cdc

Please sign in to comment.