|
|
|
@@ -17,6 +17,8 @@ const path = require("node:path");
|
|
|
|
|
|
|
|
|
|
|
|
const read = (...parts) => fs.readFileSync(path.join(__dirname, "..", ...parts), "utf8");
|
|
|
|
const read = (...parts) => fs.readFileSync(path.join(__dirname, "..", ...parts), "utf8");
|
|
|
|
const iconService = require(path.join(__dirname, "..", "backend", "src", "services", "foundry-icons"));
|
|
|
|
const iconService = require(path.join(__dirname, "..", "backend", "src", "services", "foundry-icons"));
|
|
|
|
|
|
|
|
const foundryService = require(path.join(__dirname, "..", "backend", "src", "services", "foundry"));
|
|
|
|
|
|
|
|
const http = require("node:http");
|
|
|
|
|
|
|
|
|
|
|
|
const windowDefsSource = read("frontend", "app", "services", "WindowDefinitions.js");
|
|
|
|
const windowDefsSource = read("frontend", "app", "services", "WindowDefinitions.js");
|
|
|
|
const itemWindowSource = read("frontend", "app", "components", "windows", "ItemSheetWindow.vue");
|
|
|
|
const itemWindowSource = read("frontend", "app", "components", "windows", "ItemSheetWindow.vue");
|
|
|
|
@@ -145,6 +147,73 @@ test("the icon browser browses the world's icons folder by folder", () => {
|
|
|
|
assert.match(foundryIconsSource, /ClearWindow\(\{ type: ['"]item_icon_source['"] \}\)/);
|
|
|
|
assert.match(foundryIconsSource, /ClearWindow\(\{ type: ['"]item_icon_source['"] \}\)/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- The bridge the backend reads the icon library through (issue #74) --------
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// The icon window reaches the world's `icons/` folder through the backend, which
|
|
|
|
|
|
|
|
// in turn reads the bridge that the world already pushes its snapshot to. When
|
|
|
|
|
|
|
|
// that push works the campaign reads as connected, so a read that still reports
|
|
|
|
|
|
|
|
// the bridge as unset is the bug this guards against.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the bridge environment for one call and put it back exactly as it was.
|
|
|
|
|
|
|
|
function withBridgeEnv(env, run) {
|
|
|
|
|
|
|
|
const keys = ["FOUNDRY_API_URL", "FOUNDRY_API_CLIENT_URL", "FOUNDRY_API_TOKEN"];
|
|
|
|
|
|
|
|
const saved = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
|
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
|
|
|
if (env[key] === undefined) delete process.env[key];
|
|
|
|
|
|
|
|
else process.env[key] = env[key];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
|
|
|
.then(run)
|
|
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
|
|
for (const key of keys) {
|
|
|
|
|
|
|
|
if (saved[key] === undefined) delete process.env[key];
|
|
|
|
|
|
|
|
else process.env[key] = saved[key];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test("a connected world answers icon reads through the bridge set under the client URL", async () => {
|
|
|
|
|
|
|
|
// A world that connects and syncs is often configured with FOUNDRY_API_CLIENT_URL
|
|
|
|
|
|
|
|
// alone — the address its own client reaches. The backend read falls back to it,
|
|
|
|
|
|
|
|
// so the icon window is not told its bridge is unset while the world is right there.
|
|
|
|
|
|
|
|
const answers = [];
|
|
|
|
|
|
|
|
const bridge = http.createServer((request, response) => {
|
|
|
|
|
|
|
|
answers.push(request.url);
|
|
|
|
|
|
|
|
response.writeHead(200, { "Content-Type": "application/json" });
|
|
|
|
|
|
|
|
response.end(JSON.stringify({ status: "ok", dir: "icons", directories: ["icons/svg"], files: [], offset: 0, next: null }));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await new Promise((resolve) => bridge.listen(0, "127.0.0.1", resolve));
|
|
|
|
|
|
|
|
const clientUrl = `http://127.0.0.1:${bridge.address().port}/`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const result = await withBridgeEnv(
|
|
|
|
|
|
|
|
{ FOUNDRY_API_URL: undefined, FOUNDRY_API_CLIENT_URL: clientUrl, FOUNDRY_API_TOKEN: "read-token" },
|
|
|
|
|
|
|
|
() => foundryService.requestFoundry("api/icons?dir=icons&offset=0&limit=120"),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(result.status, 200);
|
|
|
|
|
|
|
|
assert.equal(result.data.status, "ok");
|
|
|
|
|
|
|
|
assert.equal(answers.length, 1);
|
|
|
|
|
|
|
|
assert.match(answers[0], /^\/api\/icons\?/);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
await new Promise((resolve) => bridge.close(resolve));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test("without a bridge under either name a read says it is not configured", async () => {
|
|
|
|
|
|
|
|
const error = await withBridgeEnv(
|
|
|
|
|
|
|
|
{ FOUNDRY_API_URL: undefined, FOUNDRY_API_CLIENT_URL: undefined, FOUNDRY_API_TOKEN: undefined },
|
|
|
|
|
|
|
|
() => foundryService.requestFoundry("api/icons?dir=icons").then(() => null, (err) => err),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(error?.code, "FOUNDRY_NOT_CONFIGURED");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test("the icon window says what actually failed instead of always blaming the bridge", () => {
|
|
|
|
|
|
|
|
// axios rejects a non-2xx answer, so the catch reads the route's own i18n key
|
|
|
|
|
|
|
|
// off the response: a campaign with no world address is told as much rather
|
|
|
|
|
|
|
|
// than as a bridge that is not set up.
|
|
|
|
|
|
|
|
assert.match(foundryIconsSource, /requestError\.response\?\.data\?\.msg/);
|
|
|
|
|
|
|
|
assert.match(foundryIconsSource, /requestError\.response\?\.data\?\.msg \|\| ['"]foundry\.errors\.icons-unavailable['"]/);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// --- Strings -----------------------------------------------------------------------
|
|
|
|
// --- Strings -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
test("every locale names the icon windows and their controls", () => {
|
|
|
|
test("every locale names the icon windows and their controls", () => {
|
|
|
|
|