Skip to main content

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 ClassDescription
TestHealthService health check (DB + Redis)
TestUnauthenticatedVerify 401 on protected endpoints
TestGetTypesGet all command types and device-specific types
TestTemplateCRUDCreate, list, update, delete templates
TestSendCommandSend commands with owner/shared user permissions
TestCommandStatusCheck pending command status

Test Flows

TestSendCommand

  1. Create user and claim device
  2. Send valid command → 202 Accepted
  3. Send invalid command type → 400 Bad Request
  4. User without access → 403 Forbidden

TestTemplateCRUD

  1. Create template → 201 Created
  2. List templates → returns created template
  3. Update template → name changed
  4. Delete template → 204 No Content
  5. Other user cannot see template

Helper Functions

Located in tests/helpers.py:

FunctionDescription
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 helperscreate, 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.