Remove unneeded apiDetails input to getApiClient
This commit is contained in:
parent
dac8912e9f
commit
9df773d1a3
45 changed files with 128 additions and 180 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import * as githubUtils from "@actions/github/lib/utils";
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import test from "ava";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import { getApiClient, GitHubApiCombinedDetails } from "./api-client";
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import { getApiClient } from "./api-client";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment } from "./util";
|
||||
import * as util from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
const pkg = require("../package.json");
|
||||
|
|
@ -18,36 +19,27 @@ test.beforeEach(() => {
|
|||
pluginStub = sinon.stub(githubUtils.GitHub, "plugin");
|
||||
githubStub = sinon.stub();
|
||||
pluginStub.returns(githubStub);
|
||||
initializeEnvironment(pkg.version);
|
||||
util.initializeEnvironment(pkg.version);
|
||||
});
|
||||
|
||||
test("Get the API with an API URL directly", async (t) => {
|
||||
doTest(
|
||||
t,
|
||||
{
|
||||
auth: "xyz",
|
||||
url: "http://github.localhost",
|
||||
apiURL: "http://api.github.localhost",
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
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}`,
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
function doTest(
|
||||
t: ExecutionContext<unknown>,
|
||||
clientArgs: GitHubApiCombinedDetails,
|
||||
clientOptions: any,
|
||||
expected: any
|
||||
) {
|
||||
getApiClient(clientArgs, clientOptions);
|
||||
|
||||
const firstCallArgs = githubStub.args[0];
|
||||
// log is a function, so we don't need to test for equality of it
|
||||
delete firstCallArgs[0].log;
|
||||
t.deepEqual(firstCallArgs, [expected]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue