summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/stickers/__tests__/sticker-id.test.ts
blob: 573dc251f2848da78caa21ab7b32a62b725f16b6 (plain) (blame)
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
29
30
31
32
33
34
import { describe, expect, test } from "bun:test";
import { buildStickerId, parseStickerId } from "../sticker-id";

describe("sticker-id strict mode", () => {
	test("parses provider-prefixed IDs", () => {
		expect(parseStickerId({ stickerId: "icons:mdi:home" })).toEqual({
			providerId: "icons",
			providerValue: "mdi:home",
		});
		expect(parseStickerId({ stickerId: "emoji:noto:grinning-face" })).toEqual({
			providerId: "emoji",
			providerValue: "noto:grinning-face",
		});
	});

	test("throws for IDs without provider prefix", () => {
		expect(() => parseStickerId({ stickerId: "home" })).toThrow();
	});

	test("throws for malformed IDs", () => {
		expect(() => parseStickerId({ stickerId: "" })).toThrow();
		expect(() => parseStickerId({ stickerId: "icons:" })).toThrow();
		expect(() => parseStickerId({ stickerId: ":mdi:home" })).toThrow();
	});

	test("builds sticker IDs unchanged", () => {
		expect(
			buildStickerId({
				providerId: "flags",
				providerValue: "US",
			}),
		).toBe("flags:US");
	});
});