UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

63 lines (62 loc) 2.17 kB
import "@js-temporal/polyfill"; import "urlpattern-polyfill"; globalThis.addEventListener = () => {}; import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs"; import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs"; import { t as assert } from "../assert-DikXweDx.mjs"; import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs"; import { n as FederationImpl, v as actorDehydrator, y as autoIdAssigner } from "../middleware-D9k0Knum.mjs"; import { test } from "@fedify/fixture"; import { Follow, Person } from "@fedify/vocab"; //#region src/compat/transformers.test.ts const context = new FederationImpl({ kv: new MemoryKvStore() }).createContext(new URL("http://example.com/")); test("autoIdAssigner", async () => { const result = autoIdAssigner(new Follow({ actor: new URL("http://example.com/actors/1"), object: new Person({ id: new URL("http://example.com/actors/2"), name: "Bob", preferredUsername: "bob" }) }), context); const { id } = result; assertInstanceOf(id, URL); assertEquals(id.origin, "http://example.com"); assertEquals(id.pathname, "/"); assertEquals(id.search, ""); assert(id.hash.match(/^#Follow\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)); assertEquals(await result.toJsonLd(), await new Follow({ id, actor: new URL("http://example.com/actors/1"), object: new Person({ id: new URL("http://example.com/actors/2"), name: "Bob", preferredUsername: "bob" }) }).toJsonLd()); }); test("actorDehydrator()", async () => { assertEquals(await actorDehydrator(new Follow({ id: new URL("http://example.com/activities/1"), actor: new Person({ id: new URL("http://example.com/actors/1"), name: "Alice", preferredUsername: "alice" }), object: new Person({ id: new URL("http://example.com/actors/2"), name: "Bob", preferredUsername: "bob" }) }), context).toJsonLd(), await new Follow({ id: new URL("http://example.com/activities/1"), actor: new URL("http://example.com/actors/1"), object: new Person({ id: new URL("http://example.com/actors/2"), name: "Bob", preferredUsername: "bob" }) }).toJsonLd()); }); //#endregion export {};