diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-02-06 14:55:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-06 14:55:57 +0000 |
commit | 1db2668a96208046ffe316114f65d432e57db994 (patch) | |
tree | 735a1a2989721f05910fc21343a2b1f15cc02963 /__tests__ | |
parent | 00c08ba525638ab105e142d8f58788c66cb75b00 (diff) | |
download | voidsky-1db2668a96208046ffe316114f65d432e57db994.tar.zst |
Improved service handle validation logic (#7657)
* fix validation logic for 3p pdses * fix bad import * add service handle validation test
Diffstat (limited to '__tests__')
-rw-r--r-- | __tests__/lib/strings/handles.test.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/__tests__/lib/strings/handles.test.ts b/__tests__/lib/strings/handles.test.ts new file mode 100644 index 000000000..4456fae94 --- /dev/null +++ b/__tests__/lib/strings/handles.test.ts @@ -0,0 +1,42 @@ +import {IsValidHandle, validateServiceHandle} from '#/lib/strings/handles' + +describe('handle validation', () => { + const valid = [ + ['ali', 'bsky.social'], + ['alice', 'bsky.social'], + ['a-lice', 'bsky.social'], + ['a-----lice', 'bsky.social'], + ['123', 'bsky.social'], + ['123456789012345678', 'bsky.social'], + ['alice', 'custom-pds.com'], + ['alice', 'my-custom-pds-with-long-name.social'], + ['123456789012345678', 'my-custom-pds-with-long-name.social'], + ] + it.each(valid)(`should be valid: %s.%s`, (handle, service) => { + const result = validateServiceHandle(handle, service) + expect(result.overall).toEqual(true) + }) + + const invalid = [ + ['al', 'bsky.social', 'frontLength'], + ['-alice', 'bsky.social', 'hyphenStartOrEnd'], + ['alice-', 'bsky.social', 'hyphenStartOrEnd'], + ['%%%', 'bsky.social', 'handleChars'], + ['1234567890123456789', 'bsky.social', 'frontLength'], + [ + '1234567890123456789', + 'my-custom-pds-with-long-name.social', + 'frontLength', + ], + ['al', 'my-custom-pds-with-long-name.social', 'frontLength'], + ['a'.repeat(300), 'toolong.com', 'totalLength'], + ] satisfies [string, string, keyof IsValidHandle][] + it.each(invalid)( + `should be invalid: %s.%s due to %s`, + (handle, service, expectedError) => { + const result = validateServiceHandle(handle, service) + expect(result.overall).toEqual(false) + expect(result[expectedError]).toEqual(false) + }, + ) +}) |