From 6daaef2e0ae76043123a459a41d097b0ab6389b3 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Tue, 15 May 2018 17:19:49 +0200 Subject: [PATCH] add missing asset names to 404 output. #45 --- index.js | 6 +++++- test/index.js | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 6d32f27d..4d4b7810 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,11 @@ class Updates { const latest = await this.cachedGetLatest(account, repository, platform) if (!latest) { - notFound(res) + const message = + platform === 'darwin' + ? 'No updates found (needs asset matching *{mac,darwin,osx}*.zip)' + : 'No updates found (needs asset containing win32-x64 or .exe)' + notFound(res, message) } else if (semver.eq(latest.version, version)) { log.info({ account, repository, platform, version }, 'up to date') noContent(res) diff --git a/test/index.js b/test/index.js index 87cf1327..5b48d546 100644 --- a/test/index.js +++ b/test/index.js @@ -207,17 +207,29 @@ test('Updates', async t => { await t.test('Platforms', async t => { await t.test('Darwin', async t => { - for (let i = 0; i < 2; i++) { - let res = await fetch(`${address}/owner/repo/darwin/0.0.0`) - t.equal(res.status, 200) - let body = await res.json() - t.equal(body.url, 'mac.zip') + await t.test('.zip', async t => { + for (let i = 0; i < 2; i++) { + let res = await fetch(`${address}/owner/repo/darwin/0.0.0`) + t.equal(res.status, 200) + let body = await res.json() + t.equal(body.url, 'mac.zip') - res = await fetch(`${address}/owner/repo-darwin/darwin/0.0.0`) - t.equal(res.status, 200) - body = await res.json() - t.match(body.url, 'darwin.zip') - } + res = await fetch(`${address}/owner/repo-darwin/darwin/0.0.0`) + t.equal(res.status, 200) + body = await res.json() + t.match(body.url, 'darwin.zip') + } + }) + + await t.test('missing asset', async t => { + const res = await fetch(`${address}/owner/repo-win32-zip/darwin/0.0.0`) + t.equal(res.status, 404) + const body = await res.text() + t.equal( + body, + 'No updates found (needs asset matching *{mac,darwin,osx}*.zip)' + ) + }) }) await t.test('Win32', async t => { @@ -261,6 +273,16 @@ test('Updates', async t => { t.equal(res.status, 404) } }) + + await t.test('missing asset', async t => { + const res = await fetch(`${address}/owner/repo-darwin/win32/0.0.0`) + t.equal(res.status, 404) + const body = await res.text() + t.equal( + body, + 'No updates found (needs asset containing win32-x64 or .exe)' + ) + }) }) await t.test('Linux', async t => {