diff --git a/src/db/migrations/initial.sql b/src/db/migrations/initial.sql index 11ad170..2d2bc31 100644 --- a/src/db/migrations/initial.sql +++ b/src/db/migrations/initial.sql @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS products ( CREATE TABLE IF NOT EXISTS carts ( id SERIAL PRIMARY KEY, session_cart_id UUID UNIQUE DEFAULT gen_random_uuid(), - user_id INTEGER REFERENCES users(id), + user_id INTEGER REFERENCES users(id) ON DELETE CASCADE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); diff --git a/src/e2e/demo.signin.spec.ts b/src/e2e/demo.signin.spec.ts new file mode 100644 index 0000000..fd643d7 --- /dev/null +++ b/src/e2e/demo.signin.spec.ts @@ -0,0 +1,51 @@ +import { test, expect } from "@playwright/test"; + +import { hashPassword } from "@/lib/security"; +import type { CreateUserDTO } from "@/models/user.model"; +import { + createUser, + deleteUser, + getUserByEmail, +} from "@/repositories/user.repository"; + +test.describe("Visitante inicio sesion", () => { + let testUserId: number; + + test.beforeAll(async () => { + const testUser: CreateUserDTO = { + email: "diego@codeable.com", + name: null, + password: await hashPassword("letmein"), + isGuest: false, + }; + + const existingUser = await getUserByEmail(testUser.email); + + if (existingUser) { + await deleteUser(existingUser.id); + } + + const user = await createUser(testUser); + testUserId = user.id; + }); + + test.afterAll(async () => { + await deleteUser(testUserId); + }); + + test("test", async ({ page }) => { + await page.goto("http://localhost:5173/"); + await page.getByTestId("login").click(); + await page.getByRole("textbox", { name: "Correo electrónico" }).click(); + await page + .getByRole("textbox", { name: "Correo electrónico" }) + .fill("diego@codeable.com"); + await page + .getByRole("textbox", { name: "Correo electrónico" }) + .press("Tab"); + await page.getByRole("textbox", { name: "Contraseña" }).fill("letmein"); + await page.getByRole("button", { name: "Iniciar sesión" }).click(); + + await expect(page.getByText("Bienvenido diego@codeable.com")).toBeVisible(); + }); +}); diff --git a/src/routes/root/components/auth-nav/index.tsx b/src/routes/root/components/auth-nav/index.tsx index 1cf10ec..1042fbb 100644 --- a/src/routes/root/components/auth-nav/index.tsx +++ b/src/routes/root/components/auth-nav/index.tsx @@ -26,6 +26,7 @@ export default function AuthNav({ user }: { user?: Omit }) { Iniciar sesión diff --git a/src/session.server.ts b/src/session.server.ts index 89a5cb2..31d3a05 100644 --- a/src/session.server.ts +++ b/src/session.server.ts @@ -27,7 +27,7 @@ const { getSession, commitSession, destroySession } = path: "/", sameSite: "lax", secrets: ["s3cret1"], - secure: true, + secure: process.env.NODE_ENV === "production", // true en producción, false en desarrollo }, });