~james/core

core/web/src/lib/api/profileIdentifier.test.ts -rw-r--r-- 845 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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);
	});
});