@fedify/fedify
Version:
An ActivityPub server framework
121 lines (117 loc) • 4.34 kB
JavaScript
import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { assertEquals } from "../assert_equals-CTYbeopb.js";
import "../assert-DmFG7ppO.js";
import { assertInstanceOf } from "../assert_instance_of-CF09JHYM.js";
import "../docloader-C8mmLN-Y.js";
import "../url-kTAI6_KP.js";
import "../multibase-DeCHcK8L.js";
import { Collection, Note, Object as Object$1, Person } from "../vocab-dDpPQ0fF.js";
import "../langstr-DbWheeIS.js";
import "../lookup-Ozuw-rxN.js";
import "../type-D2s5lmbZ.js";
import { lookupObject, traverseCollection } from "../lookup-DNXR408t.js";
import { test } from "../testing-BZ0dJ4qn.js";
import "../std__assert-vp0TKMS1.js";
import "../assert_rejects-C-sxEMM5.js";
import "../assert_is_error-nrwA1GeT.js";
import "../assert_not_equals-Dc7y-V5Q.js";
import "../assert_throws-Cn9C6Jur.js";
import { mockDocumentLoader } from "../docloader-09nVWLAZ.js";
import { esm_default } from "../esm-Db4De7AS.js";
//#region vocab/lookup.test.ts
test("lookupObject()", async (t) => {
esm_default.spyGlobal();
esm_default.get("begin:https://example.com/.well-known/webfinger", {
subject: "acct:johndoe@example.com",
links: [
{
rel: "alternate",
href: "https://example.com/object",
type: "application/activity+json"
},
{
rel: "self",
href: "https://example.com/html/person",
type: "text/html"
},
{
rel: "self",
href: "https://example.com/person",
type: "application/activity+json"
}
]
});
const options = {
documentLoader: mockDocumentLoader,
contextLoader: mockDocumentLoader
};
await t.step("actor", async () => {
const person = await lookupObject("@johndoe@example.com", options);
assertInstanceOf(person, Person);
assertEquals(person.id, new URL("https://example.com/person"));
assertEquals(person.name, "John Doe");
const person2 = await lookupObject("johndoe@example.com", options);
assertEquals(person2, person);
const person3 = await lookupObject("acct:johndoe@example.com", options);
assertEquals(person3, person);
});
await t.step("object", async () => {
const object = await lookupObject("https://example.com/object", options);
assertInstanceOf(object, Object$1);
assertEquals(object, new Object$1({
id: new URL("https://example.com/object"),
name: "Fetched object"
}));
const person = await lookupObject("https://example.com/hong-gildong", options);
assertInstanceOf(person, Person);
assertEquals(person, new Person({
id: new URL("https://example.com/hong-gildong"),
name: "Hong Gildong"
}));
});
esm_default.removeRoutes();
esm_default.get("begin:https://example.com/.well-known/webfinger", {
subject: "acct:janedoe@example.com",
links: [{
rel: "self",
href: "https://example.com/404",
type: "application/activity+json"
}]
});
await t.step("not found", async () => {
assertEquals(await lookupObject("janedoe@example.com", options), null);
assertEquals(await lookupObject("https://example.com/404", options), null);
});
esm_default.hardReset();
});
test("traverseCollection()", async () => {
const options = {
documentLoader: mockDocumentLoader,
contextLoader: mockDocumentLoader
};
const collection = await lookupObject("https://example.com/collection", options);
assertInstanceOf(collection, Collection);
assertEquals(await Array.fromAsync(traverseCollection(collection, options)), [
new Note({ content: "This is a simple note" }),
new Note({ content: "This is another simple note" }),
new Note({ content: "This is a third simple note" })
]);
const pagedCollection = await lookupObject("https://example.com/paged-collection", options);
assertInstanceOf(pagedCollection, Collection);
assertEquals(await Array.fromAsync(traverseCollection(pagedCollection, options)), [
new Note({ content: "This is a simple note" }),
new Note({ content: "This is another simple note" }),
new Note({ content: "This is a third simple note" })
]);
assertEquals(await Array.fromAsync(traverseCollection(pagedCollection, {
...options,
interval: { milliseconds: 250 }
})), [
new Note({ content: "This is a simple note" }),
new Note({ content: "This is another simple note" }),
new Note({ content: "This is a third simple note" })
]);
});
//#endregion