Automated Testing Scripts
Relevant source files
The following files were used as context for generating this wiki page:
The automated testing scripts in the ELMEC Mobile App v2 project serve as a robust backend validation suite designed to ensure the integrity of the system's core modules, including Authentication, Requests, Chat, and Storage. These scripts utilize the Supabase JavaScript SDK to interact directly with the database and storage buckets, allowing for comprehensive CRUD (Create, Read, Update, Delete) verification, Realtime subscription testing, and Row Level Security (RLS) validation.
The testing architecture is categorized into specialized scripts for individual modules and a master execution script (test-all-modules.js) that aggregates results across the entire application ecosystem. This approach enables developers to validate backend logic independently of the frontend UI, ensuring that API endpoints and database constraints are functioning correctly before deployment.
Sources: REPORTE-EJECUCION-PRUEBAS.md:1-25, scripts/test-all-modules.js:1-20
Core Testing Architecture
The project employs a modular testing strategy where each script is responsible for a specific functional area of the Supabase backend. The scripts are primarily written in Node.js and leverage environment variables for secure connection to the Supabase instance.
Test Execution Flow
The following diagram illustrates the high-level logic used by the master test script to validate multiple application modules sequentially.
The master script initializes a central Supabase client and executes specialized functions for each module, tracking passes, failures, and skips in a global results object.
Sources: scripts/test-all-modules.js:33-70, REPORTE-EJECUCION-PRUEBAS.md:27-50
Module-Specific Validation
Request Management (CRUD)
The test-requests-crud.js script validates the full lifecycle of a service request. This includes testing field constraints, status transitions, and data relationships between users and agents.
| Test Category | Operations Verified | Target Table |
|---|---|---|
| CREATE | Creation with/without files, metadata injection | requests |
| READ | Listing by user, filtering by status/priority | requests |
| UPDATE | Status transitions, feedback entry, rating assignment | requests |
| DELETE | Soft/Hard deletion of test records | requests |
Sources: scripts/test-requests-crud.js:1-15, REPORTE_FINAL_VALIDACION.md:40-100
Chat and Realtime Messaging
The test-chat-module.js script focuses on complex messaging interactions, including Realtime subscriptions and Presence tracking. It simulates multiple users to verify that messages are delivered and received via WebSockets.
Storage and File Handling
The test-storage-crud.js script ensures that the Supabase Storage system correctly handles different MIME types and enforces file size limits.
| Test ID | Action | Details |
|---|---|---|
| TEST 1 | Upload Text | Validates .txt file creation |
| TEST 2 | Upload JSON | Validates .json structured data |
| TEST 5 | Get Public URL | Verifies accessibility of uploaded assets |
| TEST 10 | Multi-Delete | Cleans up multiple test paths simultaneously |
Sources: scripts/test-storage-crud.js:63-150, REPORTE_FINAL_VALIDACION.md:120-140
Implementation Details
Result Tracking and Reporting
Every script implements a standardized logging and result aggregation mechanism. This allows for clear console output using ANSI colors to denote test status.
// Example of result tracking logic found in test scripts
const testResults = {
total: 0,
passed: 0,
failed: 0,
tests: []
};
function recordTest(name, passed, message = '') {
testResults.total++;
if (passed) {
testResults.passed++;
log('green', '✅', `${name} - PASSED ${message}`);
} else {
testResults.failed++;
log('red', '❌', `${name} - FAILED ${message}`);
}
}
Sources: scripts/test-requests-crud.js:28-55, scripts/test-storage-crud.js:37-60
Database Constraints Verification
During execution, scripts actively verify database CHECK constraints. Historical execution reports show that these scripts identified and led to the correction of several invalid status values:
- Requests Status: Corrected from 'cerrado' to 'resuelto'.
- Chat Type: Corrected from 'directo' to 'support'.
- Notification Type: Corrected from 'test' to 'system'.
Sources: REPORTE-EJECUCION-PRUEBAS.md:158-205, scripts/test-all-modules.js:390-460
Summary Metrics
The testing suite provides a comprehensive overview of backend health. In the most recent full validation, the system achieved a 100% success rate on 26 critical backend cases, despite 94 cases being omitted due to their nature as UI/Frontend-only tests.
| Metric | Last Recorded Value |
|---|---|
| Total Backend Cases | 26 |
| Pass Rate | 100% |
| Avg. Duration | 2.94 seconds |
| Critical Errors | 0 |
Sources: REPORTE-EJECUCION-PRUEBAS.md:15-25, REPORTE_FINAL_VALIDACION.md:5-15