-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathapi-client.test.ts
More file actions
45 lines (37 loc) · 1.24 KB
/
api-client.test.ts
File metadata and controls
45 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as githubUtils from "@actions/github/lib/utils";
import test from "ava";
import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import { getApiClient } from "./api-client";
import { setupTests } from "./testing-utils";
import * as util from "./util";
// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");
setupTests(test);
let pluginStub: sinon.SinonStub;
let githubStub: sinon.SinonStub;
test.beforeEach(() => {
pluginStub = sinon.stub(githubUtils.GitHub, "plugin");
githubStub = sinon.stub();
pluginStub.returns(githubStub);
util.initializeEnvironment(pkg.version);
});
test("getApiClient", async (t) => {
sinon.stub(actionsUtil, "getRequiredInput").withArgs("token").returns("xyz");
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
requiredEnvParamStub
.withArgs("GITHUB_SERVER_URL")
.returns("http://github.localhost");
requiredEnvParamStub
.withArgs("GITHUB_API_URL")
.returns("http://api.github.localhost");
getApiClient();
t.assert(
githubStub.calledOnceWithExactly({
auth: "token xyz",
baseUrl: "http://api.github.localhost",
log: sinon.match.any,
userAgent: `CodeQL-Action/${pkg.version}`,
})
);
});