test: cover unavailable public states

This commit is contained in:
ik
2026-09-21 08:12:04 +07:00
parent c84ec1eced
commit c5f9aa85a0
3 changed files with 27 additions and 1 deletions
+5
View File
@@ -9,6 +9,11 @@ const requested = Astro.url.searchParams.get("type") ?? "fish";
const type = allowed.has(requested) ? requested : "fish";
let assets: MediaAsset[] = [], unavailable = false;
try { assets = await api<MediaAsset[]>(`/api/v1/media/catalog?entity_type=${type}`); } catch { unavailable = true; }
if (unavailable) {
Astro.response.status = 503;
Astro.response.headers.set("Retry-After", "60");
Astro.response.headers.set("Cache-Control", "no-store");
}
const labels: Record<string,string> = {fish:"Рыбы",waterbody:"Водоёмы",tackle:"Снасти и приманки",reference:"Справочные материалы"};
---
<Layout title={`${labels[type]} RF4 — медиатека RF4 Spotter`} description="Изображения рыб, водоёмов и снастей Russian Fishing 4 с обязательной атрибуцией каждого источника.">
+21
View File
@@ -0,0 +1,21 @@
import { expect, test } from "@playwright/test";
for (const path of [
"/waterbodies",
"/waterbodies/vyunok",
"/waterbodies/vyunok/pike",
"/fish",
"/media?type=waterbody",
"/tackle",
"/tackle/analytics",
"/tackle/items/00000000-0000-0000-0000-000000000000",
]) {
test(`${path} exposes a cache-safe unavailable state`, async ({ page }) => {
const response = await page.goto(path);
expect(response?.status(), `${path} status`).toBe(503);
expect(response?.headers()["retry-after"], `${path} retry header`).toBe("60");
expect(response?.headers()["cache-control"], `${path} cache header`).toBe("no-store");
await expect(page.getByRole("alert")).toContainText(/временно недоступ|недоступен/i);
await expect(page.locator("body")).not.toContainText(/Traceback|localhost:8000|API \d+/i);
});
}