Commands Service Tests
Overviewβ
Integration tests for the commands service, testing command flows and template CRUD.
Running Testsβ
cd /backend
make test commands
Test Configurationβ
- Base URL:
http://localhost/api/commands(via gateway) - Dependencies: auth, device, postgres, redis, gateway
Test Classesβ
| Test Class | Description |
|---|---|
TestHealth | Service health check (DB + Redis) |
TestUnauthenticated | Verify 401 on protected endpoints |
TestGetTypes | Get all command types and device-specific types |
TestTemplateCRUD | Create, list, update, delete templates |
TestSendCommand | Send commands with owner/shared user permissions |
TestCommandStatus | Check pending command status |
Test Flowsβ
TestSendCommandβ
- Create user and claim device
- Send valid command β 202 Accepted
- Send invalid command type β 400 Bad Request
- User without access β 403 Forbidden
TestTemplateCRUDβ
- Create template β 201 Created
- List templates β returns created template
- Update template β name changed
- Delete template β 204 No Content
- Other user cannot see template
Helper Functionsβ
Located in tests/helpers.py:
| Function | Description |
|---|---|
create_regular_user() | Creates test user in DB |
delete_user(id) | Deletes test user |
login_user(client, email, password) | Login via auth service |
get_auth_headers(token) | Create Bearer header |
claim_device(client, headers, unique_id) | Claim device via device service |
unclaim_device(client, headers, device_id) | Unclaim device |
get_command_types(client, headers) | GET /types |
send_command(client, headers, device_id, type) | POST /send |
get_command_status(client, headers, entry_id) | GET /status/{id} |
| Template CRUD helpers | create, list, update, delete |
Limitationsβ
These tests validate the command service HTTP layer only. The decoder integration (actual command delivery to devices) requires end-to-end testing with the decoder service running.