~james/core

core/web/src/lib/avatar.test.ts -rw-r--r-- 1.1 KiB
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 { describe, expect, it } from "vitest";
import { avatarUrl, bumpAvatar } from "#lib/avatar.ts";

describe("avatarUrl", () => {
	it("points at the signing route with the requested size", () => {
		expect(avatarUrl("did:plc:alice", 96)).toBe("/avatar/did%3Aplc%3Aalice?size=96");
	});

	it("carries the version of an avatar that was just changed", () => {
		bumpAvatar("did:plc:bob", "3lk2");
		expect(avatarUrl("did:plc:bob", 96)).toBe("/avatar/did%3Aplc%3Abob?size=96&v=3lk2");
		expect(avatarUrl("did:plc:carol")).toBe("/avatar/did%3Aplc%3Acarol");
	});

	it("versions an avatar by the end of its cid", () => {
		const cid = "bafkreigh2akiscaildc7gnvtklbsfhdgwz72eolmpckbqr5ej26byp3uli";
		expect(avatarUrl("did:plc:dave", 96, undefined, cid)).toBe(
			`/avatar/did%3Aplc%3Adave?size=96&v=${cid.slice(-12)}`
		);
	});

	it("prefers the version of an avatar that was just changed over its cid", () => {
		bumpAvatar("did:plc:erin", "3lk3");
		expect(avatarUrl("did:plc:erin", 96, undefined, "bafkreiabcdefghijklmnop")).toBe(
			"/avatar/did%3Aplc%3Aerin?size=96&v=3lk3"
		);
	});
});