-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1421 from sbliven/validateaction
feat(jobs): ValidateAction
- Loading branch information
Showing
20 changed files
with
965 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { ValidateAction } from "./validateaction"; | ||
import { CreateJobDto } from "../dto/create-job.dto"; | ||
|
||
const createJobBase = { | ||
type: "validate", | ||
ownerUser: "owner", | ||
ownerGroup: "group", | ||
contactEmail: "[email protected]", | ||
}; | ||
|
||
describe("ValiateAction", () => { | ||
const config = { | ||
actionType: "validate", | ||
request: { | ||
"jobParams.stringVal": { type: "string" }, | ||
"jobParams.requiredArray[*]": { type: "string" }, | ||
"jobParams.numberVal": { type: "number" }, | ||
jobParams: { required: ["nonNull"] }, | ||
}, | ||
}; | ||
const action = new ValidateAction<CreateJobDto>(config); | ||
it("should be configured successfully", async () => { | ||
expect(action).toBeDefined(); | ||
}); | ||
|
||
it("should pass if required params are present", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: 1, | ||
nonNull: "value1", | ||
requiredArray: ["ok"], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).resolves.toBeUndefined(); | ||
}); | ||
|
||
it("should fail if nonNull is missing", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: 1, | ||
//nonNull: "value1", | ||
requiredArray: ["ok"], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Invalid value for 'jobParams'", | ||
); | ||
}); | ||
|
||
it("should fail if string type is wrong", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: 0xdeadbeef, // wrong type | ||
numberVal: 1, | ||
nonNull: "value1", | ||
requiredArray: ["ok"], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Invalid value for 'jobParams.stringVal", | ||
); | ||
}); | ||
|
||
it("should fail if number type is wrong", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: "error", | ||
nonNull: "value1", | ||
requiredArray: ["ok"], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Invalid value for 'jobParams.numberVal'", | ||
); | ||
}); | ||
|
||
it("should fail if requiredArray is ommitted", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: 1, | ||
nonNull: "value1", | ||
//requiredArray: ["ok"], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Requires 'jobParams.requiredArray[*]'", | ||
); | ||
}); | ||
|
||
it("should fail if requiredArray is empty", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: 1, | ||
nonNull: "value1", | ||
requiredArray: [], | ||
}, | ||
}; | ||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Requires 'jobParams.requiredArray[*]'", | ||
); | ||
}); | ||
|
||
it("should fail if requiredArray has the wrong type", async () => { | ||
const dto: CreateJobDto = { | ||
...createJobBase, | ||
jobParams: { | ||
stringVal: "ok", | ||
numberVal: "error", | ||
nonNull: "value1", | ||
requiredArray: [0xdeadbeef], | ||
}, | ||
}; | ||
|
||
await expect(action.validate(dto)).rejects.toThrow( | ||
"Invalid request. Invalid value for 'jobParams.requiredArray[*]'", | ||
); | ||
}); | ||
}); |
Oops, something went wrong.