version: 1
plan:
  name: nxtgauge-full-e2e-test
  max_concurrency: 6
  max_consecutive_failures: 3
  max_cycles: 10
  auto_reject_retries: 1
tasks:
  - id: track-1-professions
    title: Test all 10 profession services
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      BASE_URL: http://localhost:9100
      GATEWAY is at :9100 (routes to all services)
      Individual service ports:
        photographers: 9107, makeup_artists: 9109, tutors: 9108, developers: 9110,
        video_editors: 9111, graphic_designers: 9112, social_media_managers: 9113,
        fitness_trainers: 9114, catering_services: 9115, ugc_content_creators: 9117
      Test accounts (use test_mode=true to bypass OTP):
        Professional: bug2_test_1781086381@test.com / Test1234! (PHOTOGRAPHER role active)
        Customer: cu_1781041378@test.com / Test1234! (CUSTOMER role active)
      Open lead ID: ba18c522-b3cd-43a7-a269-90cf981c173e (PHOTOGRAPHER, status OPEN)

      FOR EACH of the 10 profession services below, test:
      1. Health check: GET http://localhost:<PORT>/health or via gateway
      2. Login to get a fresh token (use test_mode=true register, then login)
      3. GET /api/<profession>/profile/me — does profile endpoint work?
      4. GET /api/<profession>/marketplace — does marketplace browse work?
      5. Send a lead request via POST /api/<profession>/leads/request with body {"requirement_id":"ba18c522-b3cd-43a7-a269-90cf981c173e","message":"interested"}

      Professions to test:
      - photographers (9107)
      - makeup_artists (9109) — route is /api/makeup-artists
      - tutors (9108)
      - developers (9110) — route is /api/developers
      - video_editors (9111) — route is /api/video-editors
      - graphic_designers (9112) — route is /api/graphic-designers
      - social_media_managers (9113) — route is /api/social-media-managers
      - fitness_trainers (9114) — route is /api/fitness-trainers
      - catering_services (9115) — route is /api/catering-services
      - ugc_content_creators (9117) — route is /api/ugc-content-creators

      NOTE: The "professional" user (bug2_test_1781086381@test.com) only has PHOTOGRAPHER role. For other professions, register a fresh user, register the role, switch to that role, then test.

      Write results to /Users/ashwin/workspace/e2e-results/track-1-professions.md with:
      - For each profession: service port, health status, profile result, marketplace result, lead_request result, any errors
      - Summary of which services are fully functional vs partially working vs broken
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-2-leads
    title: Test leads service and lead request accept/reject flow
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      Gateway: http://localhost:9100
      Leads service: http://localhost:9118 (or via gateway /api/leads)
      Customers service: http://localhost:9105

      Test accounts (use test_mode=true):
        Customer: cu_1781041378@test.com / Test1234!
        Photographer: bug2_test_1781086381@test.com / Test1234! (has PHOTOGRAPHER approved profile)

      Test the following flows:

      1. LEADS SERVICE CRUD:
         - GET /api/leads — list all leads (or http://localhost:9118/leads)
         - POST /api/leads — create a new lead {"title":"Test Lead 2","description":"API test","location":"Delhi","profession_key":"PHOTOGRAPHER"}
         - GET /api/leads/:id — get specific lead
         - PATCH /api/leads/:id — update the lead title

      2. CUSTOMER VIEW REQUESTS (the /requests endpoint we fixed):
         - Login as customer, get token
         - GET /api/customers/requests — should return HTTP 200 with {"data":[]}
         - POST a lead request as the photographer, then check GET /api/customers/requests again

      3. CUSTOMER ACCEPT/REJECT LEAD REQUEST:
         - First, check what the approve/reject endpoints look like
         - Try POST /api/customers/requests/:lead_request_id/approve
         - Try POST /api/customers/requests/:lead_request_id/reject
         - Note: these may fail with 404 or 500 — document what happens

      4. PROFESSIONAL LEAD REQUEST FLOW:
         - Login as photographer, get fresh token
         - GET /api/photographers/marketplace — should show OPEN leads
         - POST /api/photographers/leads/request — send a new lead request
         - GET /api/photographers/leads/requests/me — list my sent requests
         - DELETE /api/photographers/leads/requests/:id — cancel a pending request

      Write results to /Users/ashwin/workspace/e2e-results/track-2-leads.md with:
      - Each endpoint tested, HTTP status, response body
      - Any errors, 4xx/5xx codes, and what they mean
      - Overall status of leads + lead request flow
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-3-payments
    title: Test payments and tracecoin flows
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      Gateway: http://localhost:9100
      Payments service: http://localhost:9116
      Test accounts: bug2_test_1781086381@test.com / Test1234!

      DATABASE: postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db

      Test these flows:

      1. TRACEOCOIN WALLET:
         - GET /api/packages — list all pricing packages (via gateway or users service)
         - GET /api/photographers/wallet/me — check photographer wallet (may fail with 404 if not set up)
         - Check DB: psql "postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db" -c "SELECT * FROM tracecoin_wallets LIMIT 5;"

      2. TRACEOCOIN PURCHASE (if payments service is running on 9116):
         - GET http://localhost:9116/health — is payments service up?
         - GET http://localhost:9116/api/packages — list packages
         - Try to initiate a tracecoin purchase (check the payments service routes)

      3. PAYMENTS SERVICE ROUTES:
         - Document what routes the payments service exposes
         - Try GET /api/payments/health
         - Try GET /api/payments/packages
         - Check what the Beeceptor mock URL is (if used)

      4. TRACEOCOIN LEDGER:
         - Check DB: psql "postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db" -c "SELECT * FROM tracecoin_ledger LIMIT 10;"
         - Check the schema of tracecoin_ledger table

      5. INVOICES:
         - Check DB: psql ... -c "SELECT * FROM invoices LIMIT 5;"
         - Check invoices table schema

      Write results to /Users/ashwin/workspace/e2e-results/track-3-payments.md with:
      - Payments service status (running or not)
      - All endpoints tested with HTTP status and response
      - Tracecoin wallet balances found in DB
      - Any payment flow errors
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-4-admin
    title: Test admin approval and verification workflow
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      Gateway: http://localhost:9100
      Test admin account: cu_1781041378@test.com / Test1234! (or use admin credentials if available)

      NOTE: The admin dashboard is a separate Next.js app. Test the backend API endpoints only.

      Test these flows:

      1. ADMIN VERIFICATIONS ENDPOINT:
         - GET /api/admin/verifications — list verification cases (requires admin auth)
         - GET /api/admin/verifications?status=PENDING — filter by status
         - What does this return? 200? 403? 401?

      2. ADMIN APPROVALS ENDPOINT:
         - GET /api/admin/approvals — list approval cases
         - What does it return?

      3. APPROVE A JOB (job posting approval):
         - First create a job as a company (use co_1781041378@test.com / Test1234! if available, or register new)
         - Submit the job (status goes to PENDING_APPROVAL)
         - Try to approve it via admin endpoint: POST /api/admin/jobs/:job_id/approve or similar
         - Document what admin job approval endpoints exist

      4. APPROVE A REQUIREMENT (customer lead approval):
         - Create a customer requirement
         - Submit it (status goes to PENDING_APPROVAL)
         - Try to approve via admin endpoint

      5. ADMIN APPROVAL FLOW:
         - Check what routes exist under /api/admin/ for approvals
         - GET /api/admin/approval-cases if it exists
         - Try to find and call the actual approval endpoints

      6. VERIFICATION MANAGEMENT:
         - GET /api/admin/verifications — list all verifications
         - Try to approve/reject a verification

      Write results to /Users/ashwin/workspace/e2e-results/track-4-admin.md with:
      - Each admin endpoint tested, HTTP status, response
      - Whether verification/approval workflow is functional end-to-end
      - Missing or broken admin endpoints
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-5-support
    title: Test support tickets and email notifications
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      Gateway: http://localhost:9100
      Test accounts: bug2_test_1781086381@test.com / Test1234! (or register fresh users with test_mode=true)

      Test these flows:

      1. SUPPORT TICKETS (user-facing):
         - POST /api/support/tickets — create a support ticket
           Body: {"subject":"Test ticket from API","message":"This is a test","category":"GENERAL"}
         - GET /api/support/tickets — list my tickets
         - GET /api/support/tickets/:id — get specific ticket
         - POST /api/support/tickets/:id/messages — add a message to a ticket

      2. SUPPORT TICKETS (admin):
         - GET /api/admin/support-cases — list all support cases (admin only)
         - Try to reply to a ticket as admin

      3. EMAIL NOTIFICATIONS (check if emails are being sent):
         - Create a ticket → check DB: psql "postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db" -c "SELECT * FROM email_logs ORDER BY created_at DESC LIMIT 10;"
         - Submit a job → check email_logs
         - Submit a requirement → check email_logs
         - Submit a job application → check email_logs

      4. NOTIFICATIONS:
         - GET /api/me/notifications — list user notifications
         - Check notification table: psql "postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db" -c "SELECT * FROM notifications ORDER BY created_at DESC LIMIT 20;"

      5. KNOWLEDGE BASE:
         - GET /api/kb/articles — list KB articles
         - GET /api/kb/articles/:id — get specific article
         - GET /api/kb/categories — list categories

      Write results to /Users/ashwin/workspace/e2e-results/track-5-support.md with:
      - Support ticket creation status (success/fail/error)
      - Email logs found in DB (were emails sent?)
      - Notifications generated
      - KB articles accessible
      - Any broken endpoints
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-6-reviews-portfolio
    title: Test reviews, portfolio, and onboarding flows
    prompt: |
      You are testing the Nxtgauge backend API. All tests are via direct HTTP API calls.

      Gateway: http://localhost:9100
      Test accounts: register fresh users with test_mode=true as needed

      DATABASE: postgresql://nxtgauge:nxtgauge_dev@localhost:5432/nxtgauge_db

      Test these flows:

      1. REVIEWS:
         - POST /api/reviews — submit a review
           Body: {"entity_type":"COMPANY","entity_id":"<company_uuid>","rating":5,"comment":"Great service!"}
           (You'll need to find a valid company_id from the DB: psql ... -c "SELECT id FROM company_profiles LIMIT 3;")
         - GET /api/reviews — list reviews
         - GET /api/reviews?entity_type=COMPANY&entity_id=<id> — reviews for a company
         - Admin: GET /api/admin/reviews — admin review list

      2. PORTFOLIO (photographer):
         - Login as photographer (bug2_test_1781086381@test.com / Test1234!)
         - POST /api/photographers/portfolio/me — create portfolio item
           Body: {"title":"Test Portfolio","description":"Test description","image_url":"https://example.com/test.jpg"}
         - GET /api/photographers/portfolio/me — list portfolio items
         - PATCH /api/photographers/portfolio/me/:id — update portfolio item
         - DELETE /api/photographers/portfolio/me/:id — delete portfolio item

      3. SERVICES (photographer):
         - POST /api/photographers/services/me — create a service
           Body: {"name":"Wedding Photography Package","description":"Full day coverage","price_inr":50000}
         - GET /api/photographers/services/me — list services
         - PATCH /api/photographers/services/me/:id — update service
         - DELETE /api/photographers/services/me/:id — delete service

      4. ONBOARDING STATE:
         - GET /api/onboarding/state — get onboarding state for a user
         - POST /api/onboarding/submit — submit onboarding data
         - GET /api/me — check if role and profile status is shown

      5. RUNTIME CONFIG:
         - GET /api/runtime-config — get runtime config for a role
         - GET /api/runtime-config?role=PHOTOGRAPHER — get specific role config

      Write results to /Users/ashwin/workspace/e2e-results/track-6-reviews-portfolio.md with:
      - Each endpoint tested, HTTP status, response
      - DB schema for reviews and portfolio tables
      - Any errors found
    assigned_to: general
    verify_skip_reason: "Downstream compilation task reads all result files directly; no independent verification needed for raw API test output."
    max_retries: 1

  - id: track-7-compile-report
    title: Compile comprehensive test report
    role: verify-as-task
    prompt: |
      Read all the test result files created by the other tracks and compile a comprehensive report.

      Read these files:
      - /Users/ashwin/workspace/e2e-results/track-1-professions.md
      - /Users/ashwin/workspace/e2e-results/track-2-leads.md
      - /Users/ashwin/workspace/e2e-results/track-3-payments.md
      - /Users/ashwin/workspace/e2e-results/track-4-admin.md
      - /Users/ashwin/workspace/e2e-results/track-5-support.md
      - /Users/ashwin/workspace/e2e-results/track-6-reviews-portfolio.md
      - Also read: /Users/ashwin/workspace/E2E_TEST_REPORT.md (the previous report from Session 1)

      Compile everything into a single comprehensive report at:
      /Users/ashwin/workspace/e2e-results/COMPLETE_E2E_REPORT.md

      The report should include:
      1. Executive summary: overall system health (X/Y endpoints working)
      2. Track-by-track results with PASS/FAIL for each endpoint tested
      3. All bugs found this round (new issues not in the previous report)
      4. All bugs from the previous report and their current status (fixed/still broken)
      5. Recommendations and priority list of what to fix next
      6. Test data created during this round

      Format: Markdown report. Be thorough — this is the canonical test record.
    assigned_to: general
    depends_on:
      - track-1-professions
      - track-2-leads
      - track-3-payments
      - track-4-admin
      - track-5-support
      - track-6-reviews-portfolio
    max_retries: 1
