mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-12 09:12:40 +02:00
test(web): add Jira OAuth fixture
This commit is contained in:
parent
ebdf6cbaed
commit
ddfbe0b611
3 changed files with 86 additions and 0 deletions
|
|
@ -442,3 +442,53 @@ export async function runLinearOAuth(
|
|||
|
||||
return { authUrl: auth_url, finalUrl: location, connector };
|
||||
}
|
||||
|
||||
/**
|
||||
* Drives the Jira MCP OAuth flow programmatically.
|
||||
*
|
||||
* The E2E backend keeps SurfSense's generic MCP OAuth routes real and
|
||||
* patches Jira's external discovery/DCR/token/MCP tool boundaries.
|
||||
*/
|
||||
export async function runJiraOAuth(
|
||||
request: APIRequestContext,
|
||||
token: string,
|
||||
searchSpaceId: number
|
||||
): Promise<{
|
||||
authUrl: string;
|
||||
finalUrl: string;
|
||||
connector: ConnectorRow | null;
|
||||
}> {
|
||||
const initiateResp = await request.get(
|
||||
`${BACKEND_URL}/api/v1/auth/mcp/jira/connector/add?space_id=${searchSpaceId}`,
|
||||
{ headers: authHeaders(token) }
|
||||
);
|
||||
if (!initiateResp.ok()) {
|
||||
throw new Error(
|
||||
`Jira MCP initiate failed (${initiateResp.status()}): ${await initiateResp.text()}`
|
||||
);
|
||||
}
|
||||
const { auth_url } = (await initiateResp.json()) as { auth_url: string };
|
||||
if (!auth_url) {
|
||||
throw new Error("Jira MCP initiate response missing auth_url");
|
||||
}
|
||||
|
||||
const state = new URL(auth_url).searchParams.get("state");
|
||||
if (!state) {
|
||||
throw new Error(`Jira MCP auth_url missing state: ${auth_url}`);
|
||||
}
|
||||
|
||||
const callbackResp = await request.get(
|
||||
`${BACKEND_URL}/api/v1/auth/mcp/jira/connector/callback?code=fake-jira-oauth-code&state=${encodeURIComponent(state)}`,
|
||||
{
|
||||
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 === "JIRA_CONNECTOR") ?? null;
|
||||
|
||||
return { authUrl: auth_url, finalUrl: location, connector };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue