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:
@@ -52,3 +52,51 @@ async def test_delete_edge(client: AsyncClient, headers: dict, two_nodes):
|
||||
res = await client.delete(f"/api/v1/edges/{edge_id}", headers=headers)
|
||||
assert res.status_code == 204
|
||||
assert len((await client.get("/api/v1/edges", headers=headers)).json()) == 0
|
||||
|
||||
|
||||
async def test_delete_edge_not_found(client: AsyncClient, headers: dict):
|
||||
res = await client.delete("/api/v1/edges/nonexistent", headers=headers)
|
||||
assert res.status_code == 404
|
||||
|
||||
|
||||
async def test_update_edge(client: AsyncClient, headers: dict, two_nodes):
|
||||
src, tgt = two_nodes
|
||||
edge_id = (await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)).json()["id"]
|
||||
res = await client.patch(f"/api/v1/edges/{edge_id}", json={"type": "wifi", "label": "uplink"}, headers=headers)
|
||||
assert res.status_code == 200
|
||||
assert res.json()["type"] == "wifi"
|
||||
assert res.json()["label"] == "uplink"
|
||||
|
||||
|
||||
async def test_update_edge_not_found(client: AsyncClient, headers: dict):
|
||||
res = await client.patch("/api/v1/edges/nonexistent", json={"type": "wifi"}, headers=headers)
|
||||
assert res.status_code == 404
|
||||
|
||||
|
||||
async def test_create_edge_with_custom_color(client: AsyncClient, headers: dict, two_nodes):
|
||||
src, tgt = two_nodes
|
||||
res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet", "custom_color": "#a855f7"}, headers=headers)
|
||||
assert res.status_code == 201
|
||||
assert res.json()["custom_color"] == "#a855f7"
|
||||
|
||||
|
||||
async def test_create_edge_with_path_style(client: AsyncClient, headers: dict, two_nodes):
|
||||
src, tgt = two_nodes
|
||||
res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet", "path_style": "smooth"}, headers=headers)
|
||||
assert res.status_code == 201
|
||||
assert res.json()["path_style"] == "smooth"
|
||||
|
||||
|
||||
async def test_update_edge_custom_color_and_path_style(client: AsyncClient, headers: dict, two_nodes):
|
||||
src, tgt = two_nodes
|
||||
edge_id = (await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"}, headers=headers)).json()["id"]
|
||||
res = await client.patch(f"/api/v1/edges/{edge_id}", json={"custom_color": "#39d353", "path_style": "smooth"}, headers=headers)
|
||||
assert res.status_code == 200
|
||||
assert res.json()["custom_color"] == "#39d353"
|
||||
assert res.json()["path_style"] == "smooth"
|
||||
|
||||
|
||||
async def test_create_edge_requires_auth(client: AsyncClient, two_nodes):
|
||||
src, tgt = two_nodes
|
||||
res = await client.post("/api/v1/edges", json={"source": src, "target": tgt, "type": "ethernet"})
|
||||
assert res.status_code == 403
|
||||
|
||||
Reference in New Issue
Block a user