Skip to content

Commit

Permalink
mock API request in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Aug 7, 2020
1 parent 6575405 commit d5c453c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit d5c453c

Please sign in to comment.