Integrations.utils.test.ts49 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { getCategoryParamFromAsPath, getIntegrationsPageFromPathname } from './Integrations.utils'
4
5describe('getIntegrationsPageFromPathname', () => {
6 it('returns section only when no subsection', () => {
7 expect(getIntegrationsPageFromPathname('/project/abc123/integrations')).toBe('integrations')
8 })
9
10 it('returns section and subsection when both present', () => {
11 expect(getIntegrationsPageFromPathname('/project/abc123/integrations/xyz-456')).toBe(
12 'integrations/xyz-456'
13 )
14 })
15
16 it('returns empty string when path too short', () => {
17 expect(getIntegrationsPageFromPathname('/project')).toBe('')
18 expect(getIntegrationsPageFromPathname('/project/abc123')).toBe('')
19 expect(getIntegrationsPageFromPathname('/')).toBe('')
20 expect(getIntegrationsPageFromPathname('')).toBe('')
21 })
22
23 it('returns empty string when project segment not found', () => {
24 expect(getIntegrationsPageFromPathname('/org/my-org')).toBe('')
25 })
26
27 it('handles trailing slash', () => {
28 expect(getIntegrationsPageFromPathname('/project/abc123/integrations/')).toBe('integrations')
29 })
30})
31
32describe('getCategoryParamFromAsPath', () => {
33 it('returns category value when present', () => {
34 expect(getCategoryParamFromAsPath('/project/ref/integrations?category=wrapper')).toBe('wrapper')
35 expect(getCategoryParamFromAsPath('/path?category=postgres_extension')).toBe(
36 'postgres_extension'
37 )
38 })
39
40 it('returns null when category absent', () => {
41 expect(getCategoryParamFromAsPath('/project/ref/integrations')).toBeNull()
42 expect(getCategoryParamFromAsPath('/path?foo=bar')).toBeNull()
43 })
44
45 it('returns null for invalid input', () => {
46 expect(getCategoryParamFromAsPath(undefined)).toBeNull()
47 expect(getCategoryParamFromAsPath('')).toBeNull()
48 })
49})