WIP! A BB-style forum, on the ATmosphere!
We're still working... we'll be back soon when we have something to show off!
node
typescript
hono
htmx
atproto
1import { describe, it, expect, vi } from "vitest";
2import { resolveIdentity } from "../resolve-identity.js";
3import { AtpAgent } from "@atproto/api";
4
5vi.mock("@atproto/api", () => ({
6 AtpAgent: vi.fn(),
7}));
8
9describe("resolveIdentity", () => {
10 it("returns DID directly when input starts with 'did:'", async () => {
11 const result = await resolveIdentity("did:plc:abc123", "https://bsky.social");
12
13 expect(result).toEqual({ did: "did:plc:abc123" });
14 // AtpAgent should NOT be instantiated for DID input
15 expect(AtpAgent).not.toHaveBeenCalled();
16 });
17
18 it("resolves a handle to a DID via PDS", async () => {
19 const mockResolveHandle = vi.fn().mockResolvedValue({
20 data: { did: "did:plc:resolved123" },
21 });
22 (AtpAgent as any).mockImplementation(function () {
23 return { resolveHandle: mockResolveHandle };
24 });
25
26 const result = await resolveIdentity("alice.bsky.social", "https://bsky.social");
27
28 expect(result).toEqual({
29 did: "did:plc:resolved123",
30 handle: "alice.bsky.social",
31 });
32 expect(AtpAgent).toHaveBeenCalledWith({ service: "https://bsky.social" });
33 expect(mockResolveHandle).toHaveBeenCalledWith({ handle: "alice.bsky.social" });
34 });
35
36 it("throws when handle resolution fails", async () => {
37 (AtpAgent as any).mockImplementation(function () {
38 return {
39 resolveHandle: vi.fn().mockRejectedValue(new Error("Unable to resolve handle")),
40 };
41 });
42
43 await expect(
44 resolveIdentity("nonexistent.bsky.social", "https://bsky.social")
45 ).rejects.toThrow("Unable to resolve handle");
46 });
47});