test(web): add native Google Drive E2E journey

This commit is contained in:
Anish Sarkar 2026-05-07 03:59:58 +05:30
parent 3f2912a4ca
commit 92dd967bf1
4 changed files with 194 additions and 0 deletions

View file

@ -188,3 +188,45 @@ export async function runComposioOAuth(
return { authUrl: auth_url, finalUrl: location, connector };
}
/**
* Drives the native Google Drive OAuth flow programmatically.
*
* The E2E backend patches Google OAuth so the returned auth_url points
* straight back to the backend callback with a deterministic code/state.
*/
export async function runNativeGoogleDriveOAuth(
request: APIRequestContext,
token: string,
searchSpaceId: number
): Promise<{
authUrl: string;
finalUrl: string;
connector: ConnectorRow | null;
}> {
const initiateResp = await request.get(
`${BACKEND_URL}/api/v1/auth/google/drive/connector/add?space_id=${searchSpaceId}`,
{ headers: authHeaders(token) }
);
if (!initiateResp.ok()) {
throw new Error(
`native Google Drive initiate failed (${initiateResp.status()}): ${await initiateResp.text()}`
);
}
const { auth_url } = (await initiateResp.json()) as { auth_url: string };
if (!auth_url) {
throw new Error("native Google Drive initiate response missing auth_url");
}
const callbackResp = await request.get(auth_url, {
headers: authHeaders(token),
maxRedirects: 0,
failOnStatusCode: false,
});
const location = callbackResp.headers().location ?? auth_url;
const connectors = await listConnectors(request, token, searchSpaceId);
const connector = connectors.find((c) => c.connector_type === "GOOGLE_DRIVE_CONNECTOR") ?? null;
return { authUrl: auth_url, finalUrl: location, connector };
}