Spaces:
Runtime error
Runtime error
File size: 7,495 Bytes
8085285 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | # Testing Flows for EarWax CRM Mobile API
Based on the [openapi.yaml](file:///c:/Users/amitk/OneDrive/Desktop/Testing/Ref/openapi.yaml) specification, here are the end-to-end integration and business flows you can configure and test using this AI API Testing Tool.
---
## 1. Authentication & Security Life Cycle Flow
Verify user authentication, session security, token rotation, and clean profile termination.
### Scenario Steps:
1. **User Login**: `POST /auth/login`
- **Payload**: `{ "username": "exceladmin", "password": "your_secure_password" }`
- **Expectation**: Receives `access_token` and `refresh_token` in `TokenPair`, plus the `User` object.
2. **Retrieve Profile**: `GET /auth/me`
- **Headers**: `Authorization: Bearer <access_token>`
- **Expectation**: Confirms token validation and retrieves profile info.
3. **Update Profile**: `POST /auth/update-profile`
- **Payload**: `{ "full_name": "Admin Tester", "email": "admin@earwaxcrm.com" }`
- **Expectation**: Patches profile info and returns the updated `User` object.
4. **Token Rotation**: `POST /auth/refresh`
- **Payload**: `{ "refresh_token": "<refresh_token>" }`
- **Expectation**: Rotates the old refresh token and issues a new `TokenPair`.
5. **Change Password**: `POST /auth/change-password`
- **Payload**: `{ "current_password": "your_secure_password", "new_password": "new_secure_password123" }`
- **Expectation**: Password changed. All active sessions are invalidated.
6. **Logout**: `POST /auth/logout`
- **Expectation**: Invalidates active tokens immediately.
---
## 2. Lead Intake & Management Flow
Tests onboarding a new prospect, registering communication notes, and transitioning them through the sales pipeline.
### Scenario Steps:
1. **Authentication**: Log in to obtain a Bearer token.
2. **Create Prospect Lead**: `POST /leads/create`
- **Payload**:
```json
{
"first_name": "John",
"last_name": "Smith",
"email": "john.smith@example.com",
"phone": "+447700900077",
"qualification": "BSc Audio",
"status": "new",
"source": "Mobile App",
"notes": "Interested in Ear Wax Removal Course."
}
```
- **Expectation**: Returns `lead_id` (e.g., `45`). Triggers push notification to admins.
3. **Inspect Lead Details**: `GET /leads/detail`
- **Query Parameters**: `?id=<lead_id>`
- **Expectation**: Retrieves full profile, empty appointments array, and the "Lead Created" activity entry.
4. **Append Operator Note**: `POST /leads/add-note`
- **Payload**: `{ "id": <lead_id>, "note": "Called prospect. Requested booking options." }`
- **Expectation**: Modifies the plain-text notes and logs a new activity entry.
5. **Update Pipeline Status**: `POST /leads/update-status`
- **Payload**: `{ "id": <lead_id>, "status": "planned_later" }`
- **Expectation**: Success response. (Fires automatic system email/SMS triggers).
6. **Archive Prospect**: `POST /leads/archive` (Admin only)
- **Payload**: `{ "id": <lead_id>, "archive": true }`
- **Expectation**: Lead marked as archived, cancelling any scheduled follow-up notifications.
---
## 3. Student Lead-to-Booking Conversion Flow
The core CRM revenue flow. Tests converting an interested lead into an active student with a booked course, payment confirmation, and invoice creation.
### Scenario Steps:
1. **Select Available Course**: `GET /courses`
- **Expectation**: Retrieves list of active courses. Note down a `course_id` and training details.
2. **Onboard Student Lead**: `POST /leads/create`
- **Payload**: `{ "first_name": "Jane", "email": "jane.doe@example.com", "status": "new" }`
- **Expectation**: Returns new `lead_id`.
3. **Book Appointment**: `POST /appointments/create`
- **Payload**:
```json
{
"lead_id": <lead_id>,
"course_id": <course_id>,
"appointment_date": "2026-06-15",
"appointment_time": "09:00",
"amount_paid": 499.00,
"payment_method": "Stripe",
"status": "pending"
}
```
- **Expectation**: Returns `appointment_id` and a unique `appointment_ref` (e.g., `APT-W4X5Y6`).
4. **Inspect Lead Funnel Status**: `GET /leads/detail`
- **Query Parameters**: `?id=<lead_id>`
- **Expectation**: Confirms the appointment is now linked and listed in the lead's appointments array.
5. **Confirm and Pay Booking**: `POST /appointments/update-status`
- **Payload**: `{ "id": <appointment_id>, "status": "confirmed" }`
- **Expectation**: Status successfully transitioned (fires push notifications to admins and updates revenue analytics).
6. **Generate PDF Invoice**: `GET /invoice/pdf`
- **Query Parameters**: `?id=<appointment_id>`
- **Expectation**: Streams an A4-format PDF file (`Content-Type: application/pdf`).
---
## 4. Mobile Push Notification & Registration Flow
Tests device token management and clean session tear-down for mobile apps.
### Scenario Steps:
1. **Device Registration**: `POST /devices/register`
- **Payload**:
```json
{
"push_token": "ExponentPushToken[12345abcde67890fghij]",
"platform": "ios",
"device_name": "Developer iPad Air"
}
```
- **Expectation**: Registers device token linked to active user. Safe to trigger on every startup.
2. **Trigger Event Notification**: Run either **Lead Creation** or **Appointment Status Update**.
- **Expectation**: The backend triggers Expo Push notifications for admins.
3. **Device Deregistration via Logout**: `POST /auth/logout`
- **Payload**: `{ "push_token": "ExponentPushToken[12345abcde67890fghij]" }`
- **Expectation**: Unregisters only this specific device token during user sign-out.
---
## 5. Administrative Dashboard & User Audit Flow
Tests management reporting, staff accounts auditing, and access control.
### Scenario Steps:
1. **Fetch Dashboard Summary**: `GET /stats/dashboard`
- **Expectation**: Retrieves KPIs (total leads, enrolled count, upcoming appointments) and lists the 5 most recent leads.
2. **Fetch Financial & Pipeline Analytics**: `GET /stats` (Admin only)
- **Query Parameters**: `?date_from=2026-01-01&date_to=2026-06-30`
- **Expectation**: Returns detailed monthly revenue charts, lead breakdown by state, and main referral sources.
3. **Audit Staff List**: `GET /users` (Admin only)
- **Expectation**: Lists all registered CRM staff accounts.
4. **Provision Staff Account**: `POST /users/create` (Admin only)
- **Payload**:
```json
{
"username": "staff_jane",
"password": "TemporaryPassword123",
"full_name": "Jane Staff",
"email": "jane.staff@earwaxcrm.com",
"role": "staff"
}
```
- **Expectation**: Returns new `user_id`.
5. **Deactivate Staff Member**: `POST /users/deactivate` (Admin only)
- **Payload**: `{ "id": <user_id>, "active": false }`
- **Expectation**: Instantly revokes all active tokens for that staff member.
---
## 6. Global Search & Lookup Flow
Tests operators' ability to quickly find and filter data across the system.
### Scenario Steps:
1. **Full-Text Lead Lookup**: `GET /search`
- **Query Parameters**: `?q=Smith`
- **Expectation**: Retrieves matching non-archived leads (up to 30 results). Minimum query is 2 characters.
2. **Paginated Lead Listing with Filter**: `GET /leads`
- **Query Parameters**: `?status=new&search=Jane&sort=created_at&dir=desc`
- **Expectation**: Returns sorted and filtered search results in paginated format.
|