Skip to content

Commit

Permalink
Increase test coverage for input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 20, 2024
1 parent 1674bf4 commit d442ffc
Showing 1 changed file with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("Workflow Tests Validation Rules", () => {
rule = new WorkflowInputsValidationRule();
});

it("should pass validation when a valid input is defined in the workflow", async () => {
it("should pass validation when a valid input is defined in the workflow (inline)", async () => {
const testDocumentContents = `
- doc: The docs
job:
Expand All @@ -74,6 +74,20 @@ describe("Workflow Tests Validation Rules", () => {
expect(diagnostics.length).toBe(0);
});

it("should pass validation when a valid input is defined in the workflow", async () => {
const testDocumentContents = `
- doc: The docs
job:
My fake dataset:
class: File
`;

const diagnostics = await validate(testDocumentContents);

expect(diagnostics).not.toBeNull();
expect(diagnostics.length).toBe(0);
});

it("should error when an input is not defined in the workflow", async () => {
const testDocumentContents = `
- doc: The docs
Expand All @@ -87,6 +101,39 @@ describe("Workflow Tests Validation Rules", () => {
expect(diagnostics[0].message).toBe('Input "Missing input" is not defined in the associated workflow.');
expect(diagnostics[0].severity).toBe(DiagnosticSeverity.Error);
});

it("should error when an input has an invalid type (inline)", async () => {
const testDocumentContents = `
- doc: The docs
job:
My fake string: 5
`;

const diagnostics = await validate(testDocumentContents);

expect(diagnostics.length).toBe(1);
expect(diagnostics[0].message).toBe(
'Input "My fake string" has an invalid type. Expected "string" but found "number".'
);
expect(diagnostics[0].severity).toBe(DiagnosticSeverity.Error);
});

it("should error when an input has an invalid type", async () => {
const testDocumentContents = `
- doc: The docs
job:
My fake number:
class: string
`;

const diagnostics = await validate(testDocumentContents);

expect(diagnostics.length).toBe(1);
expect(diagnostics[0].message).toBe(
'Input "My fake number" has an invalid type. Expected "int" but found "object".'
);
expect(diagnostics[0].severity).toBe(DiagnosticSeverity.Error);
});
});

describe("WorkflowOutputsValidationRule", () => {
Expand Down

0 comments on commit d442ffc

Please sign in to comment.