Skip to content

Commit d5c453c

Browse files
mock API request in test
1 parent 6575405 commit d5c453c

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

lib/config-utils.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ function mockGetContents(content: GetContentsResponse): sinon.SinonStub<any, any
3636
return spyGetContents;
3737
}
3838

39+
function mockListLanguages(languages: string[]) {
40+
// Passing an auth token is required, so we just use a dummy value
41+
let client = new github.GitHub('123');
42+
const response = {
43+
data: {},
44+
};
45+
for (const language of languages) {
46+
response.data[language] = 123;
47+
}
48+
sinon.stub(client.repos, "listLanguages").resolves(response as any);
49+
sinon.stub(api, "getApiClient").value(() => client);
50+
}
51+
3952
test("load empty config", async t => {
4053
return await util.withTmpDir(async tmpDir => {
4154
process.env['RUNNER_TEMP'] = tmpDir;
@@ -348,6 +361,8 @@ test("No detected languages", async t => {
348361
process.env['RUNNER_TEMP'] = tmpDir;
349362
process.env['GITHUB_WORKSPACE'] = tmpDir;
350363

364+
mockListLanguages([]);
365+
351366
try {
352367
await configUtils.initConfig();
353368
throw new Error('initConfig did not throw error');

src/config-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,10 @@ async function getLanguagesInRepo(): Promise<Language[]> {
442442
let repo = repo_nwo[1];
443443

444444
core.debug(`GitHub repo ${owner} ${repo}`);
445-
const response = await api.getApiClient(true).request("GET /repos/:owner/:repo/languages", ({
445+
const response = await api.getApiClient(true).repos.listLanguages({
446446
owner,
447447
repo
448-
}));
448+
});
449449

450450
core.debug("Languages API response: " + JSON.stringify(response));
451451

0 commit comments

Comments
 (0)