From e669e89315c3658b5bb60d92b31f34bbd9537f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 27 Jul 2018 15:47:15 -0700 Subject: [PATCH] RepositorySelect displays NO_REPOS on 404 (#547) Test plan: Unit tests included, plus I manually tested it. --- src/app/credExplorer/RepositorySelect.js | 3 +++ src/app/credExplorer/RepositorySelect.test.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/app/credExplorer/RepositorySelect.js b/src/app/credExplorer/RepositorySelect.js index 60fc3e4..1f1ed92 100644 --- a/src/app/credExplorer/RepositorySelect.js +++ b/src/app/credExplorer/RepositorySelect.js @@ -89,6 +89,9 @@ function repoStringToRepo(x: string): Repo { export async function loadStatus(localStore: LocalStore): Promise { try { const response = await fetch(REPO_REGISTRY_API); + if (response.status === 404) { + return {type: "NO_REPOS"}; + } if (!response.ok) { console.error(response); return {type: "FAILURE"}; diff --git a/src/app/credExplorer/RepositorySelect.test.js b/src/app/credExplorer/RepositorySelect.test.js index 3bc1b75..ccc8e06 100644 --- a/src/app/credExplorer/RepositorySelect.test.js +++ b/src/app/credExplorer/RepositorySelect.test.js @@ -167,6 +167,13 @@ describe("app/credExplorer/RepositorySelect", () => { console.error = jest.fn(); }); }); + it("returns NO_REPOS on fetch 404", () => { + fetch.mockResponseOnce("irrelevant", {status: 404}); + expect.assertions(3); + return loadStatus(testLocalStore()).then((status) => { + expect(status).toEqual({type: "NO_REPOS"}); + }); + }); it("loads selectedRepo from localStore, if available", () => { const repos = [ {owner: "a", name: "b"},