mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-12 09:12:40 +02:00
test(web): add native Google Drive E2E journey
This commit is contained in:
parent
3f2912a4ca
commit
92dd967bf1
4 changed files with 194 additions and 0 deletions
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue