Skip to content

Commit

Permalink
Add tests for StepExportErrorValidationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jun 21, 2024
1 parent edc7b62 commit 433960c
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
45 changes: 45 additions & 0 deletions server/gx-workflow-ls-format2/tests/integration/validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Diagnostic, ValidationRule } from "@gxwf/server-common/src/languageTypes";
import { 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 @@ -123,5 +124,49 @@ steps:
expect(diagnostics).toHaveLength(0);
});
});

describe("StepExportErrorValidationRule", () => {
beforeAll(() => {
rule = new StepExportErrorValidationRule();
});

it("should report error when step contains export errors", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
errors: error in step
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(1);
expect(diagnostics[0].message).toContain(
"Tool step contains error indicated during Galaxy export - error in step"
);
});

it("should not report error when step does not contain export errors", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(0);
});

it("should not report error when step errors are null", async () => {
const content = `
class: GalaxyWorkflow
steps:
step:
tool_id: tool_id
errors: null
`;
const diagnostics = await validateRule(content);
expect(diagnostics).toHaveLength(0);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { DiagnosticSeverity, ValidationRule } from "@gxwf/server-common/src/languageTypes";
import { RequiredPropertyValidationRule } from "@gxwf/server-common/src/providers/validation/rules";
import {
RequiredPropertyValidationRule,
StepExportErrorValidationRule,
} from "@gxwf/server-common/src/providers/validation/rules";
import { WorkflowOutputLabelValidationRule } from "../../src/validation/rules/WorkflowOutputLabelValidationRule";
import { createNativeWorkflowDocument } from "../testHelpers";
import { TestWorkflowProvider } from "../testWorkflowProvider";
Expand Down Expand Up @@ -239,4 +242,53 @@ describe("Custom Validation Rules", () => {
});
});
});

describe("StepExportErrorValidationRule", () => {
beforeAll(() => {
rule = new StepExportErrorValidationRule();
});

it("should not provide diagnostics when there are no steps", async () => {
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.workflows.validation.withoutSteps);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});

it("should not provide diagnostics when there are no errors in the steps", async () => {
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.workflows.validation.withThreeSteps);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});

it("should provide diagnostics when the steps contain errors", async () => {
const wfContents = `{
"a_galaxy_workflow": "true",
"steps": {
"0": {
"errors": "Error in step 0",
},
}
}`;
const wfDocument = createNativeWorkflowDocument(wfContents);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(1);
diagnostics.forEach((diagnostic) => {
expect(diagnostic.message).toBe('Tool step contains error indicated during Galaxy export - "Error in step 0"');
});
});

it("should not provide diagnostics when the errors property is null", async () => {
const wfContents = `{
"a_galaxy_workflow": "true",
"steps": {
"0": {
"errors": null,
},
}
}`;
const wfDocument = createNativeWorkflowDocument(wfContents);
const diagnostics = await rule.validate(wfDocument);
expect(diagnostics).toHaveLength(0);
});
});
});

0 comments on commit 433960c

Please sign in to comment.