feat: toolbar actions

This commit is contained in:
dextmorgn
2025-05-12 08:19:54 +02:00
parent 9251762be6
commit e3d3824883
33 changed files with 786 additions and 377 deletions

View File

View File

@@ -0,0 +1,27 @@
from fastapi.testclient import TestClient
from unittest.mock import patch, MagicMock
from app.main import app
client = TestClient(app)
def test_add_edge_success():
sketch_id = "sketch-123"
edge_input = {
"from_node": {"uuid": "node-1"},
"to_node": {"uuid": "node-2"},
"type": "HAS_SUBDOMAIN"
}
mock_result = [{"r": {"type": "HAS_SUBDOMAIN", "sketch_id": sketch_id}}]
with patch("main.neo4j_connection.query", return_value=mock_result) as mock_query:
response = client.post(f"/sketch/{sketch_id}/edges/add", json=edge_input)
assert response.status_code == 200
assert response.json()["status"] == "edge added"
assert response.json()["edge"]["sketch_id"] == sketch_id
expected_query_part = "MERGE (a)-[r:`HAS_SUBDOMAIN`"
args, kwargs = mock_query.call_args
assert expected_query_part in args[0]
assert kwargs is None or kwargs.get("sketch_id") == sketch_id

View File

@@ -0,0 +1,44 @@
from fastapi.testclient import TestClient
from unittest.mock import patch
from app.main import app
client = TestClient(app)
def test_add_node_success():
sketch_id = "sketch-abc"
node_payload = {
"type": "Domain",
"data": {
"label": "example.com",
"color": "#ff0000",
"ip": "1.2.3.4"
}
}
# Mock de la réponse Neo4j attendue
mock_result = [{
"node": {
"uuid": "node-uuid-123",
"type": "Domain",
"label": "example.com",
"color": "#ff0000",
"ip": "1.2.3.4",
"caption": "example.com",
"size": 40,
"sketch_id": sketch_id,
}
}]
with patch("main.neo4j_connection.query", return_value=mock_result) as mock_query:
response = client.post(f"/sketch/{sketch_id}/nodes/add", json=node_payload)
assert response.status_code == 200
json_data = response.json()
assert json_data["status"] == "node added"
assert json_data["node"]["label"] == "example.com"
assert json_data["node"]["data"] == node_payload["data"]
# Vérifie qu'on a bien appelé Neo4j avec une requête contenant MERGE et le bon type
args, kwargs = mock_query.call_args
assert f"MERGE (d:`{node_payload['type']}`" in args[0]
assert kwargs is None or kwargs.get("sketch_id") == sketch_id