kamau1's picture
fix: handle {}β†’[] conversion in Contractor Pydantic schema to respect JSONB DB design
659c5be

Integration Tests

Available Tests

1. Authentication API Test

Tests the complete auth flow: register, login, profile management.

node tests/integration/test_auth_api.js

2. Invitation Flow Test

Tests the complete invitation workflow:

  • Login as platform admin
  • Create contractor organization
  • Invite user to organization
  • Validate invitation token
  • List invitations
node tests/integration/test_invitation_flow.js

Configuration

Both tests use:

  • Server: https://kamau1-swiftops-backend.hf.space
  • Admin Email: lewis.kamau421@gmail.com
  • Admin Password: TestPass123

Invitation Test Configuration

  • Invitee Email: irene@example.com
  • Invitee Phone: +254799456976
  • Role: field_agent
  • Organization: TechInstall Kenya Ltd (contractor)

Expected Output

Successful Invitation Flow

πŸš€ SwiftOps User Invitation Flow Test
πŸ“ Server: https://kamau1-swiftops-backend.hf.space
πŸ‘€ Admin: lewis.kamau421@gmail.com
πŸ“§ Inviting: irene@example.com (+254799456976)

πŸ” Step 1: Login as Platform Admin
βœ… Login successful

🏒 Step 2: Create Contractor Organization
βœ… Contractor created successfully

πŸ“§ Step 3: Invite User to Contractor
βœ… Invitation created successfully
   πŸ“± Invitation URL:
   https://swiftops.atomio.tech/accept-invitation?token=xxx

βœ… Step 4: Validate Invitation Token (Public)
βœ… Invitation validated successfully

πŸ“‹ Step 5: List All Invitations
βœ… Invitations retrieved successfully

πŸŽ‰ All steps completed successfully!

Troubleshooting

Server Not Reachable

  • Check if the server is running
  • Verify the BASE_URL is correct
  • Check network connectivity

Authentication Failed

  • Verify admin credentials are correct
  • Check if user exists in database
  • Ensure Supabase Auth is configured

Invitation Failed

  • Check environment variables are set (WASENDER_API_KEY, RESEND_API_KEY)
  • Verify contractor was created successfully
  • Check database migrations are applied

WhatsApp Not Sent

  • Verify WASENDER_API_KEY is valid
  • Check phone number format (+country code)
  • System will fallback to email automatically

Next Steps After Successful Test

  1. Check WhatsApp - Irene should receive invitation on +254799456976
  2. Click Link - Opens registration page with pre-filled email
  3. Complete Registration - Irene fills name and password
  4. Auto Login - User is created and logged in automatically

Manual Testing

You can also test the API manually using cURL:

Create Invitation

curl -X POST "https://kamau1-swiftops-backend.hf.space/api/v1/invitations" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "irene@example.com",
    "phone": "+254799456976",
    "role": "field_agent",
    "contractor_id": "YOUR_CONTRACTOR_ID",
    "invitation_method": "whatsapp"
  }'

Validate Token (Public)

curl -X POST "https://kamau1-swiftops-backend.hf.space/api/v1/invitations/validate" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "INVITATION_TOKEN"
  }'

Accept Invitation (Public)

curl -X POST "https://kamau1-swiftops-backend.hf.space/api/v1/invitations/accept" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "INVITATION_TOKEN",
    "first_name": "Irene",
    "last_name": "Wanjiku",
    "password": "SecurePass123!",
    "phone": "+254799456976"
  }'