feat: validate intentional post requests
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildSearchQuery, normalizeUserTarget } from './inputs'
|
||||
|
||||
describe('normalizeUserTarget', () => {
|
||||
it.each([
|
||||
['@tan_stack', 'tan_stack'],
|
||||
['tan_stack', 'tan_stack'],
|
||||
['https://x.com/tan_stack', 'tan_stack'],
|
||||
['https://twitter.com/tan_stack/', 'tan_stack'],
|
||||
])('normalizes %s', (input, expected) => {
|
||||
expect(normalizeUserTarget(input)).toBe(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'',
|
||||
'not valid',
|
||||
'https://example.com/tan_stack',
|
||||
'https://x.com/tan_stack/status/1',
|
||||
])('rejects %s', (input) => {
|
||||
expect(() => normalizeUserTarget(input)).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildSearchQuery', () => {
|
||||
it('keeps a deliberate query unchanged', () => {
|
||||
expect(buildSearchQuery(' AI lang:ja ', false)).toBe('AI lang:ja')
|
||||
})
|
||||
|
||||
it('adds the follows operator once', () => {
|
||||
expect(buildSearchQuery('AI lang:ja', true)).toBe(
|
||||
'AI lang:ja filter:follows',
|
||||
)
|
||||
expect(buildSearchQuery('AI filter:follows', true)).toBe(
|
||||
'AI filter:follows',
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects an empty query', () => {
|
||||
expect(() => buildSearchQuery(' ', false)).toThrow()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user