feat : add icon and introduce login with google
This commit is contained in:
@@ -4,10 +4,15 @@ import { renderToStaticMarkup } from "react-dom/server";
|
||||
const mocks = vi.hoisted(() => ({ session: vi.fn(), userRows: vi.fn(), select: vi.fn() }));
|
||||
|
||||
vi.mock("next/navigation", () => ({ redirect: (path: string) => { throw new Error(`redirect:${path}`); } }));
|
||||
vi.mock("@/lib/auth/server", () => ({ getCustomerSession: mocks.session }));
|
||||
vi.mock("@/lib/auth/server", () => ({
|
||||
getCustomerSession: mocks.session,
|
||||
isGoogleAuthEnabled: () => Boolean(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET),
|
||||
}));
|
||||
vi.mock("@/db", () => ({ getDb: () => ({ select: mocks.select }) }));
|
||||
vi.mock("@/components/public/site-header", () => ({ SiteHeader: () => null }));
|
||||
vi.mock("./account-form", () => ({ AccountForm: () => <div>account details</div> }));
|
||||
vi.mock("./account-form", () => ({ AccountForm: ({ mode, nextPath, googleEnabled }: {
|
||||
mode: "login" | "register"; nextPath: string; googleEnabled: boolean;
|
||||
}) => <div data-mode={mode} data-next-path={nextPath} data-google-enabled={googleEnabled}>account details</div> }));
|
||||
vi.mock("./profile-form", () => ({ ProfileForm: ({ name, nextPath, setup }: {
|
||||
name: string; nextPath: string; setup: boolean;
|
||||
}) => <div data-next={nextPath} data-setup={setup}>{name}</div> }));
|
||||
@@ -17,6 +22,8 @@ const { AccountPage } = await import("./account-page");
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.stubEnv("NODE_ENV", "development");
|
||||
vi.stubEnv("GOOGLE_CLIENT_ID", "");
|
||||
vi.stubEnv("GOOGLE_CLIENT_SECRET", "");
|
||||
mocks.session.mockResolvedValue({ user: { id: "user-1", email: "[email protected]",
|
||||
emailVerified: false, role: "user" }, session: { id: "session-1" } });
|
||||
mocks.select.mockReturnValue({ from: () => ({ where: () => ({ limit: mocks.userRows }) }) });
|
||||
@@ -38,9 +45,22 @@ describe("registration profile step", () => {
|
||||
mocks.session.mockResolvedValue(null);
|
||||
const html = renderToStaticMarkup(await AccountPage({ mode: "register", setup: true, next: "/commission" }));
|
||||
expect(html).toContain("account details");
|
||||
expect(html).toContain('data-google-enabled="false"');
|
||||
expect(mocks.select).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("offers the configured Google provider on both shared account screens", async () => {
|
||||
mocks.session.mockResolvedValue(null);
|
||||
vi.stubEnv("GOOGLE_CLIENT_ID", "google-client-id");
|
||||
vi.stubEnv("GOOGLE_CLIENT_SECRET", "google-client-secret");
|
||||
for (const mode of ["login", "register"] as const) {
|
||||
const html = renderToStaticMarkup(await AccountPage({ mode, next: "/commission" }));
|
||||
expect(html).toContain(`data-mode="${mode}"`);
|
||||
expect(html).toContain('data-next-path="/commission"');
|
||||
expect(html).toContain('data-google-enabled="true"');
|
||||
}
|
||||
});
|
||||
|
||||
it("sanitizes external and unauthorized admin destinations before completing setup", async () => {
|
||||
for (const next of ["https://elsewhere.test", "/admin/guides"]) {
|
||||
const html = renderToStaticMarkup(await AccountPage({ mode: "register", setup: true, next }));
|
||||
|
||||
Reference in New Issue
Block a user