
      import { Temporal } from "@js-temporal/polyfill";
      import { URLPattern } from "urlpattern-polyfill";
      globalThis.addEventListener = () => {};
    
import { Collection, Note, Object as Object$1, Person } from "../type-BSR-vRXo.js";
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
import "../assert-MZs1qjMx.js";
import { assertInstanceOf } from "../assert_instance_of-DHz7EHNU.js";
import { lookupObject, traverseCollection } from "../lookup-q8DeFAjR.js";
import { mockDocumentLoader, test } from "../testing-Cqwzq9nj.js";
import "../std__assert-X-_kMxKM.js";
import "../assert_rejects-DiIiJbZn.js";
import "../assert_is_error-BPGph1Jx.js";
import "../assert_not_equals-f3m3epl3.js";
import "../assert_throws-BOO88avQ.js";
import { esm_default } from "../esm-CIFbziGC.js";

//#region src/vocab/lookup.test.ts
test("lookupObject()", {
	sanitizeResources: false,
	sanitizeOps: false
}, 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.removeRoutes();
	esm_default.get("begin:https://example.com/.well-known/webfinger", () => new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				subject: "acct:johndoe@example.com",
				links: [{
					rel: "self",
					href: "https://example.com/person",
					type: "application/activity+json"
				}]
			});
		}, 1e3);
	}));
	await t.step("request cancellation", async () => {
		const controller = new AbortController();
		const promise = lookupObject("johndoe@example.com", {
			...options,
			signal: controller.signal
		});
		controller.abort();
		assertEquals(await promise, null);
	});
	esm_default.removeRoutes();
	esm_default.get("begin:https://example.com/.well-known/webfinger", {
		subject: "acct:johndoe@example.com",
		links: [{
			rel: "self",
			href: "https://example.com/person",
			type: "application/activity+json"
		}]
	});
	await t.step("successful request with signal", async () => {
		const controller = new AbortController();
		const person = await lookupObject("johndoe@example.com", {
			...options,
			signal: controller.signal
		});
		assertInstanceOf(person, Person);
		assertEquals(person.id, new URL("https://example.com/person"));
	});
	esm_default.removeRoutes();
	esm_default.get("begin:https://example.com/.well-known/webfinger", () => new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				subject: "acct:johndoe@example.com",
				links: [{
					rel: "self",
					href: "https://example.com/person",
					type: "application/activity+json"
				}]
			});
		}, 500);
	}));
	await t.step("cancellation with immediate abort", async () => {
		const controller = new AbortController();
		controller.abort();
		const result = await lookupObject("johndoe@example.com", {
			...options,
			signal: controller.signal
		});
		assertEquals(result, null);
	});
	esm_default.removeRoutes();
	esm_default.get("https://example.com/slow-object", () => new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				status: 200,
				headers: { "Content-Type": "application/activity+json" },
				body: {
					"@context": "https://www.w3.org/ns/activitystreams",
					type: "Note",
					content: "Slow response"
				}
			});
		}, 1e3);
	}));
	await t.step("direct object fetch cancellation", async () => {
		const controller = new AbortController();
		const promise = lookupObject("https://example.com/slow-object", {
			contextLoader: mockDocumentLoader,
			signal: controller.signal
		});
		controller.abort();
		assertEquals(await promise, null);
	});
	esm_default.hardReset();
	esm_default.removeRoutes();
});
test("traverseCollection()", {
	sanitizeResources: false,
	sanitizeOps: false
}, 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