Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/sim/lib/slack-search/onboarding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/** @vitest-environment node */
import { beforeEach, describe, expect, it, vi } from 'vitest'

const { getEnv } = vi.hoisted(() => ({ getEnv: vi.fn() }))

vi.unmock('@/lib/core/utils/urls')
vi.mock('@/lib/core/config/env', () => ({
env: { NEXT_PUBLIC_APP_URL: 'http://localhost:3000' },
getEnv,
}))
vi.mock('@/lib/core/config/env-flags', () => ({ isProd: true }))

import { slackSearchOnboardingUrl } from '@/lib/slack-search/onboarding'

describe('Slack onboarding URL', () => {
beforeEach(() => {
getEnv.mockReset()
})

it.each(['https://staging.example.com', 'https://app.example.com', 'https://search.example.org'])(
'uses the runtime origin %s instead of the build-time localhost value',
(origin) => {
getEnv.mockImplementation((key: string) =>
key === 'NEXT_PUBLIC_APP_URL' ? origin : undefined
)
expect(slackSearchOnboardingUrl('opaque-token')).toBe(
`${origin}/slack-search/connect/opaque-token`
)
}
)

it('fails when the runtime public URL is missing instead of using the build-time value', () => {
expect(() => slackSearchOnboardingUrl('opaque-token')).toThrow(
'NEXT_PUBLIC_APP_URL must be configured'
)
})
})
4 changes: 2 additions & 2 deletions apps/sim/lib/slack-search/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '@/lib/core/config/env'
import { getBaseUrl } from '@/lib/core/utils/urls'
import { organizationRoutes } from '@/lib/navigation/paths'

export function slackSearchOnboardingPath(token: string) {
Expand All @@ -12,7 +12,7 @@ export function slackSearchIntegrationsPath(organizationId: string, token: strin

/** The destination is application-authored; model-generated links never enter onboarding. */
export function slackSearchOnboardingUrl(token: string) {
return new URL(slackSearchOnboardingPath(token), env.NEXT_PUBLIC_APP_URL).href
return new URL(slackSearchOnboardingPath(token), getBaseUrl()).href
}

export const SLACK_SEARCH_CONNECT_ACCOUNT =
Expand Down
Loading