test: Add unit testing (get-latest-version) (#132)

This commit is contained in:
Shohei Ueda
2020-01-18 11:11:17 +09:00
committed by GitHub
parent 386980e22b
commit 442aa4dbd4
5 changed files with 80 additions and 21 deletions

View File

@@ -17,18 +17,14 @@ export async function getLatestVersion(
repo: string,
api: string
): Promise<string> {
try {
const url = getURL(org, repo, api);
const response = await fetch(url);
const json = await response.json();
let latestVersion = '';
if (api === 'brew') {
latestVersion = json.versions.stable;
} else if (api === 'github') {
latestVersion = json.tag_name;
}
return latestVersion;
} catch (e) {
return e;
const url = getURL(org, repo, api);
const response = await fetch(url);
const json = await response.json();
let latestVersion = '';
if (api === 'brew') {
latestVersion = json.versions.stable;
} else if (api === 'github') {
latestVersion = json.tag_name;
}
return latestVersion;
}