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.