From 4c6d88f93a6f017e3ec86d51aebc8250f72ff075 Mon Sep 17 00:00:00 2001 From: Bethany Date: Fri, 4 Aug 2023 13:00:58 -0700 Subject: [PATCH] Start writing tests --- .../__tests__/artifact-http-client.test.ts | 34 +++++++++++++++++++ .../internal/shared/artifact-twirp-client.ts | 2 +- tsconfig.json | 4 +-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 packages/artifact/__tests__/artifact-http-client.test.ts diff --git a/packages/artifact/__tests__/artifact-http-client.test.ts b/packages/artifact/__tests__/artifact-http-client.test.ts new file mode 100644 index 00000000..3ab79116 --- /dev/null +++ b/packages/artifact/__tests__/artifact-http-client.test.ts @@ -0,0 +1,34 @@ +import * as config from "../src/internal/shared/config" +import { createArtifactTwirpClient } from "../src/internal/shared/artifact-twirp-client" +import * as core from "@actions/core" + +jest.mock("@actions/http-client") + +describe("artifact-http-client", () => { + beforeAll(() => { + // mock all output so that there is less noise when running tests + jest.spyOn(console, "log").mockImplementation(() => {}) + jest.spyOn(core, "debug").mockImplementation(() => {}) + jest.spyOn(core, "info").mockImplementation(() => {}) + jest.spyOn(core, "warning").mockImplementation(() => {}) + }) + + it("should successfully create a client", () => { + jest.spyOn(config, "getResultsServiceUrl").mockReturnValue("http://localhost:8080") + jest.spyOn(config, "getRuntimeToken").mockReturnValue("token") + const client = createArtifactTwirpClient("upload") + expect(client).toBeDefined() + }) + + it("should make a request", async () => { + const client = createArtifactTwirpClient("upload") + const artifact = client.CreateArtifact( + { + workflowRunBackendId: "1234", + workflowJobRunBackendId: "5678", + name: "artifact", + version: 4} + ) + expect(artifact).toBeDefined() + }) +}) diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index 02ac36c3..6e9345ea 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -1,7 +1,7 @@ import { HttpClient, HttpClientResponse, HttpCodes } from "@actions/http-client" import { BearerCredentialHandler } from "@actions/http-client/lib/auth" import { info } from "@actions/core" -import { ArtifactServiceClientJSON } from "src/generated" +import { ArtifactServiceClientJSON } from "../../generated" import { getResultsServiceUrl, getRuntimeToken } from "./config" // The twirp http client must implement this interface diff --git a/tsconfig.json b/tsconfig.json index fb610c6e..f706470a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "module": "commonjs", "strict": true, "declaration": true, - "target": "es6", + "target": "es2020", "sourceMap": true, "noImplicitAny": false, "baseUrl": "./", @@ -22,4 +22,4 @@ "**/*.test.ts", "**/__mocks__/*" ] -} \ No newline at end of file +}