Coves frontend - a photon fork
1import { describe, it, expect } from 'vitest'
2import { match } from './handle'
3
4describe('handle param matcher', () => {
5 describe('valid handles', () => {
6 it('matches a standard handle', () => {
7 expect(match('alice.coves.social')).toBe(true)
8 })
9
10 it('matches a two-segment handle', () => {
11 expect(match('bob.example.com')).toBe(true)
12 })
13
14 it('matches a handle with hyphens', () => {
15 expect(match('my-user.some-domain.co')).toBe(true)
16 })
17
18 it('matches a handle with numeric segments', () => {
19 expect(match('user1.test123.org')).toBe(true)
20 })
21 })
22
23 describe('valid DIDs (URL-encoded)', () => {
24 it('matches a URL-encoded did:plc', () => {
25 expect(match('did%3Aplc%3Aabc123')).toBe(true)
26 })
27
28 it('matches a URL-encoded did:web', () => {
29 expect(match('did%3Aweb%3Aexample.com')).toBe(true)
30 })
31 })
32
33 describe('reserved route segments', () => {
34 it('rejects "settings"', () => {
35 expect(match('settings')).toBe(false)
36 })
37
38 it('rejects "blocks"', () => {
39 expect(match('blocks')).toBe(false)
40 })
41
42 it('rejects "media"', () => {
43 expect(match('media')).toBe(false)
44 })
45
46 it('rejects "voted"', () => {
47 expect(match('voted')).toBe(false)
48 })
49
50 it('rejects "saved"', () => {
51 expect(match('saved')).toBe(false)
52 })
53 })
54
55 describe('invalid strings', () => {
56 it('rejects empty string', () => {
57 expect(match('')).toBe(false)
58 })
59
60 it('rejects a single word without dots', () => {
61 expect(match('alice')).toBe(false)
62 })
63
64 it('rejects a string with spaces', () => {
65 expect(match('alice .example.com')).toBe(false)
66 })
67
68 it('rejects a string starting with a hyphen', () => {
69 expect(match('-alice.example.com')).toBe(false)
70 })
71
72 it('rejects a string with only dots', () => {
73 expect(match('...')).toBe(false)
74 })
75 })
76})