Files
supabase/apps/studio/tests/pages/org/routeSlug.utils.test.ts
Jordi Enric 9c8a8d25d1 fix: universal link redirects to general (#43131)
Currently `/org/_` redirects to `/general` (org settings) after picking
an org, this makes it redirect to the project list

## to test
- go to /dashboard/org/_
- select org
- redirects to project picker 

## test 2
- go to /dashboard/org/_/general
- select org
- redirects to /org/whatever/general (settings)
2026-02-24 16:10:30 +01:00

65 lines
2.1 KiB
TypeScript

import { buildOrgUrl } from 'components/interfaces/Organization/Organization.utils'
import { describe, expect, test } from 'vitest'
describe('buildOrgUrl', () => {
describe('when slug is undefined (bare /org/_ route)', () => {
test('returns the org project list url', () => {
expect(buildOrgUrl({ slug: undefined, orgSlug: 'my-org', queryString: '' })).toBe(
'/org/my-org'
)
})
test('appends query string when present', () => {
expect(buildOrgUrl({ slug: undefined, orgSlug: 'my-org', queryString: 'foo=bar' })).toBe(
'/org/my-org?foo=bar'
)
})
test('does not append a bare ? when query string is empty', () => {
expect(buildOrgUrl({ slug: undefined, orgSlug: 'my-org', queryString: '' })).not.toContain(
'?'
)
})
})
describe('when slug is a string (next.js router quirk — single segment)', () => {
test('returns the org project list url, ignoring the string slug', () => {
expect(buildOrgUrl({ slug: 'general', orgSlug: 'my-org', queryString: '' })).toBe(
'/org/my-org'
)
})
test('appends query string when present', () => {
expect(buildOrgUrl({ slug: 'general', orgSlug: 'my-org', queryString: 'ref=abc' })).toBe(
'/org/my-org?ref=abc'
)
})
})
describe('when slug is an array (sub-path route)', () => {
test('preserves a single-segment sub-path', () => {
expect(buildOrgUrl({ slug: ['general'], orgSlug: 'my-org', queryString: '' })).toBe(
'/org/my-org/general'
)
})
test('preserves a multi-segment sub-path', () => {
expect(
buildOrgUrl({ slug: ['settings', 'billing'], orgSlug: 'my-org', queryString: '' })
).toBe('/org/my-org/settings/billing')
})
test('appends query string when present', () => {
expect(
buildOrgUrl({ slug: ['general'], orgSlug: 'my-org', queryString: 'foo=1&bar=2' })
).toBe('/org/my-org/general?foo=1&bar=2')
})
test('does not append a bare ? when query string is empty', () => {
expect(buildOrgUrl({ slug: ['general'], orgSlug: 'my-org', queryString: '' })).not.toContain(
'?'
)
})
})
})