forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {type IsValidHandle, validateServiceHandle} from '#/lib/strings/handles'
2
3describe('handle validation', () => {
4 const valid = [
5 ['ali', 'bsky.social'],
6 ['alice', 'bsky.social'],
7 ['a-lice', 'bsky.social'],
8 ['a-----lice', 'bsky.social'],
9 ['123', 'bsky.social'],
10 ['123456789012345678', 'bsky.social'],
11 ['alice', 'custom-pds.com'],
12 ['alice', 'my-custom-pds-with-long-name.social'],
13 ['123456789012345678', 'my-custom-pds-with-long-name.social'],
14 ]
15 it.each(valid)(`should be valid: %s.%s`, (handle, service) => {
16 const result = validateServiceHandle(handle, service)
17 expect(result.overall).toEqual(true)
18 })
19
20 const invalid = [
21 ['al', 'bsky.social', 'frontLengthNotTooShort'],
22 ['-alice', 'bsky.social', 'hyphenStartOrEnd'],
23 ['alice-', 'bsky.social', 'hyphenStartOrEnd'],
24 ['%%%', 'bsky.social', 'handleChars'],
25 ['1234567890123456789', 'bsky.social', 'frontLengthNotTooLong'],
26 [
27 '1234567890123456789',
28 'my-custom-pds-with-long-name.social',
29 'frontLengthNotTooLong',
30 ],
31 ['al', 'my-custom-pds-with-long-name.social', 'frontLengthNotTooShort'],
32 ['a'.repeat(300), 'toolong.com', 'totalLength'],
33 ] satisfies [string, string, keyof IsValidHandle][]
34 it.each(invalid)(
35 `should be invalid: %s.%s due to %s`,
36 (handle, service, expectedError) => {
37 const result = validateServiceHandle(handle, service)
38 expect(result.overall).toEqual(false)
39 expect(result[expectedError]).toEqual(false)
40 },
41 )
42})