From 66c066616b37c80e0b087e1da472cb3157fa2691 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 10 Mar 2026 02:14:44 +0100 Subject: [PATCH] Add test for Controller.factorioVersions failure Check that errors from fetchFactorioVersions is correctly handled in the fetch method provided by the Controller class. --- test/controller/Controller.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/controller/Controller.js b/test/controller/Controller.js index ae45a11b..7b0d4127 100644 --- a/test/controller/Controller.js +++ b/test/controller/Controller.js @@ -252,6 +252,28 @@ describe("controller/src/Controller", function() { assert.equal(controller.config.restartRequired, true); }); }); + + describe(".factorioVersions", function() { + const _fetch = global.fetch; + const fetchCalls = []; + before(function() { + global.fetch = async (url) => { + fetchCalls.push(url); + return { ok: false, status: 503, statusText: "Service Unavailable" }; + }; + }); + it("should handle fetch failure", async function() { + await assert.deepEqual( + await controller.factorioVersions.get(0), + [], + ); + assert(fetchCalls.length === 1, "expected one fetch call"); + assert(fetchCalls[0].indexOf("/download") !== -1, "fetch call to be to a URL with /download in it"); + }); + after(function() { + global.fetch = _fetch; + }); + }); }); describe("finalise", function() { describe(".finaliseHosts()", function() {