jdkjskdj
Some checks failed
Build and Deploy Nuxt / build (push) Successful in 1m10s
Test / test (push) Failing after 2s

This commit is contained in:
2026-10-19 19:42:10 +02:00
parent 1c98af69b2
commit b83f64ff9e
14 changed files with 299 additions and 9 deletions

View File

@@ -6,6 +6,58 @@ const { test } = require("node:test");
const assert = require("node:assert/strict");
const serviceLinks = require("../backend/src/services/service-links");
const ServiceLinkRequest = require("../backend/src/models/ServiceLinkRequest");
test("a link found by its code can be answered and saved", async () => {
const original = ServiceLinkRequest.findOne;
const document = { _id: "link-1", state: "pending", save: async () => {} };
const query = {
select: () => query,
lean: () => Promise.resolve({ _id: "link-1", state: "pending" }),
then: (resolve, reject) => Promise.resolve(document).then(resolve, reject),
};
ServiceLinkRequest.findOne = () => query;
try {
const request = await serviceLinks.findServiceLinkByCode("code-1");
assert.equal(typeof request?.save, "function",
"the complete route saves the answered link, so it cannot be a plain lean object");
} finally {
ServiceLinkRequest.findOne = original;
}
});
test("unlinking a Foundry world forgets it and revokes its link", async () => {
const original = ServiceLinkRequest.updateMany;
const revocations = [];
ServiceLinkRequest.updateMany = async (filter, update) => {
revocations.push({ filter, update });
return { matchedCount: 1 };
};
try {
const campaign = {
_id: "campaign-1",
foundryWorldId: "world-1",
foundryWorldTitle: "Test World",
foundrySystem: "dnd5e",
foundrySyncTokenHash: "hash",
set(key, value) { this[key] = value; },
async save() { campaign.saved = true; },
};
await serviceLinks.unlinkFoundryWorld(campaign);
assert.equal(campaign.saved, true);
assert.equal(campaign.foundryWorldId, undefined);
assert.equal(campaign.foundryWorldTitle, undefined);
assert.equal(campaign.foundrySystem, undefined);
assert.equal(campaign.foundrySyncTokenHash, undefined);
assert.equal(revocations[0].filter.service, "foundry");
assert.equal(revocations[0].filter.campaign, "campaign-1");
assert.equal(revocations[0].update.$set.state, "revoked");
} finally {
ServiceLinkRequest.updateMany = original;
}
});
test("a link request keeps the service metadata short and plain", () => {
const target = serviceLinks.readTarget({