fix(api): сохранять достоверные параметры рекурсивных маршрутов

This commit is contained in:
Denozordec committed 2026-09-30 22:08:22 +07:00
1 parent 50fad3ac80
commit 54ef752a5b
17 files changed
+198 -45

No files matched your search

+11 -11
View File
@@ -20,8 +20,8 @@ for (const result of ["success", "http", "false", "missing", "foreign", "count"]
saved = body.routes; return r.fulfill({ json: { ok: true, serverId: 1, routes: saved, pushedRoutes: saved.length } })
}
return r.fulfill({ json: p === "/api/servers" ? servers : p === "/api/auth/config" ? { required: false }
: p === "/api/recursive-routes" ? { serverId: Number(u.searchParams.get("serverId")), routes: saved, live: true, stale: false }
: p === "/api/recursive-routes/gateways" ? { serverId: Number(u.searchParams.get("serverId")), gateways: [] } : {} })
: p === "/api/recursive-routes/catalog" ? { serverId: Number(u.searchParams.get("serverId")), routes: saved, live: true, stale: false }
: p === "/api/recursive-routes/gateways/catalog" ? { serverId: Number(u.searchParams.get("serverId")), gateways: [] } : {} })
})
await page.goto("/recursive-routes")
await expect(page.locator("tr[data-row-id]")).toHaveCount(1)
@@ -53,13 +53,13 @@ for (const bad of ["http", "foreign", "payload", "duplicate", "stale"] as const)
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", r => {
const p = new URL(r.request().url()).pathname
if (p === "/api/recursive-routes") {
if (p === "/api/recursive-routes/catalog") {
if (phase !== 1 && bad === "http") return r.fulfill({ status: 503, json: { error: "Чтение недоступно тест" } })
const valid = { serverId: 1, routes: phase === 0 ? [] : [routeRow()], live: true, stale: false }
return r.fulfill({ json: phase === 1 ? valid : bad === "foreign" ? { ...valid, serverId: 2 } : bad === "payload" ? { ...valid, routes: [{}] }
: bad === "duplicate" ? { ...valid, routes: [routeRow(), routeRow()] } : { ...valid, live: false, stale: true, error: "Кэш тест" } })
}
return r.fulfill({ json: p === "/api/servers" ? [servers[0]] : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes/gateways" ? { serverId: 1, gateways: [] } : {} })
return r.fulfill({ json: p === "/api/servers" ? [servers[0]] : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes/gateways/catalog" ? { serverId: 1, gateways: [] } : {} })
})
await page.goto("/recursive-routes")
await expect(page.getByRole("button", { name: "Добавить", exact: true })).toBeDisabled()
@@ -77,9 +77,9 @@ test("Рекурсивные маршруты: чтение прежнего у
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", async r => {
const u = new URL(r.request().url()), p = u.pathname, id = Number(u.searchParams.get("serverId"))
if (p === "/api/recursive-routes") { if (id === 1) { requested = true; await gate }
if (p === "/api/recursive-routes/catalog") { if (id === 1) { requested = true; await gate }
return r.fulfill({ json: { serverId: id, routes: [routeRow("r" + id, "10.0." + id + ".0/24")], live: true, stale: false } }) }
return r.fulfill({ json: p === "/api/servers" ? servers : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes/gateways" ? { serverId: id, gateways: [] } : {} })
return r.fulfill({ json: p === "/api/servers" ? servers : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes/gateways/catalog" ? { serverId: id, gateways: [] } : {} })
})
await page.goto("/recursive-routes"); await expect.poll(() => requested).toBe(true)
await page.getByRole("option").filter({ hasText: "Роутер 2" }).click()
@@ -88,12 +88,12 @@ test("Рекурсивные маршруты: чтение прежнего у
await expect(page.locator("tr[data-row-id]")).not.toContainText("10.0.1.0/24")
})
test("Рекурсивные маршруты: редактирование поиска сохраняет скрытые endpoints и таблицы", async ({ page }) => {
let saved: unknown; const rows = [{ ...routeRow(), gateway: "192.0.2.11" }, { ...routeRow("b"), gateway: "192.0.2.22" }, { ...routeRow("c", "10.0.1.0/24", "vpn"), gateway: "192.0.2.33" }]
let saved: unknown; const rows = [{ ...routeRow(), gateway: "192.0.2.11" }, { ...routeRow("b"), gateway: "192.0.2.22", disabled: true }, { ...routeRow("c", "10.0.1.0/24", "vpn"), gateway: "192.0.2.33" }]
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
await page.route("**/api/**", r => {
const p = new URL(r.request().url()).pathname
if (p === "/api/recursive-routes" && r.request().method() === "PUT") { const next = r.request().postDataJSON().routes; saved = next; return r.fulfill({ json: { ok: true, serverId: 1, routes: next, pushedRoutes: next.length } }) }
return r.fulfill({ json: p === "/api/servers" ? [servers[0]] : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes" ? { serverId: 1, routes: rows, live: true, stale: false } : p === "/api/recursive-routes/gateways" ? { serverId: 1, gateways: [] } : {} })
return r.fulfill({ json: p === "/api/servers" ? [servers[0]] : p === "/api/auth/config" ? { required: false } : p === "/api/recursive-routes/catalog" ? { serverId: 1, routes: rows, live: true, stale: false } : p === "/api/recursive-routes/gateways/catalog" ? { serverId: 1, gateways: [] } : {} })
})
await page.goto("/recursive-routes"); await expect(page.locator("tr[data-row-id]")).toHaveCount(2)
await page.getByRole("textbox", { name: "Поиск маршрутов" }).fill("192.0.2.11")
@@ -102,7 +102,7 @@ test("Рекурсивные маршруты: редактирование по
const sheet = page.getByRole("dialog")
await expect(sheet.getByPlaceholder("1.2.3.4%GW-NAME")).toHaveCount(2)
await sheet.getByRole("button", { name: "Сохранить", exact: true }).click(); await expect(sheet).toHaveCount(0)
expect(saved).toEqual(expect.arrayContaining([expect.objectContaining({ routingTable: "main", gateway: "192.0.2.11" }), expect.objectContaining({ routingTable: "main", gateway: "192.0.2.22" }), expect.objectContaining({ routingTable: "vpn", gateway: "192.0.2.33" })]))
expect(saved).toEqual(expect.arrayContaining([expect.objectContaining({ routingTable: "main", gateway: "192.0.2.11" }), expect.objectContaining({ routingTable: "main", gateway: "192.0.2.22", disabled: true }), expect.objectContaining({ routingTable: "vpn", gateway: "192.0.2.33" })]))
expect(saved).toHaveLength(3)
})
@@ -116,8 +116,8 @@ for (const allowed of [false, true]) test("Рекурсивные маршрут
const p = new URL(r.request().url()).pathname
if (r.request().method() !== "GET") writes++
return r.fulfill({ json: p === "/api/auth/config" ? { required: true } : p === "/api/servers" ? [{ ...servers[0], enabled: !allowed }]
: p === "/api/recursive-routes" ? { serverId: 1, routes: [routeRow()], live: true, stale: false }
: p === "/api/recursive-routes/gateways" ? { serverId: 1, gateways: [] }
: p === "/api/recursive-routes/catalog" ? { serverId: 1, routes: [routeRow()], live: true, stale: false }
: p === "/api/recursive-routes/gateways/catalog" ? { serverId: 1, gateways: [] }
: p.endsWith("/revisions") ? { revisions: [{ id: "rev", serverId: "1", section: "recursive-routes", source: "apply", fingerprint: "fixture", createdAt: "2026-09-30T00:00:00Z", note: null, itemCount: 1 }] } : {} })
})
await page.goto("/recursive-routes"); await expect(page.locator("tr[data-row-id]")).toHaveCount(1)