import type { Handle } from "@atcute/lexicons/syntax";
import { describe, expect, it } from "vitest";
import { INVALID_HANDLE, canonicalHandle, profileIdentifier } from "#lib/api/profileIdentifier.ts";
const DID = "did:plc:epbi6paber3mxm7237xkwvj5";
describe("profileIdentifier", () => {
it("uses a valid handle", () => {
expect(profileIdentifier("opensocial.group", DID)).toBe("opensocial.group");
});
it.each<Handle | undefined>([INVALID_HANDLE, undefined])(
"falls back to the did for %j",
(handle) => {
expect(profileIdentifier(handle, DID)).toBe(DID);
}
);
});
describe("canonicalHandle", () => {
it.each<[Handle | undefined, Handle | null]>([
["nel.pet", "nel.pet"],
[INVALID_HANDLE, null],
[undefined, null]
])("maps %j to %j", (handle, expected) => {
expect(canonicalHandle(handle)).toBe(expected);
});
});