Skip to content

Commit c3c17da

Browse files
Docs: finalize comprehensive test plan mapping all automated endpoints
1 parent 66cd127 commit c3c17da

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

test-plan_week_004.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Test Plan — Test Suite Evolution (Serverest API)
2+
3+
This document establishes the automation strategy, execution scope, scenario mapping, and quality benchmarks designed for the integration test layer of the **ServeRest API**. It serves as the definitive engineering blueprint for the continuous evolution of our test suite.
4+
5+
---
6+
7+
## 1. Test Suite Objective
8+
The primary objective of this suite is to secure the reliability, stability, contract integrity, and strict enforcement of business logic and Role-Based Access Control (RBAC) across the target endpoints. The architecture is engineered to validate resilient happy paths while aggressively catching malformed payloads, invalid operations, and critical security flaws such as privilege escalation.
9+
10+
## 2. Testing Strategy
11+
Our strategy prioritizes speed, strict thread isolation, and deterministic test execution across both local environments and remote cloud infrastructure.
12+
13+
* **Test Layer:** API / Service / Integration Testing Layer.
14+
* **Test Types:** Functional Validations (Positive & Negative flows) + Contract Compliance (JSON Schema verification).
15+
* **Core Technology Stack:**
16+
* **Language:** Python 3.12
17+
* **Test Framework:** `pytest` (for orchestration, parametric testing, and fixture management).
18+
* **HTTP Client:** `requests` (for network transmission and payload consumption).
19+
* **Contract Validation:** `pytest-schema` (powered by `jsonschema` definitions).
20+
* **Infrastructure Isolation:** `Docker` (built atop `python:3.12-slim` for consistent, environment-agnostic execution).
21+
22+
## 3. Scope Matrix
23+
24+
### 🟢 In Scope
25+
* **User Management (`/usuarios`):** Complete CRUD mutations, email uniqueness constraints, and input field integrity.
26+
* **Authentication Lifecycle (`/login`):** Token generation mechanics, validation of credentials, and security boundary responses.
27+
* **Product Catalog (`/produtos`):** Protected administrative inventory controls and role-based access restrictions.
28+
* **Shopping Carts (`/carrinhos`):** Multi-dependency checkouts and automatic inventory restocking validation.
29+
30+
### 🔴 Out of Scope
31+
* Performance benchmarks, load testing, or concurrency stress thresholds.
32+
* Core infrastructure penetration testing or cryptographic token breaking.
33+
* Front-End UI / End-to-End browser test automation.
34+
35+
---
36+
37+
## 4. Mapped & Implemented Test Scenarios
38+
39+
### Authentication Lifecycle (`/login` & `/usuarios`)
40+
* **Scenario 01 (Positive) `test_create_user_successfully`:** Registers a baseline account via `POST /usuarios`, asserts a `201 Created` status with an integrated schema validation, and triggers an automated downstream `DELETE` teardown to guarantee a stateless database.
41+
* **Scenario 02 (Negative) `test_login_invalid_password`:** Dispatches an authentication attempt via `POST /login` with an unverified password, asserting a strict `401 Unauthorized` block.
42+
* **Scenario 03 (Negative) `test_login_nonexistent_user`:** Submits unregistered credentials to `/login`, verifying that the API gracefully rejects the transaction via standard `401`/`404` error envelopes to maintain user privacy.
43+
* **Scenario 04 (Negative) `test_login_without_name`:** Rejects input creation on `/usuarios` when the `nome` key is dropped, expecting an explicit `400 Bad Request` and field-specific validation strings.
44+
* **Scenario 05 (Negative) `test_login_without_email`:** Rejects input creation on `/usuarios` when the `email` key is dropped, expecting an explicit `400 Bad Request` and field-specific validation strings.
45+
* **Scenario 06 (Negative) `test_login_without_password`:** Rejects input creation on `/usuarios` when the `password` key is dropped, expecting an explicit `400 Bad Request` and field-specific validation strings.
46+
* **Scenario 07 (Negative) `test_login_without_administrator`:** Rejects input creation on `/usuarios` when the boolean `administrador` flag is omitted, returning a `400 Bad Request`.
47+
48+
### User Administration CRUD (`/usuarios`)
49+
* **Scenario 01 (Positive) `test_create_user_successfully`:** Validates account provisioning via `POST`, verifying payload metadata and cascading cleanups.
50+
* **Scenario 02 (Negative) `test_create_user_duplicated_email`:** Enforces backend data constraints by attempting a duplicate user registration, verifying that the engine catches conflicts and returns a `400 Bad Request` containing the specific error string.
51+
* **Scenario 03 (Positive) `test_list_all_users`:** Targets a global `GET /usuarios`, confirming a `200 OK` status and validating that the structural multi-user array matches expectations.
52+
* **Scenario 04 (Positive) `test_delete_user_successfully_by_id`:** Sequentially registers a record, executes a targeted `DELETE /usuarios/{id}`, and runs a subsequent `GET` check to confirm the profile is fully expunged.
53+
* **Scenario 05 (Positive) `test_search_user_by_id`:** Asserts direct id-parameterized lookups via `GET /usuarios/{id}`, ensuring contract data integrity.
54+
* **Scenario 06 (Positive) `test_update_user_successfully`:** Isolates state using randomized UUID structures, applies changes via an authorized `PUT /usuarios/{id}`, and confirms a `200 OK` update state.
55+
* **Scenario 07 (Negative) `test_update_user_duplicated_email`:** Populates two separate users and attempts to overwrite the second profile's email parameter with the first user's registered address via a `PUT` mutation, forcing a `400 Bad Request` validation failure.
56+
57+
### Product Catalog Management (`/produtos`)
58+
* **Scenario 01 (Positive) `test_create_product_successfully_with_admin_token`:** Registers an item via `POST /produtos` using administrative tokens, asserting a successful `200/201` status before cleaning the environment.
59+
* **Scenario 02 (Negative/Security) `test_create_product_without_admin_token`:** Validates access control blockages by dropping auth headers on catalog insertions, confirming an explicit `401/403` handling.
60+
* **Scenario 03 (Negative) `test_create_product_without_name`:** Drops the `nome` key from the payload dictionary via controlled fixture mutations, ensuring a `400 Bad Request` rejection.
61+
* **Scenario 04 (Negative) `test_create_product_without_price`:** Drops the `preco` key from the payload dictionary via controlled fixture mutations, ensuring a `400 Bad Request` rejection.
62+
* **Scenario 05 (Negative) `test_create_product_without_description`:** Drops the `descricao` key from the payload dictionary via controlled fixture mutations, ensuring a `400 Bad Request` rejection.
63+
* **Scenario 06 (Positive) `test_search_product_by_id`:** Generates an isolated catalog listing, checks specific parameter lookups via `GET /produtos/{id}`, and cascades a deletion teardown.
64+
* **Scenario 07 (Positive) `test_update_product_with_token`:** Creates a target resource and alters its properties using active admin authorization tokens via `PUT /produtos/{id}`.
65+
* **Scenario 08 (Negative/Security) `test_update_product_without_token`:** Sets up a test item but strips the authorization header out of the subsequent `PUT` modification request, ensuring the API returns a proper `401/403` message block.
66+
* **Scenario 09 (Positive) `test_delete_product_successfully`:** Seeds an item and verifies the behavior of administrative deletions using target endpoints.
67+
68+
### Shopping Carts & Checkout (`/carrinhos`)
69+
* **Scenario 01 (Positive) `test_create_cart_successfully`:** Coordinates an upstream product setup, hooks the dynamic `idProduto` into a cart payload, asserts a `201 Created` status with schema validations, and applies a robust multi-tiered teardown process.
70+
* **Scenario 02 (Negative) `test_create_cart_insufficient_stock`:** Provisions a product and intentionally leverages a `payload_factory` to ask for a volume of 50 units, asserting that the engine catches the stock deficit and throws a `400 Bad Request`.
71+
* **Scenario 03 (Positive) `test_conclude_purchase_successfully`:** Mounts a valid card structure linked to an active product, calls `DELETE /carrinhos/concluir-compra`, and asserts a clean checkout completion (`200 OK`).
72+
* **Scenario 04 (Positive) `test_cancel_purchase_and_stock_return`:** Builds a test state, hits the `/cancelar-compra` route, and validates that the system reverses the checkout, returns a `200 OK`, and automatically restocks the inventory pools.
73+
74+
---
75+
76+
## 5. Definition of Done (DoD)
77+
A test script is only considered completed and eligible to be merged into the `main` branch when it satisfies the following validation gates:
78+
79+
1. **Triple Assertion Paradigm:** Every automation script must explicitly validate the HTTP **Status Code**, verify structural accuracy within the **Response Body** (error messages or payload payloads), and ensure acceptable server performance (Tolerable **Response Time**).
80+
2. **State Independence:** Side effects from previous test execution blocks must never impact current tests. Pre-requisite data states must be generated and systematically destroyed dynamically using localized `pytest` fixtures.
81+
3. **Strict Type Contracts:** Major mutations must pass strict JSON schema evaluation gates using `pytest-schema` to guarantee structural regressions do not go unnoticed.
82+
4. **Isolated Docker Integrity:** The full suite must execute seamlessly and pass without local errors inside the project's specialized container.
83+
5. **CI Pipeline Stability:** Remote pushes must trigger a green build across the sandboxed workflows defined in `.github/workflows/ci.yml`.

0 commit comments

Comments
 (0)