Skip to content

Commit

Permalink
restore configuration in the schema, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
despadam committed Aug 7, 2024
1 parent 8f5b7bf commit b7eefc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
13 changes: 5 additions & 8 deletions src/jobs/jobs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -568,11 +567,11 @@ export class JobsController {
async performJobStatusUpdateAction(jobInstance: JobClass): Promise<void> {
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",
Expand Down Expand Up @@ -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);

Check failure on line 682 in src/jobs/jobs.controller.ts

View workflow job for this annotation

GitHub Actions / eslint

Replace `currentJobInstance.type` with `⏎······currentJobInstance.type,⏎····`

const ability = this.caslAbilityFactory.createForUser(
request.user as JWTUser,
Expand Down
5 changes: 3 additions & 2 deletions src/jobs/schemas/job.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
19 changes: 10 additions & 9 deletions test/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
});
});

Expand All @@ -349,6 +348,8 @@ describe("1100: Jobs: Test New Job Model", () => {
type: "all_access",
ownerUser: "admin",
ownerGroup: "admin",
jobParams: {
},
};

return request(appUrl)
Expand Down Expand Up @@ -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",
Expand All @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down Expand Up @@ -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.");
});
});

Expand Down

0 comments on commit b7eefc3

Please sign in to comment.