@fedify/fedify
Version:
An ActivityPub server framework
93 lines (89 loc) • 3.07 kB
JavaScript
import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { assertEquals } from "../assert_equals-CTYbeopb.js";
import { assert } from "../assert-DmFG7ppO.js";
import { assertInstanceOf } from "../assert_instance_of-CF09JHYM.js";
import { MemoryKvStore } from "../kv-BMY6Qf_A.js";
import { FederationImpl, actorDehydrator, autoIdAssigner } from "../middleware-DlU2_Djj.js";
import "../docloader-C8mmLN-Y.js";
import "../url-kTAI6_KP.js";
import "../semver-DWClQt_5.js";
import "../client-rv6n0nKR.js";
import "../router-D_aVZZUc.js";
import "../types-C7C_l-jz.js";
import "../multibase-DeCHcK8L.js";
import { Follow, Person } from "../vocab-dDpPQ0fF.js";
import "../langstr-DbWheeIS.js";
import "../lookup-Ozuw-rxN.js";
import "../type-D2s5lmbZ.js";
import "../actor-BP-NTJ2m.js";
import "../key-CPSlDkCj.js";
import "../http-BmfI6U39.js";
import "../authdocloader-Banw__l6.js";
import "../ld-D9kk1Uy2.js";
import "../owner-DF6Fg4-s.js";
import "../proof-13QPysOU.js";
import "../lookup-DNXR408t.js";
import "../inbox-AwdJVoMZ.js";
import "../builder-EdzpUb9N.js";
import "../collection-Dfb0TPno.js";
import "../keycache-BPwY_Up0.js";
import "../retry-BiIhZWgD.js";
import "../send-CaL5Xv1F.js";
import { test } from "../testing-BZ0dJ4qn.js";
//#region compat/transformers.test.ts
const federation = new FederationImpl({ kv: new MemoryKvStore() });
const context = federation.createContext(new URL("http://example.com/"));
test("autoIdAssigner", async () => {
const activity = 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"
})
});
const result = autoIdAssigner(activity, 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 () => {
const activity = 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"
})
});
const result = actorDehydrator(activity, context);
assertEquals(await result.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