TriggerList.utils.test.ts 1.5 KB

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