From d9d5fa3e17d46e17793494152937e46e92c9f748 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Sat, 22 Jun 2024 15:42:00 +0200 Subject: [PATCH] Add tests for ChildrenRequiredPropertyValidationRule --- .../tests/integration/validation.test.ts | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts index 8ff41c5..7cba2cd 100644 --- a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts +++ b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts @@ -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"; @@ -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); + }); + }); }); });