FunctionList.utils.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { describe, expect, it } from 'vitest'
  2. import { getDatabaseTriggersHref } from './FunctionList.utils'
  3. describe('FunctionList.utils: getDatabaseTriggersHref', () => {
  4. it('builds the triggers href with a plain function name', () => {
  5. expect(getDatabaseTriggersHref('abc', 'on_insert')).toBe(
  6. '/project/abc/database/triggers?search=on_insert'
  7. )
  8. })
  9. it('preserves special characters in the function name', () => {
  10. const href = getDatabaseTriggersHref('abc', 'on_insert&schema=secret')
  11. const parsed = new URL(href, 'http://example.com')
  12. expect(parsed.searchParams.get('search')).toBe('on_insert&schema=secret')
  13. expect(parsed.searchParams.get('schema')).toBeNull()
  14. })
  15. it('preserves spaces and plus signs in the function name', () => {
  16. const href = getDatabaseTriggersHref('abc', 'a name+x')
  17. const parsed = new URL(href, 'http://example.com')
  18. expect(parsed.searchParams.get('search')).toBe('a name+x')
  19. })
  20. it('falls back to empty strings for undefined inputs', () => {
  21. expect(getDatabaseTriggersHref(undefined, undefined)).toBe(
  22. '/project//database/triggers?search='
  23. )
  24. })
  25. })