From 498acbb63f78400161b496287686de64f45b7a7c Mon Sep 17 00:00:00 2001
From: Kir_Antipov <kp.antipov@gmail.com>
Date: Tue, 9 Jan 2024 12:49:15 +0000
Subject: [PATCH] Added tests for `action-metadata`

---
 .../utils/actions/action-metadata.spec.ts     | 140 ++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 tests/unit/utils/actions/action-metadata.spec.ts

diff --git a/tests/unit/utils/actions/action-metadata.spec.ts b/tests/unit/utils/actions/action-metadata.spec.ts
new file mode 100644
index 0000000..e362d11
--- /dev/null
+++ b/tests/unit/utils/actions/action-metadata.spec.ts
@@ -0,0 +1,140 @@
+import mockFs from "mock-fs";
+import { parseActionMetadataFromFile, parseActionMetadataFromString } from "@/utils/actions/action-metadata";
+
+beforeEach(() => {
+    mockFs({
+        "action.yml": `
+            name: Test Action
+            description: This is a test action
+            inputs:
+              - name: input1
+                description: This is input1
+                type: string
+              - name: input2
+                description: This is input2
+                type: number
+        `,
+    });
+});
+
+afterEach(() => {
+    mockFs.restore();
+});
+
+describe("parseActionMetadataFromString", () => {
+    test("returns the parsed ActionMetadata object for valid YAML text", () => {
+        const actionYamlText = `
+            name: Test Action
+            description: This is a test action
+            inputs:
+              - name: input1
+                description: This is input1
+                type: string
+              - name: input2
+                description: This is input2
+                type: number
+        `;
+
+        const result = parseActionMetadataFromString(actionYamlText);
+
+        expect(result).toEqual({
+            name: "Test Action",
+            description: "This is a test action",
+            inputs: [
+                { name: "input1", description: "This is input1", type: "string" },
+                { name: "input2", description: "This is input2", type: "number" },
+            ],
+        });
+    });
+});
+
+describe("parseActionMetadataFromFile", () => {
+    test("reads the file and parses the content as ActionMetadata", async () => {
+        const result = await parseActionMetadataFromFile("action.yml");
+
+        expect(result).toEqual({
+            name: "Test Action",
+            description: "This is a test action",
+            inputs: [
+                { name: "input1", description: "This is input1", type: "string" },
+                { name: "input2", description: "This is input2", type: "number" },
+            ],
+        });
+    });
+
+    test("throws an error if the file doesn't exist", async () => {
+        await expect(parseActionMetadataFromFile("action.txt")).rejects.toThrowError();
+    });
+});
+
+describe("processActionMetadataTemplate", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("processActionMetadataTemplateString", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("processActionMetadataTemplateFile", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("createTypeScriptDefinitionForActionMetadata", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("createModuleLoaderTypeScriptDefinitionForActionMetadata", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("stripActionMetadataFromCustomFields", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("stripActionMetadataStringFromCustomFields", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});
+
+describe("stripActionMetadataFileFromCustomFields", () => {
+    test("assume that everything is fine, until it's not", () => {
+        // This method is only used for code generation during
+        // TypeScript-to-JavaScript transpilation. Thus, there's
+        // no need to expend effort testing code that would cause
+        // a compilation error if something was actually wrong.
+    });
+});