Skip to content

Commit

Permalink
Add tests for ChildrenRequiredPropertyValidationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 22, 2024
1 parent 22a6598 commit d9d5fa3
Showing 1 changed file with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Diagnostic, ValidationRule } from "@gxwf/server-common/src/languageTypes";
import { StepExportErrorValidationRule } from "@gxwf/server-common/src/providers/validation/rules";
import {
ChildrenRequiredPropertyValidationRule,
StepExportErrorValidationRule,
} from "@gxwf/server-common/src/providers/validation/rules";
import { GalaxyWorkflowFormat2SchemaLoader } from "../../src/schema";
import { GxFormat2SchemaValidationService } from "../../src/services/schemaValidationService";
import { InputTypeValidationRule } from "../../src/validation/rules/InputTypeValidationRule";
Expand Down Expand Up @@ -274,5 +277,68 @@ steps:
expect(diagnostics).toHaveLength(0);
});
});

describe("ChildrenRequiredPropertyValidationRule", () => {
beforeAll(() => {
rule = new ChildrenRequiredPropertyValidationRule("steps", "doc");
});

it("should report error when step is missing required property", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(1);
expect(diagnostics[0].message).toBe('Missing required property "doc".');
});

it("should not report error when all steps have required property", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
doc: step doc
step2:
tool_id: tool_id
doc: step2 doc
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(0);
});

it("should report error when step has empty required property", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
doc:
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(1);
expect(diagnostics[0].message).toBe('Missing required value in property "doc".');
});

it("should not report error when there are no steps", async () => {
const content = `
class: GalaxyWorkflow
steps:
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(0);
});

it("should not report error when the steps property does not exist", async () => {
const content = `
class: GalaxyWorkflow
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(0);
});
});
});
});

0 comments on commit d9d5fa3

Please sign in to comment.