test(e2e): add OneDrive connector Playwright journey

This commit is contained in:
Anish Sarkar 2026-05-08 03:48:58 +05:30
parent da8b151634
commit 2d78dda487
5 changed files with 239 additions and 0 deletions

View file

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

View file

@ -20,6 +20,7 @@ export const CANARY_TOKENS = {
driveArchive: "SURFSENSE_E2E_ARCHIVE_MARKER",
gmailCanary: "SURFSENSE_E2E_CANARY_TOKEN_GMAIL_001",
calendarCanary: "SURFSENSE_E2E_CANARY_TOKEN_CALENDAR_001",
onedriveCanary: "SURFSENSE_E2E_CANARY_TOKEN_ONEDRIVE_001",
notionCanary: "SURFSENSE_E2E_CANARY_TOKEN_NOTION_001",
confluenceCanary: "SURFSENSE_E2E_CANARY_TOKEN_CONFLUENCE_001",
linearCanary: "SURFSENSE_E2E_CANARY_TOKEN_LINEAR_001",
@ -50,6 +51,18 @@ export const FAKE_DRIVE_FOLDERS = {
},
} as const;
/**
* Fake OneDrive file IDs that match the Microsoft Graph-shaped backend
* fake in onedrive_files.json.
*/
export const FAKE_ONEDRIVE_FILES = {
canary: {
id: "fake-onedrive-canary",
name: "e2e-onedrive-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.