mock API request in test
This commit is contained in:
parent
657540584e
commit
d5c453c995
6 changed files with 34 additions and 6 deletions
|
|
@ -36,6 +36,19 @@ function mockGetContents(content: GetContentsResponse): sinon.SinonStub<any, any
|
|||
return spyGetContents;
|
||||
}
|
||||
|
||||
function mockListLanguages(languages: string[]) {
|
||||
// Passing an auth token is required, so we just use a dummy value
|
||||
let client = new github.GitHub('123');
|
||||
const response = {
|
||||
data: {},
|
||||
};
|
||||
for (const language of languages) {
|
||||
response.data[language] = 123;
|
||||
}
|
||||
sinon.stub(client.repos, "listLanguages").resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
}
|
||||
|
||||
test("load empty config", async t => {
|
||||
return await util.withTmpDir(async tmpDir => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
|
|
@ -348,6 +361,8 @@ test("No detected languages", async t => {
|
|||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
|
||||
mockListLanguages([]);
|
||||
|
||||
try {
|
||||
await configUtils.initConfig();
|
||||
throw new Error('initConfig did not throw error');
|
||||
|
|
|
|||
|
|
@ -442,10 +442,10 @@ async function getLanguagesInRepo(): Promise<Language[]> {
|
|||
let repo = repo_nwo[1];
|
||||
|
||||
core.debug(`GitHub repo ${owner} ${repo}`);
|
||||
const response = await api.getApiClient(true).request("GET /repos/:owner/:repo/languages", ({
|
||||
const response = await api.getApiClient(true).repos.listLanguages({
|
||||
owner,
|
||||
repo
|
||||
}));
|
||||
});
|
||||
|
||||
core.debug("Languages API response: " + JSON.stringify(response));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue