diff --git a/test/lib/external/FactorioVersions.test.js b/test/lib/external/FactorioVersions.test.js index 30e4f3ae..32b86dad 100644 --- a/test/lib/external/FactorioVersions.test.js +++ b/test/lib/external/FactorioVersions.test.js @@ -51,8 +51,16 @@ describe("FactorioVersions", function() { const versions = await fetchFactorioVersions(); assert.deepEqual(versions, [ - { stable: false, version: "2.0.73", downloadUrl: "https://factorio.com/download/archive/2.0.73" }, - { stable: true, version: "2.0.72", downloadUrl: "https://factorio.com/download/archive/2.0.72" }, + { + stable: false, + version: "2.0.73", + headlessUrl: "www.factorio.com/get-download/2.0.73/headless/linux64", + }, + { + stable: true, + version: "2.0.72", + headlessUrl: "www.factorio.com/get-download/2.0.72/headless/linux64", + }, ]); }); it("deduplicates versions by last occurrence", async function() { @@ -79,7 +87,11 @@ describe("FactorioVersions", function() { const versions = await fetchFactorioVersions(); assert.deepEqual(versions, [ - { stable: true, version: "2.0.73", downloadUrl: "https://factorio.com/download/archive/2.0.73" }, + { + stable: true, + version: "2.0.73", + headlessUrl: "www.factorio.com/get-download/2.0.73/headless/linux64", + }, ]); }); it("thorws on HTTP error status", async function() { @@ -105,18 +117,18 @@ describe("FactorioVersions", function() { mockFetch(await readFile("test/file/html/factorio-download-archive.html")); const versions = await fetchFactorioVersions(); - assert.equal(versions.length, 111); - assert.equal(versions.filter(v => v.stable).length, 53); - assert.equal(versions.filter(v => !v.stable).length, 58); + assert.equal(versions.length, 105); + assert.equal(versions.filter(v => v.stable).length, 48); + assert.equal(versions.filter(v => !v.stable).length, 57); }); it("parses versions from live api", async function() { slowTest(this); global.fetch = originalFetch; const versions = await fetchFactorioVersions(); - assert.ok(versions.length >= 111); - assert.ok(versions.filter(v => v.stable).length >= 53); - assert.ok(versions.filter(v => !v.stable).length >= 58); + assert.ok(versions.length >= 105); + assert.ok(versions.filter(v => v.stable).length >= 48); + assert.ok(versions.filter(v => !v.stable).length >= 57); }); }); }); diff --git a/test/messages/controller.test.js b/test/messages/controller.test.js index 1e345475..7b735e9b 100644 --- a/test/messages/controller.test.js +++ b/test/messages/controller.test.js @@ -34,4 +34,44 @@ describe("messages/controller", function() { ); }); }); + + describe("External", function() { + it("runs", async function() { + let callCount = 0; + const versions = [ + { version: "1.2.3", stable: true, headlessUrl: "path/to/download" }, + { version: "1.2.4", stable: false, headlessUrl: "path/to/download" }, + ]; + + // Mock the cache to avoid needless fetches + controller.factorioVersions = new lib.ValueCache(async () => { + callCount += 1; + return versions; + }); + + // First call should result in a fetch + const versions1 = await controlConnection.handleFactorioVersionsRequest( + new lib.FactorioVersionsRequest() + ); + + assert.deepEqual(versions1, versions); + assert.equal(callCount, 1); + + // Second call should not fetch due to default maxAgeMs being greater than 0 + const versions2 = await controlConnection.handleFactorioVersionsRequest( + new lib.FactorioVersionsRequest() + ); + + assert.deepEqual(versions2, versions); + assert.equal(callCount, 1); + + // Setting maxAgeMs to 0 should result in a new fetch + const versions3 = await controlConnection.handleFactorioVersionsRequest( + new lib.FactorioVersionsRequest(0) + ); + + assert.deepEqual(versions3, versions); + assert.equal(callCount, 2); + }); + }); });