test(web): add native Google Gmail live-tool journey

This commit is contained in:
Anish Sarkar 2026-05-07 04:23:20 +05:30
parent a5c04cb38d
commit 9dafd38e19
5 changed files with 183 additions and 1 deletions

View file

@ -126,6 +126,31 @@ export async function triggerIndex(
return { ok: true };
}
export async function triggerIndexExpectDisabled(
request: APIRequestContext,
token: string,
connectorId: number,
searchSpaceId: number,
body: IndexBody = {}
): Promise<{ indexing_started: false; message?: string }> {
const response = await request.post(
`${BACKEND_URL}/api/v1/search-source-connectors/${connectorId}/index?search_space_id=${searchSpaceId}`,
{ headers: authHeaders(token), data: body }
);
if (!response.ok()) {
throw new Error(
`triggerIndexExpectDisabled(${connectorId}) failed (${response.status()}): ${await response.text()}`
);
}
const payload = (await response.json()) as { indexing_started?: boolean; message?: string };
if (payload.indexing_started !== false) {
throw new Error(
`triggerIndexExpectDisabled(${connectorId}) expected indexing_started=false, got ${JSON.stringify(payload)}`
);
}
return { indexing_started: false, message: payload.message };
}
/**
* Drives the OAuth flow for a Composio toolkit programmatically.
*
@ -230,3 +255,45 @@ export async function runNativeGoogleDriveOAuth(
return { authUrl: auth_url, finalUrl: location, connector };
}
/**
* Drives the native Google Gmail 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 runNativeGoogleGmailOAuth(
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/gmail/connector/add?space_id=${searchSpaceId}`,
{ headers: authHeaders(token) }
);
if (!initiateResp.ok()) {
throw new Error(
`native Google Gmail 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 Gmail 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_GMAIL_CONNECTOR") ?? null;
return { authUrl: auth_url, finalUrl: location, connector };
}