test: improve coverage across frontend and backend
Frontend (22 → 37 tests): - canvasStore: add tests for onNodesChange, onEdgesChange, onConnect, addNode with parentId, updateEdge, deleteEdge, setProxmoxContainerMode ON/OFF, loadCanvas parent-before-child ordering - edgeColors: 6 tests for EDGE_DEFAULT_COLORS (all types, hex format, values) Backend (40 → 80 tests): - test_canvas (new): load empty canvas, default viewport, save creates/updates/ deletes nodes+edges, viewport upsert, custom_colors, edge custom_color+path_style, auth guard - test_fingerprint (new): match_port (known, unknown, wrong protocol, banner match, banner no-match, no banner), fingerprint_ports (matched, unknown, mixed, empty, default protocol), suggest_node_type (proxmox, server, generic, priority) - test_nodes: update/delete 404, custom_colors CRUD, container_mode CRUD, auth guard - test_edges: update edge, update/delete 404, custom_color, path_style, auth guard
This commit is contained in:
@@ -65,3 +65,48 @@ async def test_list_nodes_returns_all(client: AsyncClient, headers: dict):
|
||||
await client.post("/api/v1/nodes", json={"type": "generic", "label": f"Node {i}", "status": "unknown"}, headers=headers)
|
||||
res = await client.get("/api/v1/nodes", headers=headers)
|
||||
assert len(res.json()) == 3
|
||||
|
||||
|
||||
async def test_update_node_not_found(client: AsyncClient, headers: dict):
|
||||
res = await client.patch("/api/v1/nodes/nonexistent", json={"label": "X"}, headers=headers)
|
||||
assert res.status_code == 404
|
||||
|
||||
|
||||
async def test_delete_node_not_found(client: AsyncClient, headers: dict):
|
||||
res = await client.delete("/api/v1/nodes/nonexistent", headers=headers)
|
||||
assert res.status_code == 404
|
||||
|
||||
|
||||
async def test_create_node_with_custom_colors(client: AsyncClient, headers: dict):
|
||||
payload = {"type": "server", "label": "Styled", "status": "unknown", "custom_colors": {"border": "#ff0000", "background": "#001122", "icon": "#ffffff"}}
|
||||
res = await client.post("/api/v1/nodes", json=payload, headers=headers)
|
||||
assert res.status_code == 201
|
||||
assert res.json()["custom_colors"] == {"border": "#ff0000", "background": "#001122", "icon": "#ffffff"}
|
||||
|
||||
|
||||
async def test_update_node_custom_colors(client: AsyncClient, headers: dict):
|
||||
create = await client.post("/api/v1/nodes", json={"type": "server", "label": "N", "status": "unknown"}, headers=headers)
|
||||
node_id = create.json()["id"]
|
||||
res = await client.patch(f"/api/v1/nodes/{node_id}", json={"custom_colors": {"border": "#a855f7"}}, headers=headers)
|
||||
assert res.status_code == 200
|
||||
assert res.json()["custom_colors"] == {"border": "#a855f7"}
|
||||
|
||||
|
||||
async def test_create_proxmox_node_with_container_mode(client: AsyncClient, headers: dict):
|
||||
payload = {"type": "proxmox", "label": "PVE", "status": "unknown", "container_mode": True}
|
||||
res = await client.post("/api/v1/nodes", json=payload, headers=headers)
|
||||
assert res.status_code == 201
|
||||
assert res.json()["container_mode"] is True
|
||||
|
||||
|
||||
async def test_update_node_container_mode(client: AsyncClient, headers: dict):
|
||||
create = await client.post("/api/v1/nodes", json={"type": "proxmox", "label": "PVE", "status": "unknown"}, headers=headers)
|
||||
node_id = create.json()["id"]
|
||||
res = await client.patch(f"/api/v1/nodes/{node_id}", json={"container_mode": True}, headers=headers)
|
||||
assert res.status_code == 200
|
||||
assert res.json()["container_mode"] is True
|
||||
|
||||
|
||||
async def test_create_node_requires_auth(client: AsyncClient):
|
||||
res = await client.post("/api/v1/nodes", json={"type": "server", "label": "N", "status": "unknown"})
|
||||
assert res.status_code == 403
|
||||
|
||||
Reference in New Issue
Block a user