From 85d37194eac77c8b1391cf2ab449c65fd1b41626 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Sat, 22 Jun 2024 11:19:24 +0200 Subject: [PATCH] Adapt and add more validation tests --- .../tests/integration/validation.test.ts | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) 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 5fca011..8ff41c5 100644 --- a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts +++ b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts @@ -64,22 +64,51 @@ class: GalaxyWorkflow expect(diagnostics[2].message).toBe("The 'outputs' field is required."); }); - it("should report error for invalid enum value", async () => { + it("should report error for invalid input type value", async () => { const content = ` class: GalaxyWorkflow inputs: the_input: - type: unknown + type: 5 outputs: steps: `; const diagnostics = await validateDocument(content); expect(diagnostics).toHaveLength(1); expect(diagnostics[0].message).toBe( - "The value is not a valid 'GalaxyType'. Allowed values are: integer, text, File, data, collection, null, boolean, int, long, float, double, string." + "Type mismatch for field 'type'. Expected 'GalaxyType | string' but found 'number'." ); }); + it("should report error for invalid enum value", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + type: unknown + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(1); + expect(diagnostics[0].message).toBe( + "The value is not a valid 'WorkflowStepType'. Allowed values are: tool, subworkflow, pause." + ); + }); + + it("should not report error for valid enum value", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + type: tool + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(0); + }); + it("should not report error for compatible primitive types", async () => { const content = ` class: GalaxyWorkflow @@ -108,7 +137,9 @@ steps: `; const diagnostics = await validateDocument(content); expect(diagnostics).toHaveLength(1); - expect(diagnostics[0].message).toContain("Type mismatch for field 'top'. Expected 'float' but found 'string'."); + expect(diagnostics[0].message).toContain( + "Type mismatch for field 'top'. Expected 'float | int' but found 'string'." + ); }); it("should not report error for properties with Any type", async () => { @@ -126,6 +157,35 @@ steps: expect(diagnostics).toHaveLength(0); }); + it("should not report error when multiple types are allowed (string)", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + out: a string + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(0); + }); + + it("should not report error when multiple types are allowed (object)", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + out: + add_tags: + - tag1 + - tag2 + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(0); + }); + describe("Custom Rules", () => { let rule: ValidationRule;