mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
Make tests pass
This commit is contained in:
parent
91242b73bf
commit
4ced6744fa
|
|
@ -12,7 +12,9 @@ export default async (
|
||||||
req: Request,
|
req: Request,
|
||||||
matchedRoute: MatchedRoute
|
matchedRoute: MatchedRoute
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
const scopes = matchedRoute.query.scopes.replaceAll("+", " ").split(" ");
|
const scopes = (matchedRoute.query.scopes || "")
|
||||||
|
.replaceAll("+", " ")
|
||||||
|
.split(" ");
|
||||||
const redirect_uri = matchedRoute.query.redirect_uri;
|
const redirect_uri = matchedRoute.query.redirect_uri;
|
||||||
const response_type = matchedRoute.query.response_type;
|
const response_type = matchedRoute.query.response_type;
|
||||||
const client_id = matchedRoute.query.client_id;
|
const client_id = matchedRoute.query.client_id;
|
||||||
|
|
@ -54,10 +56,5 @@ export default async (
|
||||||
await token.save();
|
await token.save();
|
||||||
|
|
||||||
// Redirect back to application
|
// Redirect back to application
|
||||||
return new Response(null, {
|
return Response.redirect(`${redirect_uri}?code=${token.code}`);
|
||||||
status: 302,
|
|
||||||
headers: {
|
|
||||||
Location: `${redirect_uri}?code=${token.code}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,11 @@ describe("POST /auth/login/", () => {
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
|
redirect: "manual",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(response.status).toBe(302);
|
expect(response.status).toBe(302);
|
||||||
expect(response.headers.get("location")).toMatch(
|
expect(response.headers.get("Location")).toMatch(
|
||||||
/https:\/\/example.com\?code=/
|
/https:\/\/example.com\?code=/
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -108,13 +108,16 @@ describe("POST /v1/oauth/token/", () => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
|
const json = await response.json();
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
expect(response.headers.get("content-type")).toBe("application/json");
|
expect(response.headers.get("content-type")).toBe("application/json");
|
||||||
expect(await response.json()).toEqual({
|
expect(json).toEqual({
|
||||||
access_token: expect.any(String),
|
access_token: expect.any(String),
|
||||||
token_type: "bearer",
|
token_type: "Bearer",
|
||||||
scope: "read write",
|
scope: "read write",
|
||||||
created_at: expect.any(Number),
|
created_at: expect.any(String),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue