fix(api): accept academic-year codes in rankings year filter #7

Merged
tudor merged 1 commits from fix/rankings-year-validation into main 2026-07-05 10:46:04 +00:00
2 changed files with 22 additions and 1 deletions
Showing only changes of commit 6c872ce726 - Show all commits
+4 -1
View File
@@ -834,7 +834,10 @@ async def get_rankings(
request: Request,
metric: str = Query("rwm_expected_pct", description="Metric to rank by", max_length=50),
year: Optional[int] = Query(
None, description="Specific year (defaults to most recent)", ge=2000, le=2100
None,
description="Academic year code, e.g. 201819 (defaults to most recent)",
ge=2000,
le=210100,
),
limit: int = Query(20, ge=1, le=100, description="Number of schools to return"),
local_authority: Optional[str] = Query(
+18
View File
@@ -73,3 +73,21 @@ test('rankings page loads a populated table', async ({ page }) => {
await expect(rows.first()).toBeVisible({ timeout: 15_000 });
expect(await rows.count()).toBeGreaterThan(5);
});
test('rankings stay populated after picking a specific year', async ({ page }) => {
// Years are academic-year codes (e.g. 201819); the API must accept them
// as the `year` query param rather than rejecting with a 422.
await page.goto('/rankings');
const yearSelect = page.locator('#year-select');
await expect(yearSelect).toBeVisible({ timeout: 15_000 });
// Pick the first explicit year option (index 0 is the "Latest" default).
const yearValue = await yearSelect.locator('option').nth(1).getAttribute('value');
expect(yearValue).toBeTruthy();
await yearSelect.selectOption(yearValue!);
await page.waitForURL(/year=/);
const rows = page.locator('table tbody tr');
await expect(rows.first()).toBeVisible({ timeout: 15_000 });
expect(await rows.count()).toBeGreaterThan(5);
});