37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
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")));
|
|
});
|