{
  "ursId": "URS-034",
  "title": "Export Order and Inventory History for Audits",
  "timestamp": "2026-04-23T03:40:59.668Z",
  "durationMs": 67466,
  "config": {
    "inboxUrl": "http://localhost:64119",
    "dbHost": "localhost",
    "dbPort": 64120,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Exports page overview",
      "status": "pass",
      "description": "Step 1: Exports page overview",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-01-exports-page-overview.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-01-exports-page-all-cards.png"
      ],
      "explanation": "Logs in as an admin user (Dan Distributor) and navigates to the /exports page, confirming that export options for Orders and Inventory are visible to authorized users.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-04-23T03:41:11.295Z",
      "finishedAt": "2026-04-23T03:41:14.181Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-01-exports-page.webm"
    },
    {
      "name": "Step 2: Export order history",
      "status": "pass",
      "description": "Step 2: Export order history",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-02-before-order-export.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-02-orders-csv-content.png"
      ],
      "explanation": "Downloads the Orders CSV export, verifying that order history can be exported for audits and that the file contains the expected audit columns including order numbers, status, and creation dates.",
      "startedAt": "2026-04-23T03:41:22.128Z",
      "finishedAt": "2026-04-23T03:41:27.920Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-02-export-orders.webm"
    },
    {
      "name": "Step 3: Order export verification",
      "status": "pass",
      "description": "Step 3: Order export verification",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-03-orders-verification.png"
      ],
      "explanation": "Verifies the downloaded order CSV contains all required audit fields with non-empty values, confirming the export provides complete audit-ready data.",
      "startedAt": "2026-04-23T03:41:30.901Z",
      "finishedAt": "2026-04-23T03:41:30.901Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-03-verify-orders.webm"
    },
    {
      "name": "Step 4: Export inventory",
      "status": "pass",
      "description": "Step 4: Export inventory",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-04-after-inventory-export.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-04-inventory-csv-content.png"
      ],
      "explanation": "Downloads the Inventory CSV export, verifying that inventory history is exportable for audits with the expected columns including location and quantity data.",
      "startedAt": "2026-04-23T03:41:43.948Z",
      "finishedAt": "2026-04-23T03:41:44.503Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-04-export-inventory.webm"
    },
    {
      "name": "Step 5: Date range filtering",
      "status": "pass",
      "description": "Step 5: Date range filtering",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-05-date-range-comparison.png"
      ],
      "explanation": "Confirms that the date range filter on the orders export works correctly: a narrow historical range returns zero results while a wide range spanning the test data returns the expected records.",
      "startedAt": "2026-04-23T03:41:50.674Z",
      "finishedAt": "2026-04-23T03:41:50.674Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-05-date-range-filter.webm"
    },
    {
      "name": "Step 6: Permission restriction",
      "status": "pass",
      "description": "Step 6: Permission restriction",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/screenshots/step-06-rep-exports-restricted.png"
      ],
      "explanation": "Logs in as Ryan Delauintana (Sales Rep without export permissions) and verifies that the /exports page and the direct CSV endpoint deny access, enforcing role-based export access control.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-04-23T03:42:04.332Z",
      "finishedAt": "2026-04-23T03:42:04.332Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z/videos/step-06-permission-restriction.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Exports feature flag enabled",
      "query": "SELECT id, value FROM feature_flags\n      WHERE id = 'exports' AND organization_id = $1",
      "status": "pass",
      "rows": [
        {
          "id": "exports",
          "value": true
        }
      ],
      "assertion": "The \"exports\" feature flag should be enabled for StellarTech"
    },
    {
      "name": "Admin role has exports:access",
      "query": "SELECT p.permission FROM permissions p\n      WHERE p.actor_id = $1 AND p.permission = 'exports:access'",
      "status": "pass",
      "rows": [
        {
          "permission": "exports:access"
        }
      ],
      "assertion": "The StellarTech Admin role should have exports:access permission"
    },
    {
      "name": "Sales rep role lacks exports:access",
      "query": "SELECT p.permission FROM permissions p\n      WHERE p.actor_id = $1 AND p.permission = 'exports:access'",
      "status": "pass",
      "rows": [],
      "assertion": "The Sales Rep role should NOT have exports:access permission"
    },
    {
      "name": "Order requests exist for organization",
      "query": "SELECT COUNT(*) as count,\n        MIN(created_at) as oldest_order,\n        MAX(created_at) as newest_order\n      FROM order_requests\n      WHERE requesting_organization_id = $1 OR fulfilling_organization_id = $1",
      "status": "pass",
      "rows": [
        {
          "count": "3",
          "oldest_order": "2026-03-24T03:40:59.719Z",
          "newest_order": "2026-04-18T03:40:59.719Z"
        }
      ],
      "assertion": "At least one order request should exist for StellarTech"
    },
    {
      "name": "Inventory items exist for organization",
      "query": "SELECT COUNT(*) as count\n      FROM inventory_items\n      WHERE organization_id = $1\n        AND (quantity_ready > 0 OR quantity_backordered > 0 OR quantity_in_transit > 0)",
      "status": "pass",
      "rows": [
        {
          "count": "4"
        }
      ],
      "assertion": "At least one inventory item with positive quantity should exist for StellarTech"
    },
    {
      "name": "Admin user has Admin role",
      "query": "SELECT u.email, u.name, r.name as role_name, r.id as role_id\n      FROM users u\n      JOIN user_roles ur ON ur.user_id = u.id\n      JOIN roles r ON r.id = ur.role_id\n      WHERE u.id = $1 AND ur.organization_id = $2",
      "status": "pass",
      "rows": [
        {
          "email": "dan.distributor@stellartech.com",
          "name": "Dan Distributor",
          "role_name": "StellarTech Admin",
          "role_id": "40e1f2a3-b4c5-6789-4567-890123456789"
        }
      ],
      "assertion": "Dan Distributor should have the Admin role for StellarTech"
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-034-export-audit-history/2026-04-23T03-40-59-667Z",
  "auditStartTime": "2026-04-23T03:40:57.813Z",
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:41:05.842Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "dan.distributor@stellartech.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "dan.distributor@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:41:16.899Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "dan.distributor@stellartech.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "dan.distributor@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:41:35.888Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "dan.distributor@stellartech.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "dan.distributor@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:41:47.269Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "dan.distributor@stellartech.com",
      "userId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "dan.distributor@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:41:58.140Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "ryan.delauintana@stellartech.com",
      "userId": "28c9d0e1-f2a3-4567-2345-678901234567",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "ryan.delauintana@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    }
  ],
  "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 1: Exports page overview",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 6: Permission restriction",
      "expectedAction": "user_log:user:login",
      "found": true
    }
  ],
  "emailAssertions": []
}