feat: validate intentional post requests

This commit is contained in:
2026-07-13 10:21:27 +09:00
parent 92fbcd2242
commit 5873728c30
5 changed files with 185 additions and 0 deletions
+41
View File
@@ -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()
})
})