Skip to content

Commit 319aee5

Browse files
fix(slack): use runtime origin for onboarding links
1 parent 92d231d commit 319aee5

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/** @vitest-environment node */
2+
import { beforeEach, describe, expect, it, vi } from 'vitest'
3+
4+
const { getEnv } = vi.hoisted(() => ({ getEnv: vi.fn() }))
5+
6+
vi.unmock('@/lib/core/utils/urls')
7+
vi.mock('@/lib/core/config/env', () => ({
8+
env: { NEXT_PUBLIC_APP_URL: 'http://localhost:3000' },
9+
getEnv,
10+
}))
11+
vi.mock('@/lib/core/config/env-flags', () => ({ isProd: true }))
12+
13+
import { slackSearchOnboardingUrl } from '@/lib/slack-search/onboarding'
14+
15+
describe('Slack onboarding URL', () => {
16+
beforeEach(() => {
17+
getEnv.mockReset()
18+
})
19+
20+
it.each(['https://staging.example.com', 'https://app.example.com', 'https://search.example.org'])(
21+
'uses the runtime origin %s instead of the build-time localhost value',
22+
(origin) => {
23+
getEnv.mockImplementation((key: string) =>
24+
key === 'NEXT_PUBLIC_APP_URL' ? origin : undefined
25+
)
26+
expect(slackSearchOnboardingUrl('opaque-token')).toBe(
27+
`${origin}/slack-search/connect/opaque-token`
28+
)
29+
}
30+
)
31+
32+
it('fails when the runtime public URL is missing instead of using the build-time value', () => {
33+
expect(() => slackSearchOnboardingUrl('opaque-token')).toThrow(
34+
'NEXT_PUBLIC_APP_URL must be configured'
35+
)
36+
})
37+
})

apps/sim/lib/slack-search/onboarding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { env } from '@/lib/core/config/env'
1+
import { getBaseUrl } from '@/lib/core/utils/urls'
22
import { organizationRoutes } from '@/lib/navigation/paths'
33

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

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

1818
export const SLACK_SEARCH_CONNECT_ACCOUNT =

0 commit comments

Comments
 (0)