{
  "ursId": "URS-018",
  "title": "Upload PO to an Existing Order",
  "timestamp": "2026-04-23T03:36:53.669Z",
  "durationMs": 60126,
  "config": {
    "inboxUrl": "http://localhost:62804",
    "dbHost": "localhost",
    "dbPort": 62805,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Create order without PO",
      "status": "pass",
      "description": "Step 1: Create order without PO",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-01-order-type-selected.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-01-products-no-po.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-01-review.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-01-order-submitted.png"
      ],
      "explanation": "Creates a direct order through the full multi-step form without attaching any PO document during submission. This proves the system accepts orders in the absence of PO documentation and that the upload step is optional at order creation time.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-04-23T03:37:04.796Z",
      "finishedAt": "2026-04-23T03:37:17.338Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/videos/step-01-create-order.webm"
    },
    {
      "name": "Step 2: No documents linked",
      "status": "pass",
      "description": "Step 2: No documents linked",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-02-no-documents.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-02-upload-area-visible.png"
      ],
      "explanation": "Navigates to the order detail page of the newly created order and confirms the Source Documents section displays \"no linked documents yet\" alongside a visible PO upload area. This proves the UI correctly exposes the post-creation upload capability at the right location.",
      "startedAt": "2026-04-23T03:37:27.776Z",
      "finishedAt": "2026-04-23T03:37:31.160Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/videos/step-02-no-documents.webm"
    },
    {
      "name": "Step 3: PO document attached",
      "status": "pass",
      "description": "Step 3: PO document attached",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-03-po-document-visible.png",
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-03-document-details.png"
      ],
      "explanation": "Uses the file uploader to attach test-po.pdf to the existing order via the Source Documents UI. After upload the \"no linked documents\" message disappears and the filename, uploader attribution, and a View link appear. This proves a PDF PO can be attached to an order after it has already been created.",
      "startedAt": "2026-04-23T03:37:39.494Z",
      "finishedAt": "2026-04-23T03:37:42.890Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/videos/step-03-po-attached.webm"
    },
    {
      "name": "Step 4: PO persists after reload",
      "status": "pass",
      "description": "Step 4: PO persists after reload",
      "screenshots": [
        "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/screenshots/step-04-po-persisted.png"
      ],
      "explanation": "Reloads the order detail page in a fresh browser context and confirms the attached PO document is still listed with its View link, and that the \"no linked documents\" message is absent. This proves the upload is durably stored and survives a full page reload.",
      "startedAt": "2026-04-23T03:37:50.316Z",
      "finishedAt": "2026-04-23T03:37:50.316Z",
      "videoPath": "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z/videos/step-04-verify-persistence.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Test order created",
      "query": "SELECT id, request_number, order_type, status, created_at\n      FROM order_requests\n      WHERE requested_by_user_id = $1\n        AND notes LIKE $2\n      ORDER BY created_at DESC\n      LIMIT 1",
      "status": "pass",
      "rows": [
        {
          "id": "019db869-d6cb-76d7-a35e-2487c170eecf",
          "request_number": "OR-1",
          "order_type": "direct",
          "status": "submitted",
          "created_at": "2026-04-23T03:37:17.244Z"
        }
      ],
      "assertion": "An order should have been created during the test"
    },
    {
      "name": "PO document linked to order",
      "query": "SELECT ord.id, ord.order_request_id, d.filename, d.mime_type, d.category, ord.created_at\n      FROM order_request_documents ord\n      JOIN documents d ON d.id = ord.document_id\n      WHERE ord.order_request_id IN (\n        SELECT id FROM order_requests\n        WHERE requested_by_user_id = $1\n          AND notes LIKE $2\n      )\n      ORDER BY ord.created_at DESC",
      "status": "pass",
      "rows": [
        {
          "id": "019db86a-2ca6-75a3-a374-ab7a76db98c1",
          "order_request_id": "019db869-d6cb-76d7-a35e-2487c170eecf",
          "filename": "test-po.pdf",
          "mime_type": "application/pdf",
          "category": "direct_order",
          "created_at": "2026-04-23T03:37:39.205Z"
        }
      ],
      "assertion": "At least one PO document should be linked to the test order"
    },
    {
      "name": "Document has correct category",
      "query": "SELECT d.id, d.filename, d.category, d.mime_type, d.size\n      FROM documents d\n      JOIN order_request_documents ord ON ord.document_id = d.id\n      WHERE ord.order_request_id IN (\n        SELECT id FROM order_requests\n        WHERE requested_by_user_id = $1\n          AND notes LIKE $2\n      )\n      ORDER BY d.created_at DESC\n      LIMIT 1",
      "status": "pass",
      "rows": [
        {
          "id": "019db86a-2ca5-7026-b1fd-f52d84b44cc3",
          "filename": "test-po.pdf",
          "category": "direct_order",
          "mime_type": "application/pdf",
          "size": 582
        }
      ],
      "assertion": "Uploaded PO document should have category \"direct_order\""
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/Users/jason/projects/casecohort/code/validation_test_results/urs-018-upload-po-existing-order/2026-04-23T03-36-53-667Z",
  "auditStartTime": "2026-04-23T03:36:51.749Z",
  "auditEventEvidence": [
    {
      "createdAt": "2026-04-23T03:36:56.103Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:37:17.244Z",
      "eventType": "decision",
      "action": "order_request_created",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "ZuriMED",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019db869-d6cb-76d7-a35e-2487c170eecf",
      "secondaryObjectId": null,
      "payload": {
        "reason": "Order request OR-1 created (importSource=manual)",
        "priority": "normal",
        "itemCount": 1,
        "orderType": "direct",
        "performed": true,
        "entityType": "order_request",
        "importSource": "manual",
        "requestNumber": "OR-1",
        "resolvedLocationId": "6ea3b4c5-d6e7-8901-6789-012345678901",
        "resolvedSalesAccountId": "fea7b8c9-d0e1-2345-0123-456789012345",
        "fulfillingOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "requestingOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-04-23T03:37:21.923Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:37:32.311Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@stellartech.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-04-23T03:37:44.232Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "bob.kauffman@stellartech.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "StellarTech Medical Solutions",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "bob.kauffman@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: Create order without PO",
      "expectedAction": "user_log:user:login",
      "found": true
    }
  ],
  "emailAssertions": [],
  "inputFiles": [
    {
      "name": "Sample Purchase Order (PO) Document",
      "description": "A sample PDF purchase order used in Step 3 to demonstrate attaching a PO document to an existing order. This file is uploaded via the UI in the test.",
      "path": "/Users/jason/projects/casecohort/code/testing/validations/urs-018-upload-po-existing-order/fixtures/test-po.pdf"
    }
  ]
}