test(e2e): wire Dropbox Playwright fixtures

This commit is contained in:
Anish Sarkar 2026-05-08 12:28:26 +05:30
parent 69437b1fe4
commit 7303e3ebb3
5 changed files with 147 additions and 2 deletions

View file

@ -0,0 +1,32 @@
import {
type ConnectorRow,
deleteConnector,
runNativeDropboxOAuth,
} from "../../helpers/api/connectors";
import { searchSpaceFixtures } from "../search-space.fixture";
export type NativeDropboxFixtures = {
/**
* A pre-connected native Dropbox connector inside the fixture's
* `searchSpace`. OAuth uses E2E Dropbox fakes and is cleaned up
* automatically after the test.
*/
nativeDropboxConnector: ConnectorRow;
};
export const nativeDropboxFixtures = searchSpaceFixtures.extend<NativeDropboxFixtures>({
nativeDropboxConnector: async ({ request, apiToken, searchSpace }, use) => {
const { connector } = await runNativeDropboxOAuth(request, apiToken, searchSpace.id);
if (!connector) {
throw new Error(
"nativeDropboxConnector fixture: OAuth completed but no DROPBOX_CONNECTOR was created. " +
"Check the backend log — the Dropbox fake likely rejected an unmodelled call."
);
}
try {
await use(connector);
} finally {
await deleteConnector(request, apiToken, connector.id);
}
},
});

View file

