Add test for Controller.factorioVersions failure

Check that errors from fetchFactorioVersions is correctly handled in the
fetch method provided by the Controller class.
This commit is contained in:
Hornwitser committed 2026-03-10 02:14:44 +01:00
1 parent 30f552847a
commit 66c066616b
1 file changed
+22
+22
View File
@@ -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() {