ai-api-testing / TESTING_FLOWS.md
Amitkasar's picture
Remove binary files from tracking
8085285
|
Raw History Blame Contribute Delete
7.5 kB

Testing Flows for EarWax CRM Mobile API

Based on the 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:
      {
        "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:
      {
        "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:
      {
        "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:
      {
        "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.