Files
AITrader/tests/stock-db.spec.ts
henry 15e49cb0f9
Run Tests / test (push) Failing after 8s
feat(tests): update Alpaca API tests to include range parameters and improve stock database cleanup
- Modified Alpaca Historical Bars tests to include range parameters in API requests.
- Updated test descriptions for clarity.
- Added cleanup step to delete test ticker after verification in stock database tests.
- Adjusted Vitest configuration to exclude test files from coverage.
2026-05-14 16:46:28 +02:00

46 lines
1.8 KiB
TypeScript

import { test, expect } from "@playwright/test";
test.describe("Stock Database", () => {
test("should add and list stocks", async ({ page }) => {
const uniqueTicker = `TEST${Date.now()}`;
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 page.request.get("/api/stocks");
const stocks = await listRes.json();
expect(stocks).toContainEqual(expect.objectContaining({ ticker: uniqueTicker }));
// Cleanup: delete the test ticker
await page.request.post("/api/stocks", {
data: new URLSearchParams({ ticker: uniqueTicker, _method: "DELETE" }).toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
});
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" },
});
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 }));
});
});