feat: make command parameter optional in set_alarm mutation

This commit is contained in:
Markus Graf
2026-05-11 15:05:29 +02:00
parent 5b5b845e41
commit ff79224560
10 changed files with 152 additions and 98 deletions
+13 -8
View File
@@ -13,6 +13,7 @@ from api.main import app # noqa: E402
client = TestClient(app)
def test_auth_missing():
query = """
query {
@@ -24,6 +25,7 @@ def test_auth_missing():
response = client.post("/graphql", json={"query": query})
assert response.status_code == 401
def test_auth_invalid():
query = """
query {
@@ -32,12 +34,15 @@ def test_auth_invalid():
}
}
"""
response = client.post("/graphql", json={"query": query}, headers={"X-API-Key": "wrong"})
response = client.post(
"/graphql", json={"query": query}, headers={"X-API-Key": "wrong"}
)
assert response.status_code == 401
def test_graphql_workflow():
headers = {"X-API-Key": "test-secret"}
# 1. Get empty alarms
query_get = """
query {
@@ -49,7 +54,7 @@ def test_graphql_workflow():
res = client.post("/graphql", json={"query": query_get}, headers=headers)
assert res.status_code == 200
assert res.json()["data"]["getAlarms"] == []
# 2. Set alarm
mutation_set = """
mutation {
@@ -68,12 +73,12 @@ def test_graphql_workflow():
assert alarm["command"] == "python wecker.py"
assert alarm["isEnabled"] is True
alarm_id = alarm["id"]
# 3. Get alarms lists it
res = client.post("/graphql", json={"query": query_get}, headers=headers)
assert len(res.json()["data"]["getAlarms"]) == 1
assert res.json()["data"]["getAlarms"][0]["id"] == alarm_id
# 4. Get specific alarm
query_one = f"""
query {{
@@ -86,7 +91,7 @@ def test_graphql_workflow():
res = client.post("/graphql", json={"query": query_one}, headers=headers)
assert res.json()["data"]["getAlarm"]["id"] == alarm_id
assert res.json()["data"]["getAlarm"]["cronExpression"] == "30 7 * * *"
# 5. Update alarm
mutation_update = f"""
mutation {{
@@ -102,7 +107,7 @@ def test_graphql_workflow():
assert alarm_updated["id"] == alarm_id
assert alarm_updated["cronExpression"] == "0 8 * * *"
assert alarm_updated["isEnabled"] is False
# 6. Delete alarm
mutation_delete = f"""
mutation {{
@@ -111,7 +116,7 @@ def test_graphql_workflow():
"""
res = client.post("/graphql", json={"query": mutation_delete}, headers=headers)
assert res.json()["data"]["deleteAlarm"] is True
# 7. List again is empty
res = client.post("/graphql", json={"query": query_get}, headers=headers)
assert res.json()["data"]["getAlarms"] == []