Add tests for Alpaca Historical Bars API
- Implemented tests for fetching historical bars for AAPL with different timeframes (1D, 5Min, 1H). - Verified response structure and data integrity for each timeframe. - Ensured that the API returns valid data and appropriate status for the requests.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
test.describe("Alpaca Historical Bars", () => {
|
||||
test("should return bars for AAPL with 1D timeframe", async ({ page }) => {
|
||||
const response = await page.request.get("/api/alpaca/quote/AAPL");
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
const data = await response.json();
|
||||
expect(data.ticker).toBe("AAPL");
|
||||
expect(data.price).toBeGreaterThan(0);
|
||||
expect(data.bars.length).toBeGreaterThan(0);
|
||||
|
||||
const bar = data.bars[0];
|
||||
expect(bar.t).toBeDefined();
|
||||
expect(bar.o).toBeGreaterThan(0);
|
||||
expect(bar.h).toBeGreaterThan(0);
|
||||
expect(bar.l).toBeGreaterThan(0);
|
||||
expect(bar.c).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("should return bars for AAPL with 5Min timeframe", async ({ page }) => {
|
||||
const response = await page.request.get("/api/alpaca/quote/AAPL?timeframe=5Min&limit=5");
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
const data = await response.json();
|
||||
expect(data.ticker).toBe("AAPL");
|
||||
expect(data.bars.length).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
test("should return bars for AAPL with 1H timeframe", async ({ page }) => {
|
||||
const response = await page.request.get("/api/alpaca/quote/AAPL?timeframe=1H&limit=10");
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
const data = await response.json();
|
||||
expect(data.ticker).toBe("AAPL");
|
||||
expect(data.bars.length).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user