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 +}