-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(search): close Slack and desktop source-connect review gaps #8500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
apps/sim/app/api/credential-groups/slack-managed-users/callback/route.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { authMockFns } from '@sim/testing' | ||
| import { NextRequest } from 'next/server' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { GET } from '@/app/api/credential-groups/slack-managed-users/callback/route' | ||
|
|
||
| describe('GET /api/credential-groups/slack-managed-users/callback', () => { | ||
| it('sends a signed-out browser to the sign-in recovery screen', async () => { | ||
| authMockFns.mockGetSession.mockResolvedValueOnce(null) | ||
| const response = await GET( | ||
| new NextRequest( | ||
| 'http://localhost/api/credential-groups/slack-managed-users/callback?state=s1&code=c1' | ||
| ), | ||
| {} | ||
| ) | ||
| expect(response.status).toBe(303) | ||
| const location = new URL(response.headers.get('location') ?? '') | ||
| expect(location.pathname).toBe('/credential-groups/slack-complete') | ||
| expect(location.searchParams.get('reason')).toBe('signin_required') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { authMockFns } from '@sim/testing' | ||
| import { NextRequest } from 'next/server' | ||
| import { beforeEach, describe, expect, it } from 'vitest' | ||
| import { POST } from '@/app/api/desktop/source-connect/route' | ||
|
|
||
| describe('POST /api/desktop/source-connect', () => { | ||
| beforeEach(() => { | ||
| authMockFns.mockGetSession.mockResolvedValue({ user: { id: 'u1' }, session: { id: 's1' } }) | ||
| }) | ||
|
|
||
| it('rejects a body far beyond the ticket limit at the parser', async () => { | ||
| const body = JSON.stringify({ | ||
| requestId: 'a'.repeat(32), | ||
| request: { kind: 'reconnect-account', credentialId: 'c'.repeat(128) }, | ||
| padding: 'x'.repeat(256 * 1024), | ||
| }) | ||
| const response = await POST( | ||
| new NextRequest('http://localhost/api/desktop/source-connect', { | ||
| method: 'POST', | ||
| headers: { 'content-type': 'application/json' }, | ||
| body, | ||
| }), | ||
| {} | ||
| ) | ||
| expect(response.status).toBe(413) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** @vitest-environment jsdom */ | ||
|
|
||
| import { act } from 'react' | ||
| import { | ||
| apiClientRequestMock, | ||
| apiClientRequestMockFns, | ||
| } from '@sim/testing/mocks/api-client-request.mock' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('@/lib/api/client/request', () => apiClientRequestMock) | ||
|
|
||
| import { useStartSlackSearchOAuth } from '@/hooks/queries/slack-search' | ||
|
|
||
| const mockRequestJson = apiClientRequestMockFns.mockRequestJson | ||
|
|
||
| describe('useStartSlackSearchOAuth', () => { | ||
| let root: Root | ||
| let client: QueryClient | ||
| let result: ReturnType<typeof useStartSlackSearchOAuth> | ||
|
|
||
| function Probe() { | ||
| result = useStartSlackSearchOAuth() | ||
| return null | ||
| } | ||
|
|
||
| beforeEach(async () => { | ||
| vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) | ||
| mockRequestJson.mockReset() | ||
| client = new QueryClient() | ||
| root = createRoot(document.createElement('div')) | ||
| await act(async () => | ||
| root.render( | ||
| <QueryClientProvider client={client}> | ||
| <Probe /> | ||
| </QueryClientProvider> | ||
| ) | ||
| ) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => root.unmount()) | ||
| client.clear() | ||
| }) | ||
|
|
||
| it('cancels an in-flight browser OAuth start when its signal aborts', async () => { | ||
| mockRequestJson.mockImplementation( | ||
| (_contract: unknown, input: { signal?: AbortSignal }) => | ||
| new Promise((_resolve, reject) => | ||
| input.signal?.addEventListener('abort', () => reject(input.signal?.reason)) | ||
| ) | ||
| ) | ||
| const controller = new AbortController() | ||
| let outcome: 'pending' | 'rejected' = 'pending' | ||
| await act(async () => { | ||
| void result | ||
| .mutateAsync({ | ||
| organizationId: 'org-1', | ||
| name: 'Sim Search', | ||
| description: 'Search Slack', | ||
| mode: 'shared', | ||
| signal: controller.signal, | ||
| }) | ||
| .catch(() => { | ||
| outcome = 'rejected' | ||
| }) | ||
| }) | ||
| await act(async () => controller.abort()) | ||
| expect(outcome).toBe('rejected') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.