Coverage for app/api/v1/endpoints/move_router.py: 100%
7 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-16 20:06 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-16 20:06 +0000
1from fastapi import APIRouter
3from app.api.v1.dependencies import MoveServiceDependency
4from app.schemas.move import MoveRequest, MoveResponse
6move_router = APIRouter()
9@move_router.patch(
10 "",
11 response_model=MoveResponse,
12 summary="Move probe on the grid",
13 description="Move a probe on the Martian grid based on a command string.\n\n"
14 "## Validations\n\n"
15 "The endpoint performs comprehensive validation of the move command before applying any changes to the probe state:\n\n"
16 "- **Command Validation**: Ensures the command string contains only valid commands (L, R, M).\n"
17 "- **Movement Validation**: Verifies that the probe stays within grid boundaries and doesn't attempt invalid movements.\n\n"
18 "## Error Handling\n\n"
19 "In case of validation errors, **no commands are applied to the probe state**, ensuring data integrity and security.\n\n"
20 "This is guaranteed for all error scenarios:\n"
21 "- Invalid command format or unsupported commands\n"
22 "- Movement that would take the probe outside the grid boundaries\n"
23 "- Any unexpected errors\n\n"
24 "The probe state remains unchanged if any error occurs during command execution.",
25 status_code=200,
26 responses={
27 200: {
28 "description": "Probe moved successfully",
29 "model": MoveResponse,
30 },
31 400: {
32 "description": "Invalid command error - unsupported or malformed command string. Probe state unchanged.",
33 "content": {
34 "application/json": {
35 "example": {
36 "detail": {
37 "code": "INVALID_COMMAND_ERROR",
38 "message": "Invalid command: X. For security, no commands were delivered to the probe.",
39 }
40 }
41 }
42 },
43 },
44 404: {
45 "description": "Probe not found with the given ID.",
46 "content": {
47 "application/json": {
48 "example": {
49 "detail": {
50 "code": "PROBE_NOT_FOUND",
51 "message": "Probe {id} not found.",
52 }
53 }
54 }
55 },
56 },
57 422: {
58 "description": "Invalid movement error - probe would move outside grid boundaries. Probe state unchanged.",
59 "content": {
60 "application/json": {
61 "example": {
62 "detail": {
63 "code": "INVALID_MOVEMENT_ERROR",
64 "message": "Movement would place probe outside grid. For security, no commands were delivered to the probe.",
65 }
66 }
67 }
68 },
69 },
70 500: {
71 "description": "Unexpected server error. Probe state unchanged.",
72 "content": {
73 "application/json": {
74 "example": {
75 "detail": {
76 "code": "MOVE_UNEXPECTED_ERROR",
77 "message": "Unexpected error. Try again. For security, no commands were delivered to the probe.",
78 }
79 }
80 }
81 },
82 },
83 },
84)
85async def move_probe(move: MoveRequest, service: MoveServiceDependency):
86 """
87 Execute a move command on a probe.
88 """
89 return await service.process(move)