Skip to content

Commit 745e3ec

Browse files
committed
fix: add ON DELETE CASCADE to user_id reference in carts table and update secure cookie setting based on environment
1 parent 1633e7f commit 745e3ec

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/db/migrations/initial.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS products (
3636
CREATE TABLE IF NOT EXISTS carts (
3737
id SERIAL PRIMARY KEY,
3838
session_cart_id UUID UNIQUE DEFAULT gen_random_uuid(),
39-
user_id INTEGER REFERENCES users(id),
39+
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
4040
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
4141
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
4242
);

src/e2e/demo.signin.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
import { test, expect } from "@playwright/test";
22

3+
import { hashPassword } from "@/lib/security";
4+
import type { CreateUserDTO } from "@/models/user.model";
5+
import {
6+
createUser,
7+
deleteUser,
8+
getUserByEmail,
9+
} from "@/repositories/user.repository";
10+
311
test.describe("Visitante inicio sesion", () => {
12+
let testUserId: number;
13+
14+
test.beforeAll(async () => {
15+
const testUser: CreateUserDTO = {
16+
17+
name: null,
18+
password: await hashPassword("letmein"),
19+
isGuest: false,
20+
};
21+
22+
const existingUser = await getUserByEmail(testUser.email);
23+
24+
if (existingUser) {
25+
await deleteUser(existingUser.id);
26+
}
27+
28+
const user = await createUser(testUser);
29+
testUserId = user.id;
30+
});
31+
32+
test.afterAll(async () => {
33+
await deleteUser(testUserId);
34+
});
35+
436
test("test", async ({ page }) => {
537
await page.goto("http://localhost:5173/");
638
await page.getByTestId("login").click();

src/session.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const { getSession, commitSession, destroySession } =
2727
path: "/",
2828
sameSite: "lax",
2929
secrets: ["s3cret1"],
30-
secure: true,
30+
secure: process.env.NODE_ENV === "production", // true en producción, false en desarrollo
3131
},
3232
});
3333

0 commit comments

Comments
 (0)