@ -22,6 +22,8 @@
* nativeCalendarWithChatTest chatThread
* nativeOneDriveFixtures nativeOneDriveConnector
* nativeOneDriveWithChatTest chatThread
* nativeDropboxFixtures nativeDropboxConnector
* nativeDropboxWithChatTest chatThread
* notionFixtures notionConnector
* notionWithChatTest chatThread
* confluenceFixtures confluenceConnector
@ -48,11 +50,12 @@ export { jiraFixtures } from "./connectors/jira.fixture";
export { linearFixtures } from "./connectors/linear.fixture";
export { nativeCalendarFixtures } from "./connectors/native-calendar.fixture";
export { nativeDriveFixtures } from "./connectors/native-drive.fixture";
export { nativeDropboxFixtures } from "./connectors/native-dropbox.fixture";
export { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
export { nativeOneDriveFixtures } from "./connectors/native-onedrive.fixture";
export { notionFixtures } from "./connectors/notion.fixture";
export { searchSpaceFixtures } from "./search-space.fixture";
export { slackFixtures } from "./connectors/slack.fixture";
export { searchSpaceFixtures } from "./search-space.fixture";
import { type ChatThreadFixtures, chatThreadFixtures } from "./chat-thread.fixture";
import { composioCalendarFixtures } from "./connectors/composio-calendar.fixture";
@ -63,11 +66,12 @@ import { jiraFixtures } from "./connectors/jira.fixture";
import { linearFixtures } from "./connectors/linear.fixture";
import { nativeCalendarFixtures } from "./connectors/native-calendar.fixture";
import { nativeDriveFixtures } from "./connectors/native-drive.fixture";
import { nativeDropboxFixtures } from "./connectors/native-dropbox.fixture";
import { nativeGmailFixtures } from "./connectors/native-gmail.fixture";
import { nativeOneDriveFixtures } from "./connectors/native-onedrive.fixture";
import { notionFixtures } from "./connectors/notion.fixture";
import { searchSpaceFixtures } from "./search-space.fixture";
import { slackFixtures } from "./connectors/slack.fixture";
import { searchSpaceFixtures } from "./search-space.fixture";
/** Default `test` for specs that just need auth + a clean search space. */
export const test = searchSpaceFixtures;
@ -106,6 +110,11 @@ export const nativeOneDriveTest = nativeOneDriveFixtures;
/** `test` for native OneDrive specs that also need a chat thread. */
export const nativeOneDriveWithChatTest =
nativeOneDriveFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
/** `test` for specs that also need a pre-connected native Dropbox connector. */
export const nativeDropboxTest = nativeDropboxFixtures;
/** `test` for native Dropbox specs that also need a chat thread. */
export const nativeDropboxWithChatTest =
nativeDropboxFixtures.extend<ChatThreadFixtures>(chatThreadFixtures);
/** `test` for specs that also need a pre-connected Notion connector. */
export const notionTest = notionFixtures;
/** `test` for Notion specs that also need a chat thread. */

View file

@ -312,6 +312,62 @@ export async function runNativeOneDriveOAuth(
return { authUrl: auth_url, finalUrl: location, connector };
}
/**
* Drives the native Dropbox OAuth flow programmatically.
*
* The Dropbox authorization URL is off-origin, so the helper extracts the
* signed state and calls the backend callback directly. The E2E backend fakes
* Dropbox's token and account HTTP responses inside that callback.
*/
export async function runNativeDropboxOAuth(
request: APIRequestContext,
token: string,
searchSpaceId: number
): Promise<{
authUrl: string;
finalUrl: string;
connector: ConnectorRow | null;
}> {
const initiateResp = await request.get(
`${BACKEND_URL}/api/v1/auth/dropbox/connector/add?space_id=${searchSpaceId}`,
{ headers: authHeaders(token) }
);
if (!initiateResp.ok()) {
throw new Error(
`native Dropbox initiate failed (${initiateResp.status()}): ${await initiateResp.text()}`
);
}
const { auth_url } = (await initiateResp.json()) as { auth_url: string };
if (!auth_url) {
throw new Error("native Dropbox initiate response missing auth_url");
}
const state = new URL(auth_url).searchParams.get("state");
if (!state) {
throw new Error(`native Dropbox auth_url missing state: ${auth_url}`);
}
const callbackResp = await request.get(
`${BACKEND_URL}/api/v1/auth/dropbox/connector/callback?code=fake-dropbox-oauth-code&state=${encodeURIComponent(state)}`,
{
headers: authHeaders(token),
maxRedirects: 0,
failOnStatusCode: false,
}
);
if (callbackResp.status() >= 400) {
throw new Error(
`native Dropbox callback failed (${callbackResp.status()}): ${await callbackResp.text()}`
);
}
const location = callbackResp.headers().location ?? auth_url;
const connectors = await listConnectors(request, token, searchSpaceId);
const connector = connectors.find((c) => c.connector_type === "DROPBOX_CONNECTOR") ?? null;
return { authUrl: auth_url, finalUrl: location, connector };
}
/**
* Drives the native Google Gmail OAuth flow programmatically.
*

View file

@ -21,6 +21,7 @@ export const CANARY_TOKENS = {
gmailCanary: "SURFSENSE_E2E_CANARY_TOKEN_GMAIL_001",
calendarCanary: "SURFSENSE_E2E_CANARY_TOKEN_CALENDAR_001",
onedriveCanary: "SURFSENSE_E2E_CANARY_TOKEN_ONEDRIVE_001",
dropboxCanary: "SURFSENSE_E2E_CANARY_TOKEN_DROPBOX_001",
notionCanary: "SURFSENSE_E2E_CANARY_TOKEN_NOTION_001",
confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001",
linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001",
@ -63,6 +64,18 @@ export const FAKE_ONEDRIVE_FILES = {
},
} as const;
/**
* Fake Dropbox file paths that match the Dropbox-shaped backend fake in
* dropbox_files.json. Dropbox selected-file indexing accepts path_lower via id.
*/
export const FAKE_DROPBOX_FILES = {
canary: {
id: "/e2e-dropbox-canary.txt",
name: "e2e-dropbox-canary.txt",
mimeType: "text/plain",
},
} as const;
/**
* Fake Gmail message IDs that match what the backend fake returns from
* GMAIL_FETCH_EMAILS / GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID.