{
  "ursId": "URS-063",
  "title": "Distributor Onboarding Workflow with Roles",
  "timestamp": "2026-04-23T03:45:07.127Z",
  "durationMs": 91437,
  "config": {
    "inboxUrl": "http://localhost:65472",
    "dbHost": "localhost",
    "dbPort": 65473,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Login as manufacturer admin",
      "status": "pass",
      "description": "Step 1: Login as manufacturer admin",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-01-manufacturer-logged-in.png"
      ],
      "explanation": "Proves that Mark (ZuriMED manufacturer admin) can authenticate successfully. Establishes the administrative context required to manage distributor relationships and member invitations in all subsequent steps. This step also opens the single browser context re-used by steps 2–11 so the audit log records exactly one `user:login` event for the manufacturer session (not one per step).",
      "startedAt": "2026-04-23T03:45:15.348Z",
      "finishedAt": "2026-04-23T03:45:15.348Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-01-login.webm"
    },
    {
      "name": "Step 2: Navigate to Distributor Agencies",
      "status": "pass",
      "description": "Step 2: Navigate to Distributor Agencies",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-02-org-relationships-page.png"
      ],
      "explanation": "Navigates to the Organization Relationships settings page where distributor agency relationships are managed. Confirms the page is accessible to manufacturer admins and displays the correct heading.",
      "startedAt": "2026-04-23T03:45:18.653Z",
      "finishedAt": "2026-04-23T03:45:18.653Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-02-navigate-distributor-agencies.webm"
    },
    {
      "name": "Step 3: Existing distributors",
      "status": "pass",
      "description": "Step 3: Existing distributors",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-03-existing-distributors.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-03-create-button-visible.png"
      ],
      "explanation": "Verifies that existing downstream distributor relationships (StellarTech Medical Solutions) are displayed in the Downstream Organizations section, and that the \"Create New Distributor\" action is available to the admin.",
      "startedAt": "2026-04-23T03:45:23.646Z",
      "finishedAt": "2026-04-23T03:45:23.699Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-03-existing-distributors.webm"
    },
    {
      "name": "Step 4: Create distributor",
      "status": "pass",
      "description": "Step 4: Create distributor",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-04-create-distributor-form-empty.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-04-form-filled-with-ids.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-04-distributor-created.png"
      ],
      "explanation": "Fills out and submits the new distributor form with an organization name, invite email, invitee name, the \"Add user as a representative\" option, and the Rep ID and Trunk ID inputs. Confirms the system creates the distributor relationship and redirects back to the org-relationships page on success. The submitted Rep ID / Trunk ID values are asserted in DB validation to prove they were persisted.",
      "expectedEmailTemplates": [
        "Verify your DeviceFlow",
        "Representative Account Approved"
      ],
      "expectedAuditActions": [
        "user_log:rep_onboarding_request_approved"
      ],
      "startedAt": "2026-04-23T03:45:28.772Z",
      "finishedAt": "2026-04-23T03:45:36.082Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-04-create-distributor.webm"
    },
    {
      "name": "Step 5: Duplicate name rejected",
      "status": "pass",
      "description": "Step 5: Duplicate name rejected",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-05-duplicate-form-filled.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-05-duplicate-error-visible.png"
      ],
      "explanation": "Re-submits the new-distributor form with the same organization name and asserts the server rejects it with the inline message \"An organization with this name already exists\". Proves the case-insensitive `ilike` duplicate-name guard in new-child.remote.ts is active end-to-end — not just at the form schema level.",
      "startedAt": "2026-04-23T03:45:40.836Z",
      "finishedAt": "2026-04-23T03:45:41.547Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-05-duplicate-name-guard.webm"
    },
    {
      "name": "Step 6: New distributor in list",
      "status": "pass",
      "description": "Step 6: New distributor in list",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-06-new-distributor-in-list.png"
      ],
      "explanation": "After creation, the new distributor organization (\"New Medical Supplies Inc.\") appears alongside the existing StellarTech in the downstream organizations list, confirming the relationship was persisted correctly.",
      "startedAt": "2026-04-23T03:45:46.551Z",
      "finishedAt": "2026-04-23T03:45:46.551Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-06-verify-new-distributor.webm"
    },
    {
      "name": "Step 7: Members page",
      "status": "pass",
      "description": "Step 7: Members page",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-07-members-page.png"
      ],
      "explanation": "Navigates to the Members settings page and confirms it loads with an existing member table and the \"Invite Member\" button visible. Proves the admin has the manage_users permission required to send invitations.",
      "startedAt": "2026-04-23T03:45:51.610Z",
      "finishedAt": "2026-04-23T03:45:51.610Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-07-members-page.webm"
    },
    {
      "name": "Step 8: Invite member",
      "status": "pass",
      "description": "Step 8: Invite member",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-08-invite-form-open.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-08-role-assigned.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-08-invite-submitted.png"
      ],
      "explanation": "Opens the Invite Member form, fills in the new member's name and email, and explicitly selects the \"ZuriMED Admin\" role from the role dropdown. Submits the invitation and verifies the form resets on success. The specific role picked here is asserted in DB check 8 so a silent regression (e.g. hardcoding the role on the server) is caught.",
      "expectedEmailTemplates": [
        "Verify your DeviceFlow"
      ],
      "startedAt": "2026-04-23T03:45:57.648Z",
      "finishedAt": "2026-04-23T03:46:04.481Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-08-invite-member.webm"
    },
    {
      "name": "Step 9: Member in list",
      "status": "pass",
      "description": "Step 9: Member in list",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-09-member-in-list.png"
      ],
      "explanation": "After invitation, the new member (\"Jane Doe\") appears in the members list with their email address visible, confirming the invitation was recorded and the member is searchable from the admin interface.",
      "startedAt": "2026-04-23T03:46:10.492Z",
      "finishedAt": "2026-04-23T03:46:10.492Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-09-verify-member.webm"
    },
    {
      "name": "Step 10: Member details",
      "status": "pass",
      "description": "Step 10: Member details",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-10-member-details-page.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-10-member-roles.png"
      ],
      "explanation": "Opens the member detail page for the invited user and verifies the Roles section is present. Confirms that role assignments made during invitation are accessible and visible to administrators.",
      "startedAt": "2026-04-23T03:46:16.137Z",
      "finishedAt": "2026-04-23T03:46:16.184Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-10-member-details.webm"
    },
    {
      "name": "Step 11: Admin overview",
      "status": "pass",
      "description": "Step 11: Admin overview",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-11-all-distributors.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-11-all-members.png"
      ],
      "explanation": "Final admin view showing both the full distributor list (StellarTech + new distributor) and the complete member roster. Provides end-to-end evidence that the entire distributor onboarding workflow — from agency creation through member invitation and role assignment — is operational.",
      "startedAt": "2026-04-23T03:46:21.168Z",
      "finishedAt": "2026-04-23T03:46:23.814Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-11-admin-overview.webm"
    },
    {
      "name": "Step 12: Distributor first login",
      "status": "pass",
      "description": "Step 12: Distributor first login",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-12-password-form.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/step-12-landing-page.png"
      ],
      "explanation": "Switches to the distributor invitee's perspective in a fresh browser context. Reads the verification email captured during step 4, extracts the `/verify-email?requestId=…&code=…` link, and navigates to it. The server auto-verifies the code and redirects through the password-reset flow, where the invitee sets an initial password and lands on the app home page. Proves the invitation link is functional from the recipient's point of view, not just from the admin's.",
      "startedAt": "2026-04-23T03:46:30.185Z",
      "finishedAt": "2026-04-23T03:46:34.032Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/videos/step-12-distributor-first-login.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "New distributor organization created",
      "query": "SELECT id, name, created_at\n      FROM organizations\n      WHERE name = $1",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "name": "New Medical Supplies Inc.",
          "created_at": "2026-04-23T03:45:33.904Z"
        }
      ],
      "assertion": "Organization \"New Medical Supplies Inc.\" should exist in the organizations table"
    },
    {
      "name": "Distributor relationship established",
      "query": "SELECT\n        r.parent_organization_id,\n        r.child_organization_id,\n        r.relationship_type,\n        p.name as parent_name,\n        c.name as child_name\n      FROM organization_relationships r\n      JOIN organizations p ON p.id = r.parent_organization_id\n      JOIN organizations c ON c.id = r.child_organization_id\n      WHERE r.parent_organization_id = $1\n        AND c.name = $2",
      "status": "pass",
      "rows": [
        {
          "parent_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "child_organization_id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "relationship_type": "distributor",
          "parent_name": "ZuriMED",
          "child_name": "New Medical Supplies Inc."
        }
      ],
      "assertion": "A distributor relationship should exist between ZuriMED and New Medical Supplies Inc."
    },
    {
      "name": "Invited distributor user created",
      "query": "SELECT id, email, name, created_at\n      FROM users\n      WHERE email = $1",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-6ace-7c25-ac42-eda8884f37d1",
          "email": "test-distributor@example.com",
          "name": "John Smith",
          "created_at": "2026-04-23T03:45:33.902Z"
        }
      ],
      "assertion": "User with email test-distributor@example.com should exist in the users table"
    },
    {
      "name": "Distributor user has expected role assigned",
      "query": "SELECT\n        ur.user_id,\n        ur.role_id,\n        ur.organization_id,\n        r.name as role_name,\n        u.email,\n        o.name as org_name\n      FROM user_roles ur\n      JOIN users u ON u.id = ur.user_id\n      JOIN roles r ON r.id = ur.role_id\n      JOIN organizations o ON o.id = ur.organization_id\n      WHERE u.email = $1\n        AND o.name = $2",
      "status": "pass",
      "rows": [
        {
          "user_id": "019db871-6ace-7c25-ac42-eda8884f37d1",
          "role_id": "24ee9b94-92a6-4bd4-89e6-48d4f19cfdbe",
          "organization_id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "role_name": "Administrator (preset)",
          "email": "test-distributor@example.com",
          "org_name": "New Medical Supplies Inc."
        }
      ],
      "assertion": "User test-distributor@example.com should have role \"Administrator (preset)\" in New Medical Supplies Inc. (hardcoded at new-child.remote.ts as globalOrgAdminRoleId)"
    },
    {
      "name": "User is member of distributor org",
      "query": "SELECT\n        om.user_id,\n        om.organization_id,\n        om.active,\n        u.email,\n        o.name as org_name\n      FROM organization_members om\n      JOIN users u ON u.id = om.user_id\n      JOIN organizations o ON o.id = om.organization_id\n      WHERE u.email = $1\n        AND o.name = $2",
      "status": "pass",
      "rows": [
        {
          "user_id": "019db871-6ace-7c25-ac42-eda8884f37d1",
          "organization_id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "active": true,
          "email": "test-distributor@example.com",
          "org_name": "New Medical Supplies Inc."
        }
      ],
      "assertion": "User test-distributor@example.com should be a member of New Medical Supplies Inc."
    },
    {
      "name": "Representation relationship created",
      "query": "SELECT\n        orr.id,\n        orr.user_id,\n        orr.approving_organization_id,\n        orr.requesting_organization_id,\n        orr.status,\n        orr.representative_type,\n        u.email,\n        ao.name as approving_org,\n        ro.name as requesting_org\n      FROM organization_representation_relationships orr\n      JOIN users u ON u.id = orr.user_id\n      JOIN organizations ao ON ao.id = orr.approving_organization_id\n      JOIN organizations ro ON ro.id = orr.requesting_organization_id\n      WHERE u.email = $1",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-6af3-7bc1-83e2-9b20e8b3232e",
          "user_id": "019db871-6ace-7c25-ac42-eda8884f37d1",
          "approving_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "requesting_organization_id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "status": "active",
          "representative_type": "salesperson",
          "email": "test-distributor@example.com",
          "approving_org": "ZuriMED",
          "requesting_org": "New Medical Supplies Inc."
        }
      ],
      "assertion": "A representation relationship should exist for test-distributor@example.com (created via \"Add as representative\" checkbox)"
    },
    {
      "name": "Submitted Rep ID persisted for invited user",
      "query": "SELECT\n        rwci.id,\n        rwci.organization_id,\n        rwci.contact_id,\n        rwci.id_type,\n        rwci.value,\n        u.email,\n        o.name as org_name\n      FROM real_world_contact_ids rwci\n      JOIN contacts c ON c.id = rwci.contact_id\n      JOIN users u ON u.id = c.user_id\n      JOIN organizations o ON o.id = rwci.organization_id\n      WHERE u.email = $1\n        AND o.name = $2",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-6af1-7d68-94e0-a15bd635c0bd",
          "organization_id": "019db871-6ad0-78b9-88d0-1a0a769394fd",
          "contact_id": "019db871-6ad3-7057-bf8f-1361ee09c9dc",
          "id_type": "zurimed_rep_id",
          "value": "TEST-REP-063",
          "email": "test-distributor@example.com",
          "org_name": "New Medical Supplies Inc."
        }
      ],
      "assertion": "Rep ID \"TEST-REP-063\" submitted through the new-distributor form should be stored in real_world_contact_ids for test-distributor@example.com scoped to New Medical Supplies Inc."
    },
    {
      "name": "Submitted Trunk ID persisted for invited user",
      "query": "SELECT\n        rwli.id,\n        rwli.organization_id,\n        rwli.location_id,\n        rwli.id_type,\n        rwli.value,\n        u.email,\n        o.name as org_name\n      FROM real_world_location_ids rwli\n      JOIN real_world_locations rwl ON rwl.id = rwli.location_id\n      JOIN contacts c ON c.default_location_id = rwl.id\n      JOIN users u ON u.id = c.user_id\n      JOIN organizations o ON o.id = rwli.organization_id\n      WHERE u.email = $1\n        AND o.id = $2",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-6af2-708c-9ab1-ae40de821be0",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "location_id": "019db871-6ae3-7fd5-a11e-994d6fb5b94b",
          "id_type": "TRUNK_LOCATION_ID",
          "value": "TEST-TRUNK-063",
          "email": "test-distributor@example.com",
          "org_name": "ZuriMED"
        }
      ],
      "assertion": "Trunk ID \"TEST-TRUNK-063\" submitted through the new-distributor form should be stored in real_world_location_ids scoped to the manufacturer org (ZuriMED)"
    },
    {
      "name": "Invited member exists in ZuriMED org",
      "query": "SELECT\n        u.id, u.email, u.name,\n        om.active,\n        o.name as org_name\n      FROM users u\n      JOIN organization_members om ON om.user_id = u.id\n      JOIN organizations o ON o.id = om.organization_id\n      WHERE u.email = $1\n        AND om.organization_id = $2",
      "status": "pass",
      "rows": [
        {
          "id": "019db871-e1ce-7006-aaf8-b2cafb26bdf5",
          "email": "jane.doe.test@zurimed.com",
          "name": "Jane Doe",
          "active": true,
          "org_name": "ZuriMED"
        }
      ],
      "assertion": "User jane.doe.test@zurimed.com should be a member of ZuriMED"
    },
    {
      "name": "Invited member has the role selected in the form",
      "query": "SELECT\n        ur.user_id,\n        ur.role_id,\n        r.name as role_name,\n        u.email,\n        o.name as org_name\n      FROM user_roles ur\n      JOIN users u ON u.id = ur.user_id\n      JOIN roles r ON r.id = ur.role_id\n      JOIN organizations o ON o.id = ur.organization_id\n      WHERE u.email = $1\n        AND ur.organization_id = $2",
      "status": "pass",
      "rows": [
        {
          "user_id": "019db871-e1ce-7006-aaf8-b2cafb26bdf5",
          "role_id": "39d0e1f2-a3b4-5678-3456-789012345678",
          "role_name": "ZuriMED Admin",
          "email": "jane.doe.test@zurimed.com",
          "org_name": "ZuriMED"
        }
      ],
      "assertion": "User jane.doe.test@zurimed.com should have role \"ZuriMED Admin\" in ZuriMED (this is the role the spec picks from the Invite Member dropdown)"
    },
    {
      "name": "Distributor org has feature flags",
      "query": "SELECT\n        ff.id as flag_id,\n        ff.value,\n        o.name as org_name\n      FROM feature_flags ff\n      JOIN organizations o ON o.id = ff.organization_id\n      WHERE o.name = $1\n      ORDER BY ff.id",
      "status": "pass",
      "rows": [
        {
          "flag_id": "billing",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "home_screen_prototype",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "inbox_checklist_items",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "inbox_tickets",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "inventory_snapshots",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "order_requests",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "org_type:distributor",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "organization_representation",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "sales_accounts",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        },
        {
          "flag_id": "workflow_visualization",
          "value": true,
          "org_name": "New Medical Supplies Inc."
        }
      ],
      "assertion": "New Medical Supplies Inc. should have feature flags propagated from parent org"
    },
    {
      "name": "manufacturer_can_create_distributors flag enabled",
      "query": "SELECT id, organization_id, value\n      FROM feature_flags\n      WHERE id = 'manufacturer_can_create_distributors'\n        AND organization_id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "manufacturer_can_create_distributors",
          "organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "value": true
        }
      ],
      "assertion": "manufacturer_can_create_distributors feature flag should be enabled for ZuriMED"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z",
  "auditStartTime": "2026-04-23T03:45:05.195Z",
  "emailEvidence": [
    {
      "subject": "Representative Account Approved - ZuriMED",
      "template": "Representative_Account_Approved_-_ZuriMED",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/emails/2026-04-23T03-45-33-957Z-Representative_Account_Approved_-_ZuriMED.png"
    },
    {
      "subject": "Verify your DeviceFlow account",
      "template": "Verify_your_DeviceFlow_account",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/emails/2026-04-23T03-45-35-487Z-Verify_your_DeviceFlow_account.png"
    },
    {
      "subject": "Verify your DeviceFlow account",
      "template": "Verify_your_DeviceFlow_account",
      "screenshotPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-063-distributor-onboarding/2026-04-23T03-45-07-126Z/screenshots/emails/2026-04-23T03-46-06-043Z-Verify_your_DeviceFlow_account.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:45:13.422Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "mark.manufacturer@zurimed.com",
      "userId": "d4e5f6a7-b8c9-0123-def1-234567890123",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "mark.manufacturer@zurimed.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:45:34.457Z",
      "eventType": "user_log",
      "action": "rep_onboarding_request_approved",
      "userEmail": "test-distributor@example.com",
      "userId": "019db871-6ace-7c25-ac42-eda8884f37d1",
      "organizationName": "New Medical Supplies Inc.",
      "organizationId": "019db871-6ad0-78b9-88d0-1a0a769394fd",
      "objectId": "019db871-6af3-7bc1-83e2-9b20e8b3232e",
      "secondaryObjectId": "019db871-6af3-7bc1-83e2-9b20e8b3232e",
      "payload": {
        "userId": "019db871-6ace-7c25-ac42-eda8884f37d1",
        "userName": "John Smith",
        "distributorOrganizationId": "019db871-6ad0-78b9-88d0-1a0a769394fd",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": "/settings/org-relationships/new-child",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:45:34.485Z",
      "eventType": "transactional_email",
      "action": "rep_created",
      "userEmail": null,
      "userId": null,
      "organizationName": "New Medical Supplies Inc.",
      "organizationId": "019db871-6ad0-78b9-88d0-1a0a769394fd",
      "objectId": "019db871-6af3-7bc1-83e2-9b20e8b3232e",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "test-distributor@example.com"
        ],
        "s3Path": "email-audit/019db871-6ad0-78b9-88d0-1a0a769394fd/019db871-6b09-7ec6-9773-2cf60d3d9e2b/",
        "subject": "Representative Account Approved - ZuriMED",
        "messageId": "dev-console-log",
        "relatedEntityType": "organization_representation_relationship"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:45:35.561Z",
      "eventType": "transactional_email",
      "action": "verify_email",
      "userEmail": null,
      "userId": null,
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db871-6ace-7c25-ac42-eda8884f37d1",
      "secondaryObjectId": null,
      "payload": {
        "to": "test-distributor@example.com",
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/019db871-711c-7c65-af0f-05e6d6b845d0/",
        "subject": "Verify your DeviceFlow account",
        "messageId": "dev-console-log",
        "relatedEntityType": "user"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:46:06.086Z",
      "eventType": "transactional_email",
      "action": "verify_email",
      "userEmail": null,
      "userId": null,
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db871-e1ce-7006-aaf8-b2cafb26bdf5",
      "secondaryObjectId": null,
      "payload": {
        "to": "jane.doe.test@zurimed.com",
        "s3Path": "email-audit/a1b2c3d4-e5f6-7890-abcd-ef1234567890/019db871-e860-7168-b733-07a5615a9375/",
        "subject": "Verify your DeviceFlow account",
        "messageId": "dev-console-log",
        "relatedEntityType": "user"
      },
      "route": null,
      "traceId": null
    }
  ],
  "auditQuery": "SELECT\n    ae.created_at,\n    ae.event_type,\n    ae.action,\n    ae.user_id,\n    u.email AS user_email,\n    ae.organization_id,\n    o.name AS organization_name,\n    ae.object_id,\n    ae.secondary_object_id,\n    ae.payload,\n    ae.route,\n    ae.trace_id\n  FROM audit_events ae\n  LEFT JOIN users u ON u.id = ae.user_id\n  LEFT JOIN organizations o ON o.id = ae.organization_id\n  WHERE ae.created_at >= $1\n    AND ae.organization_id = ANY($2::uuid[])\n  ORDER BY ae.created_at ASC",
  "auditAssertions": [
    {
      "stepName": "Step 4: Create distributor",
      "expectedAction": "user_log:rep_onboarding_request_approved",
      "found": true
    }
  ],
  "emailAssertions": [
    {
      "stepName": "Step 4: Create distributor",
      "expectedTemplate": "Verify your DeviceFlow",
      "found": true
    },
    {
      "stepName": "Step 4: Create distributor",
      "expectedTemplate": "Representative Account Approved",
      "found": true
    },
    {
      "stepName": "Step 8: Invite member",
      "expectedTemplate": "Verify your DeviceFlow",
      "found": true
    }
  ]
}