Skip to main content

Tracking Service Tests

Overview

Integration tests for the tracking-service, covering positions, events, and geofences against a live service and database.

Running Tests

[!IMPORTANT] The tracking-service and db-persister containers must be running to ensure database tables are created.

# 1. Start services (creates tables)
make up tracking db-persister

# 2. Run tests
make test tracking

Test Flows

Test ClassDescription
TestHealth
test_health_checkVerify service is healthy (200 OK).
TestPositionFlowLifecycle & Permissions
test_position_tracking_lifecycle1. Insert: Add mock positions (past & present).
2. Latest: Verify GET /positions returns latest.
3. History: Verify GET /positions?from=... returns range.
4. Security: Verify other user cannot access.
5. Delete: Verify owner can delete history.
6. Verify: Confirm deletion.
TestEventFlowEvents & Filtering
test_event_lifecycle1. Insert: Add deviceOnline/deviceOffline events.
2. List: Verify all events returned.
3. Filter: Verify type=deviceOffline filtering.
4. Get: Verify single event retrieval.
5. 404: Verify nonexistent event checks.
TestGeofenceFlowCRUD & Validation
test_geofence_crud1. Create: Create valid CIRCLE geofence.
2. List: Verify created geofence appears.
3. Update: Modify name.
4. Delete: Remove geofence.
5. Validation: Verify invalid WKT returns 400.

Helper Functions

FunctionTypeDescription
create_userDBCreate user directly in users table.
create_device_for_userDBCreate device & owner link in devices/user_device.
insert_positionDBInsert mock GPS data into positions.
insert_eventDBInsert mock event into events.
get_positionsAPIGET /positions/ details or history.
list_eventsAPIGET /events/ with filters.
create_geofenceAPIPOST /geofences/ with WKT.

Permissions Tested

OperationOwnerShared UserOther User
View Latest Position✅ (if enabled)
View Position History✅ (if enabled)
Delete Position History
View Events✅ (if enabled)
Manage Geofences