87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
|
|
test.describe("Social Login Flow", () => {
|
|
test("login page renders with social buttons", async ({ page }) => {
|
|
await page.goto("/");
|
|
|
|
// Should see the app title
|
|
await expect(page.locator("h1")).toContainText("pp-mono");
|
|
|
|
// Should see both social login buttons
|
|
const githubBtn = page.locator("#btn-github");
|
|
const googleBtn = page.locator("#btn-google");
|
|
|
|
await expect(githubBtn).toBeVisible();
|
|
await expect(googleBtn).toBeVisible();
|
|
|
|
await expect(githubBtn).toContainText("Sign in with GitHub");
|
|
await expect(googleBtn).toContainText("Sign in with Google");
|
|
});
|
|
|
|
test("GitHub button redirects to OAuth flow", async ({ page }) => {
|
|
// Intercept the Auth.js signin route to avoid hitting real GitHub
|
|
await page.route("**/api/auth/signin/github", (route) => {
|
|
// Auth.js would normally redirect to GitHub.
|
|
// We verify the request reaches our server.
|
|
route.fulfill({
|
|
status: 302,
|
|
headers: { Location: "https://github.com/login/oauth/authorize?mock=true" },
|
|
});
|
|
});
|
|
|
|
await page.goto("/");
|
|
const githubBtn = page.locator("#btn-github");
|
|
|
|
// Intercept navigation to GitHub
|
|
const [response] = await Promise.all([
|
|
page.waitForResponse((r) => r.url().includes("/api/auth/signin/github")),
|
|
githubBtn.click(),
|
|
]);
|
|
|
|
expect(response.status()).toBe(302);
|
|
});
|
|
|
|
test("Google button redirects to OAuth flow", async ({ page }) => {
|
|
await page.route("**/api/auth/signin/google", (route) => {
|
|
route.fulfill({
|
|
status: 302,
|
|
headers: { Location: "https://accounts.google.com/o/oauth2/auth?mock=true" },
|
|
});
|
|
});
|
|
|
|
await page.goto("/");
|
|
const googleBtn = page.locator("#btn-google");
|
|
|
|
const [response] = await Promise.all([
|
|
page.waitForResponse((r) => r.url().includes("/api/auth/signin/google")),
|
|
googleBtn.click(),
|
|
]);
|
|
|
|
expect(response.status()).toBe(302);
|
|
});
|
|
|
|
test("authenticated user sees dashboard", async ({ page }) => {
|
|
// Mock the session endpoint to simulate a logged-in user
|
|
await page.route("**/api/auth/session", (route) => {
|
|
route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({
|
|
user: {
|
|
name: "Test User",
|
|
email: "test@example.com",
|
|
image: "https://via.placeholder.com/80",
|
|
},
|
|
expires: new Date(Date.now() + 86400000).toISOString(),
|
|
}),
|
|
});
|
|
});
|
|
|
|
await page.goto("/");
|
|
|
|
// Should see the dashboard instead of login
|
|
await expect(page.locator("h1")).toContainText("Welcome, Test User");
|
|
await expect(page.locator("#btn-signout")).toBeVisible();
|
|
});
|
|
});
|