feat: delete ticker from database when removed from portfolio

- Add DELETE support to /api/stocks endpoint via _method parameter
- Modify removeStock to delete db- prefixed entries from database
- Add confirmation dialog on delete button click
- Add test for stock deletion
This commit is contained in:
2026-05-14 10:29:27 +02:00
parent 3340fd11ca
commit 043c3d5afe
4 changed files with 62 additions and 23 deletions
+25 -16
View File
@@ -1,31 +1,40 @@
import { test, expect } from "@playwright/test";
test.describe("Stock Database", () => {
test("should add and list stocks", async ({ request }) => {
test("should add and list stocks", async ({ page }) => {
const uniqueTicker = `TEST${Date.now()}`;
const createRes = await request.post("/api/stocks", {
form: { ticker: uniqueTicker },
const createRes = await page.request.post("/api/stocks", {
data: new URLSearchParams({ ticker: uniqueTicker }).toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
expect(createRes.ok()).toBeTruthy();
const listRes = await request.get("/api/stocks");
const listRes = await page.request.get("/api/stocks");
const stocks = await listRes.json();
expect(stocks).toContainEqual(expect.objectContaining({ ticker: uniqueTicker }));
});
test("should persist tickers after page reload", async ({ request, page }) => {
const uniqueTicker = `PERSIST${Date.now()}`;
await request.post("/api/stocks", {
form: { ticker: uniqueTicker },
test("should delete stock from database", async ({ page }) => {
const uniqueTicker = `DEL${Date.now()}`;
await page.request.post("/api/stocks", {
data: new URLSearchParams({ ticker: uniqueTicker }).toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
await page.goto("/stocks");
await page.waitForLoadState("networkidle");
const listRes = await request.get("/api/stocks");
const stocks = await listRes.json();
let listRes = await page.request.get("/api/stocks");
let stocks = await listRes.json();
expect(stocks).toContainEqual(expect.objectContaining({ ticker: uniqueTicker }));
const delRes = await page.request.post("/api/stocks", {
data: new URLSearchParams({ ticker: uniqueTicker, _method: "DELETE" }).toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
expect(delRes.ok()).toBeTruthy();
listRes = await page.request.get("/api/stocks");
stocks = await listRes.json();
expect(stocks).not.toContainEqual(expect.objectContaining({ ticker: uniqueTicker }));
});
});