1
0
Fork 0

Start writing tests

pull/1486/head
Bethany 2023-08-04 13:00:58 -07:00
parent 8a5343d54a
commit 4c6d88f93a
3 changed files with 37 additions and 3 deletions

View File

@ -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()
})
})

View File

@ -1,7 +1,7 @@
import { HttpClient, HttpClientResponse, HttpCodes } from "@actions/http-client" import { HttpClient, HttpClientResponse, HttpCodes } from "@actions/http-client"
import { BearerCredentialHandler } from "@actions/http-client/lib/auth" import { BearerCredentialHandler } from "@actions/http-client/lib/auth"
import { info } from "@actions/core" import { info } from "@actions/core"
import { ArtifactServiceClientJSON } from "src/generated" import { ArtifactServiceClientJSON } from "../../generated"
import { getResultsServiceUrl, getRuntimeToken } from "./config" import { getResultsServiceUrl, getRuntimeToken } from "./config"
// The twirp http client must implement this interface // The twirp http client must implement this interface

View File

@ -4,7 +4,7 @@
"module": "commonjs", "module": "commonjs",
"strict": true, "strict": true,
"declaration": true, "declaration": true,
"target": "es6", "target": "es2020",
"sourceMap": true, "sourceMap": true,
"noImplicitAny": false, "noImplicitAny": false,
"baseUrl": "./", "baseUrl": "./",
@ -22,4 +22,4 @@
"**/*.test.ts", "**/*.test.ts",
"**/__mocks__/*" "**/__mocks__/*"
] ]
} }