From b7eefc31b96669565621dd58742cc082dae957a3 Mon Sep 17 00:00:00 2001 From: Despina Adamopoulou Date: Wed, 7 Aug 2024 13:51:56 +0200 Subject: [PATCH] restore configuration in the schema, fix tests --- src/jobs/jobs.controller.ts | 13 +++++-------- src/jobs/schemas/job.schema.ts | 5 +++-- test/Jobs.js | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/jobs/jobs.controller.ts b/src/jobs/jobs.controller.ts index edfe35200..11ad05ba4 100644 --- a/src/jobs/jobs.controller.ts +++ b/src/jobs/jobs.controller.ts @@ -392,8 +392,7 @@ export class JobsController { jobInstance.contactEmail = jobCreateDto.contactEmail; jobInstance.jobParams = jobCreateDto.jobParams; jobInstance.datasetsValidation = false; - jobInstance.configVersion = - jobConfiguration[JobsConfigSchema.ConfigVersion]; + jobInstance.configuration = jobConfiguration; jobInstance.statusCode = "Initializing"; jobInstance.statusMessage = "Building and validating job, verifying authorization"; @@ -568,11 +567,11 @@ export class JobsController { async performJobStatusUpdateAction(jobInstance: JobClass): Promise { const jobConfig = this.getJobTypeConfiguration(jobInstance.type); - // TODO - do we need to do something with the new configVersion ? - if (jobConfig.configVersion !== jobInstance.configVersion) { + // TODO - what shall we do when configVersion does not match? + if (jobConfig.configVersion !== jobInstance.configuration.configVersion) { Logger.log( ` - Job was created with configVersion ${jobInstance.configVersion}. + Job was created with configVersion ${jobInstance.configuration.configVersion}. Current configVersion is ${jobConfig.configVersion}. `, "JobStatusUpdate", @@ -680,9 +679,7 @@ export class JobsController { } const currentJobInstance = await this.generateJobInstanceForPermissions(currentJob); - currentJobInstance.configVersion = this.getJobTypeConfiguration( - currentJobInstance.type, - )[JobsConfigSchema.ConfigVersion]; + currentJobInstance.configuration = this.getJobTypeConfiguration(currentJobInstance.type); const ability = this.caslAbilityFactory.createForUser( request.user as JWTUser, diff --git a/src/jobs/schemas/job.schema.ts b/src/jobs/schemas/job.schema.ts index fe8e51003..cf0359726 100644 --- a/src/jobs/schemas/job.schema.ts +++ b/src/jobs/schemas/job.schema.ts @@ -3,6 +3,7 @@ import { ApiProperty } from "@nestjs/swagger"; import { Document } from "mongoose"; import { v4 as uuidv4 } from "uuid"; import { OwnableClass } from "src/common/schemas/ownable.schema"; +import { JobConfig } from "../config/jobconfig"; export type JobDocument = JobClass & Document; @@ -122,14 +123,14 @@ export class JobClass extends OwnableClass { @ApiProperty({ type: Object, - description: "Configuration version that was used to create this job.", + description: "Configuration that was used to create this job.", required: true, }) @Prop({ type: Object, required: true, }) - configVersion: string; + configuration: JobConfig; } export const JobSchema = SchemaFactory.createForClass(JobClass); diff --git a/test/Jobs.js b/test/Jobs.js index e9d48638a..08f60dbda 100644 --- a/test/Jobs.js +++ b/test/Jobs.js @@ -340,7 +340,6 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Job parameters need to be defined."); }); }); @@ -349,6 +348,8 @@ describe("1100: Jobs: Test New Job Model", () => { type: "all_access", ownerUser: "admin", ownerGroup: "admin", + jobParams: { + }, }; return request(appUrl) @@ -967,7 +968,7 @@ describe("1100: Jobs: Test New Job Model", () => { }); }); - it("0310: Add a new job as a normal user himself/herself in '#datasetPublic' configuration with one unpublished dataset, which should fail ad forbidden", async () => { + it("0310: Add a new job as a normal user himself/herself in '#datasetPublic' configuration with one unpublished dataset, which should fail as forbidden", async () => { const newDataset = { ...jobDatasetPublic, ownerUser: "user5.1", @@ -987,7 +988,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -1031,7 +1032,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -1204,7 +1205,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -1467,7 +1468,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -1733,7 +1734,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -2025,7 +2026,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); }); @@ -2344,7 +2345,7 @@ describe("1100: Jobs: Test New Job Model", () => { .expect("Content-Type", /json/) .then((res) => { res.body.should.not.have.property("id"); - res.body.should.have.property("message").and.be.equal("Unauthorized to create this dataset."); + res.body.should.have.property("message").and.be.equal("Unauthorized to create this job."); }); });