TriggerList.utils.test.ts38 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { getDatabaseFunctionsHref } from './TriggerList.utils' |
| 4 | |
| 5 | describe('TriggerList.utils: getDatabaseFunctionsHref', () => { |
| 6 | it('builds the functions href with plain values', () => { |
| 7 | expect(getDatabaseFunctionsHref('abc', 'public', 'do_thing')).toBe( |
| 8 | '/project/abc/database/functions?search=do_thing&schema=public' |
| 9 | ) |
| 10 | }) |
| 11 | |
| 12 | it('preserves special characters in the function name', () => { |
| 13 | const href = getDatabaseFunctionsHref('abc', 'public', 'do_thing&secret=1') |
| 14 | const parsed = new URL(href, 'http://example.com') |
| 15 | expect(parsed.searchParams.get('search')).toBe('do_thing&secret=1') |
| 16 | expect(parsed.searchParams.get('schema')).toBe('public') |
| 17 | }) |
| 18 | |
| 19 | it('preserves special characters in the schema', () => { |
| 20 | const href = getDatabaseFunctionsHref('abc', 'my schema+x', 'do_thing') |
| 21 | const parsed = new URL(href, 'http://example.com') |
| 22 | expect(parsed.searchParams.get('schema')).toBe('my schema+x') |
| 23 | expect(parsed.searchParams.get('search')).toBe('do_thing') |
| 24 | }) |
| 25 | |
| 26 | it('encodes both name and schema together', () => { |
| 27 | const href = getDatabaseFunctionsHref('abc', 'a&b=c', 'd e+f') |
| 28 | const parsed = new URL(href, 'http://example.com') |
| 29 | expect(parsed.searchParams.get('schema')).toBe('a&b=c') |
| 30 | expect(parsed.searchParams.get('search')).toBe('d e+f') |
| 31 | }) |
| 32 | |
| 33 | it('falls back to empty strings for undefined inputs', () => { |
| 34 | expect(getDatabaseFunctionsHref(undefined, undefined, undefined)).toBe( |
| 35 | '/project//database/functions?search=&schema=' |
| 36 | ) |
| 37 | }) |
| 38 | }) |