Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .env

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dist-ssr
.react-router/

.build/
.env

# Playwright
/test-results/
Expand Down
2 changes: 1 addition & 1 deletion src/db/migrations/initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS cart_items (

CREATE TABLE IF NOT EXISTS orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
total_amount NUMERIC(10,2) NOT NULL,

-- Customer and shipping details
Expand Down
93 changes: 93 additions & 0 deletions src/e2e/user-create-order.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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("User", () => {
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("User can create an order", async ({ page }) => {
await page.goto("http://localhost:5173/");

await page.getByRole("link", { name: "Iniciar sesión" }).click();

const loginForm = {
"Correo electrónico": "diego@codeable.com",
Contraseña: "letmein",
};

for (const [key, value] of Object.entries(loginForm)) {
const input = await page.getByRole("textbox", { name: key });
await input.click();
await input.fill(value);
}

await page.getByRole("button", { name: "Iniciar sesión" }).click();

// Wait for the user to be logged in
await expect(
page.getByRole("button", { name: "Cerrar sesión" })
).toBeVisible();

await page.getByRole("menuitem", { name: "Polos" }).click();
await page.getByTestId("product-item").first().click();

await page.getByRole("button", { name: "Agregar al Carrito" }).click();
await page.getByRole("link", { name: "Carrito de compras" }).click();

await page.getByRole("link", { name: "Continuar Compra" }).click();

const orderForm = {
Nombre: "Testino",
Apellido: "Diprueba",
Compañia: "",
Dirección: "Calle De Prueba 123",
Ciudad: "Lima",
"Provincia/Estado": "Lima",
"Código Postal": "51111",
Teléfono: "987456321",
};

for (const [key, value] of Object.entries(orderForm)) {
const input = await page.getByRole("textbox", { name: key });
await input.click();
await input.fill(value);
}

await page.getByRole("combobox", { name: "País" }).selectOption("PE");

await page.getByRole("button", { name: "Confirmar Orden" }).click();

await expect(
page.getByText("¡Muchas gracias por tu compra!")
).toBeVisible();
await expect(page.getByTestId("orderId")).toBeVisible();
});
});
7 changes: 6 additions & 1 deletion src/routes/order-confirmation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export default function OrderConfirmation({
Llegaremos a la puerta de tu domicilio lo antes posible
</p>
<p className="text-sm font-medium mb-2">Código de seguimiento</p>
<p className="text-sm font-medium text-accent-foreground">{orderId}</p>
<p
data-testid="orderId"
className="text-sm font-medium text-accent-foreground"
>
{orderId}
</p>
</Container>
</section>
);
Expand Down