1db2668a96
* fix validation logic for 3p pdses * fix bad import * add service handle validation test
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
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)
|
|
},
|
|
)
|
|
})
|