feat(api): Enhance session events API with pagination, sorting, and filtering

- Added support for pagination (page and limit) in the session events endpoint.
- Implemented sorting functionality based on specified columns and directions.
- Introduced free-text search capability for session events.
- Updated SQL queries to retrieve all events and added a new SQL constant for events.
- Refactored GraphQL types and helpers to support new plugin and event queries.
- Created new GraphQL resolvers for plugins and events with pagination and filtering.
- Added comprehensive tests for new GraphQL endpoints and session events functionality.
This commit is contained in:
Jokob @NetAlertX
2026-03-26 20:57:10 +00:00
parent 250e533655
commit ec3e4c8988
15 changed files with 1312 additions and 352 deletions

View File

@@ -160,6 +160,43 @@ def test_device_session_events(client, api_token, test_mac):
assert isinstance(sessions, list)
def test_session_events_pagination(client, api_token):
"""session-events supports page, limit, and returns total/recordsFiltered."""
resp = client.get(
"/sessions/session-events?type=all&period=1 year&page=1&limit=5",
headers=auth_headers(api_token),
)
assert resp.status_code == 200
body = resp.json
assert "data" in body
assert "total" in body
assert "recordsFiltered" in body
assert isinstance(body["total"], int)
assert len(body["data"]) <= 5
def test_session_events_sorting(client, api_token):
"""session-events supports sortCol and sortDir without errors."""
resp_desc = client.get(
"/sessions/session-events?type=all&period=1 year&page=1&limit=10&sortCol=0&sortDir=desc",
headers=auth_headers(api_token),
)
assert resp_desc.status_code == 200
desc_data = resp_desc.json["data"]
resp_asc = client.get(
"/sessions/session-events?type=all&period=1 year&page=1&limit=10&sortCol=0&sortDir=asc",
headers=auth_headers(api_token),
)
assert resp_asc.status_code == 200
asc_data = resp_asc.json["data"]
# If there are at least 2 rows, order should differ (or be identical if all same)
if len(desc_data) >= 2 and len(asc_data) >= 2:
# First row of desc should >= first row of asc (column 0 is the order column)
assert desc_data[0][0] >= asc_data[0][0] or desc_data == asc_data
# -----------------------------
def test_delete_session(client, api_token, test_mac):
# First create session