Add Nextcloud recipe display and controller

This commit is contained in:
2026-08-03 15:22:28 -05:00
parent 4ea34ec429
commit 464ae4159d
12 changed files with 1189 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const NextcloudPublicShare = require("../lib/nextcloud-public-share");
test("extracts a token and lists recipe JSON files", async () => {
const calls = [];
const fetchImpl = async (url, options = {}) => {
calls.push({ url: String(url), options });
if (options.method === "PROPFIND") {
return new Response(`<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:">
<d:response><d:href>/public.php/dav/files/share-token/Apple%20Pie/recipe.json</d:href></d:response>
</d:multistatus>`, { status: 207 });
}
return Response.json({ name: "Apple Pie", description: "A test recipe" });
};
const client = new NextcloudPublicShare({
shareUrl: "https://cloud.example.test/s/share-token",
fetchImpl
});
const recipes = await client.listRecipes();
assert.equal(recipes.length, 1);
assert.equal(recipes[0].name, "Apple Pie");
assert.equal(calls[0].options.headers.Authorization, undefined);
assert.equal(calls[0].options.headers.Depth, "infinity");
assert.equal(calls[0].options.headers["X-Requested-With"], "XMLHttpRequest");
});
test("rejects recipe identifiers that do not point to recipe.json", async () => {
const client = new NextcloudPublicShare({
shareUrl: "https://cloud.example.test/s/share-token",
fetchImpl: async () => Response.json({})
});
await assert.rejects(() => client.getRecipe(Buffer.from("/other.txt").toString("base64url")));
});