mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
Test that uploads merge with the uploading instance's components
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c798b2a33f
commit
8487c6d923
1 file changed
+38
-1
@@ -6,7 +6,7 @@ import * as lib from "@clusterio/lib";
|
||||
import * as mock from "../../../test/mock.js";
|
||||
import controllerEntrypoint from "../dist/node/controller.js";
|
||||
import { plugin as info } from "../dist/node/index.js";
|
||||
import { DatabaseStatsRequest } from "../dist/node/messages.js";
|
||||
import { DatabaseStatsRequest, DownloadRequest, UploadRequest } from "../dist/node/messages.js";
|
||||
|
||||
describe("player_sync controller", function() {
|
||||
const databaseDir = path.join("temp", "test", "player_sync");
|
||||
@@ -50,4 +50,41 @@ describe("player_sync controller", function() {
|
||||
assert.equal(stats.databaseEntries, 1);
|
||||
assert.equal(stats.largestEntry.name, "new");
|
||||
});
|
||||
|
||||
describe("UploadRequest", function() {
|
||||
let controller;
|
||||
let disabled;
|
||||
beforeEach(async function() {
|
||||
disabled = [];
|
||||
const stored = { generation: 1, name: "test", force: "player", tag: "stored" };
|
||||
await fs.writeFile(path.join(databaseDir, "player_sync.json"), JSON.stringify([["test", stored]]));
|
||||
controller = await load();
|
||||
controller.instances = new Map([[1, {
|
||||
config: {
|
||||
get: name => {
|
||||
if (name === "instance.name") { return "test instance"; }
|
||||
return !disabled.includes(name.replace("player_sync.sync_", ""));
|
||||
},
|
||||
},
|
||||
}]]);
|
||||
});
|
||||
|
||||
async function upload(playerData) {
|
||||
await mock.getHandler(controller, UploadRequest)({ instanceId: 1, playerName: "test", playerData });
|
||||
return (await mock.getHandler(controller, DownloadRequest)({ instanceId: 1, playerName: "test" }))
|
||||
.playerData;
|
||||
}
|
||||
|
||||
it("should store the upload as is when everything is synced", async function() {
|
||||
const playerData = { generation: 2, name: "test", force: "enemy", tag: "uploaded" };
|
||||
assert.deepEqual(await upload(playerData), playerData);
|
||||
});
|
||||
it("should keep stored fields the uploading instance does not sync", async function() {
|
||||
disabled = ["force"];
|
||||
assert.deepEqual(
|
||||
await upload({ generation: 2, name: "test", tag: "uploaded" }),
|
||||
{ generation: 2, name: "test", force: "player", tag: "uploaded" },
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user