{
  "ursId": "URS-039",
  "title": "Returns form supports multiple item questionnaires",
  "timestamp": "2026-08-03T23:04:07.576Z",
  "durationMs": 63822,
  "config": {
    "inboxUrl": "http://localhost:44587",
    "dbHost": "localhost",
    "dbPort": 42531,
    "dbName": "cc_repinbox_dev"
  },
  "setup": {
    "status": "pass"
  },
  "scenarios": [
    {
      "name": "Step 1: Login and navigate to returns",
      "status": "pass",
      "description": "Step 1: Login and navigate to returns",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-01-logged-in.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-01-returns-list.png"
      ],
      "explanation": "A sales rep logs in and navigates to the returns list. This verifies the returns feature is accessible and that the rep's permissions permit viewing returns.",
      "expectedAuditActions": [
        "user_log:user:login"
      ],
      "startedAt": "2026-08-03T23:04:13.639Z",
      "finishedAt": "2026-08-03T23:04:16.659Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/videos/step-01-navigate-returns.webm"
    },
    {
      "name": "Step 2: Submit return request with multiple item questionnaires",
      "status": "pass",
      "description": "Step 2: Submit return request with multiple item questionnaires",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-new-return-form.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-products-selected.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-per-item-cards-rendered.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-per-item-questions-filled.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-review.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-02-submission-success.png"
      ],
      "explanation": "The rep completes the multi-step return form with two different products. Each product has its own return question, so the per-item questionnaire step renders one distinct card per returned item. The rep fills a different answer per item and submits the return. This verifies the URS-039 requirement that the form supports submitting multiple individual item questionnaires.",
      "expectedAuditActions": [
        "return_request:created"
      ],
      "startedAt": "2026-08-03T23:04:22.949Z",
      "finishedAt": "2026-08-03T23:04:51.682Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/videos/step-02-submit-return.webm"
    },
    {
      "name": "Step 3: View output form for each returned item",
      "status": "pass",
      "description": "Step 3: View output form for each returned item",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-03-return-detail-top.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-03-return-detail-items-visible.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-03-return-detail-bottom.png"
      ],
      "explanation": "Immediately after submission, the rep opens the return detail page — the \"output form\" that URS-039 asks the system to generate per returned item. The detail page shows each item with its product, lot number, and the per-item questionnaire response captured on the previous step. This is the primary URS-039 evidence that one form is generated per returned item.",
      "startedAt": "2026-08-03T23:04:58.599Z",
      "finishedAt": "2026-08-03T23:05:00.977Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/videos/step-03-view-output-form.webm"
    },
    {
      "name": "Step 4: Verify return appears in returns list",
      "status": "pass",
      "description": "Step 4: Verify return appears in returns list",
      "screenshots": [
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-04-returns-list-with-return.png",
        "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/step-04-return-detail-submitted.png"
      ],
      "explanation": "The rep returns to the Returns list, confirms the new return appears, and opens it to verify the Submitted status on the detail page. This verifies the system persisted the return and that it is discoverable for follow-up actions.",
      "startedAt": "2026-08-03T23:05:06.850Z",
      "finishedAt": "2026-08-03T23:05:09.024Z",
      "videoPath": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/videos/step-04-verify-in-list.webm"
    }
  ],
  "dbValidations": [
    {
      "name": "Return created for Corveta → Vantis",
      "query": "SELECT id, return_number, status, date_of_event, notes, created_at\n    FROM returns\n    WHERE sales_organization_id = $1\n      AND manufacturer_organization_id = $2\n      AND notes LIKE '%URS-039%'\n      AND created_at > NOW() - INTERVAL '2 hours'\n    ORDER BY created_at DESC",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-7042-7581-9a70-ba57b6a4f66f",
          "return_number": "RET-1",
          "status": "submitted",
          "date_of_event": "2026-08-03T00:00:00.000Z",
          "notes": "URS-039 validation run — submitted at 2026-08-03T23:04:31.037Z",
          "created_at": "2026-08-03T23:04:51.481Z"
        }
      ],
      "assertion": "A URS-039 return with status=submitted should exist (marker: \"URS-039 validation run\")."
    },
    {
      "name": "Return number generated",
      "query": "-- return_number from the row above",
      "status": "pass",
      "rows": [
        {
          "return_number": "RET-1"
        }
      ],
      "assertion": "Return should have a return number in RET-XXXXX format."
    },
    {
      "name": "One return_items row per returned product",
      "query": "SELECT ri.id, ri.product_id, op.sku, op.title, ri.lot_number,\n      ri.return_item_number, ri.created_at\n    FROM return_items ri\n    JOIN org_products op ON op.id = ri.product_id\n    WHERE ri.return_id = $1\n    ORDER BY op.sku, ri.lot_number",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-7047-7764-aea4-38f46b578784",
          "product_id": "01989ca1-f2f8-7ab7-8269-7179342797cc",
          "sku": "LL516SNA",
          "title": "LiraLock® Instrument SN",
          "lot_number": "URS039-FL-001",
          "return_item_number": "RET-1-LL516SNA-1",
          "created_at": "2026-08-03T23:04:51.481Z"
        },
        {
          "id": "019fc9df-7047-7764-aea4-38f34562495e",
          "product_id": "01989ca2-6a54-7834-8376-06a0251bacd8",
          "sku": "NP019N1A",
          "title": "NovaPatch® PET",
          "lot_number": "URS039-SP-001",
          "return_item_number": "RET-1-NP019N1A-1",
          "created_at": "2026-08-03T23:04:51.481Z"
        }
      ],
      "assertion": "Expected 2 return_items rows (one per returned product)."
    },
    {
      "name": "Each returned item has its own distinct lot number",
      "query": "-- Expected lot numbers: URS039-SP-001, URS039-FL-001",
      "status": "pass",
      "rows": [
        {
          "lot_number": "URS039-FL-001",
          "sku": "LL516SNA",
          "title": "LiraLock® Instrument SN"
        },
        {
          "lot_number": "URS039-SP-001",
          "sku": "NP019N1A",
          "title": "NovaPatch® PET"
        }
      ],
      "assertion": "All expected per-item lot numbers should appear exactly once, proving per-item data was stored."
    },
    {
      "name": "Each returned item has its own questionnaire response",
      "query": "SELECT riqr.id, riqr.return_item_id, riqr.question_version_id,\n      riqr.response_text, ri.lot_number, rpqv.question_text, rpqv.question_type\n    FROM return_item_question_responses riqr\n    JOIN return_items ri ON ri.id = riqr.return_item_id\n    JOIN return_product_question_versions rpqv ON rpqv.id = riqr.question_version_id\n    WHERE ri.return_id = $1\n    ORDER BY ri.lot_number",
      "status": "pass",
      "rows": [
        {
          "id": "019fc9df-704a-7776-b942-beca280eca1a",
          "return_item_id": "019fc9df-7047-7764-aea4-38f46b578784",
          "question_version_id": "03922222-2222-4222-8222-222222222222",
          "response_text": "URS-039 LiraLock: instrument returned unopened, customer downgraded procedure plan and no longer needs the unit.",
          "lot_number": "URS039-FL-001",
          "question_text": "Describe the condition and reason for returning this LiraLock unit",
          "question_type": "text"
        },
        {
          "id": "019fc9df-704a-7776-b942-bec92671952b",
          "return_item_id": "019fc9df-7047-7764-aea4-38f34562495e",
          "question_version_id": "03911111-2222-4222-8222-222222222222",
          "response_text": "URS-039 NovaPatch: outer seal ruptured on arrival, adhesive layer contaminated and unusable.",
          "lot_number": "URS039-SP-001",
          "question_text": "Describe the defect observed for this NovaPatch unit",
          "question_type": "text"
        }
      ],
      "assertion": "Every return_items row should have at least one return_item_question_responses row, proving one questionnaire was generated per returned item."
    },
    {
      "name": "Per-item answers persisted match the spec input",
      "query": "-- compares response_text per lot against RETURN_ITEMS definitions",
      "status": "pass",
      "rows": [
        {
          "lot_number": "URS039-FL-001",
          "question_text": "Describe the condition and reason for returning this LiraLock unit",
          "response_text": "URS-039 LiraLock: instrument returned unopened, customer downgraded procedure plan and no longer needs the unit.",
          "question_version_id": "03922222-2222-4222-8222-222222222222"
        },
        {
          "lot_number": "URS039-SP-001",
          "question_text": "Describe the defect observed for this NovaPatch unit",
          "response_text": "URS-039 NovaPatch: outer seal ruptured on arrival, adhesive layer contaminated and unusable.",
          "question_version_id": "03911111-2222-4222-8222-222222222222"
        }
      ],
      "assertion": "Each item's saved response should be distinct and match the answer the spec entered for that product."
    },
    {
      "name": "Return linked to Vantis (manufacturer) and Corveta (distributor)",
      "query": "SELECT r.manufacturer_organization_id, r.sales_organization_id\n    FROM returns r\n    WHERE r.id = $1",
      "status": "pass",
      "rows": [
        {
          "manufacturer_organization_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
          "sales_organization_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901"
        }
      ],
      "assertion": "Return should be linked to Vantis (manufacturer) and Corveta (distributor)."
    }
  ],
  "overallStatus": "pass",
  "outputDir": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z",
  "auditStartTime": "2026-08-03T23:04:05.749Z",
  "emailEvidence": [
    {
      "subject": "Return Submitted - RET-1",
      "template": "Return_Submitted_-_RET-1",
      "screenshotPath": "/home/runner/_work/code/code/validation_test_results/urs-039-return-submission-processing/2026-08-03T23-04-07-576Z/screenshots/emails/2026-08-03T23-04-55-381Z-Return_Submitted_-_RET-1.png"
    }
  ],
  "auditEventEvidence": [
    {
      "createdAt": "2026-08-03T23:04:11.956Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-08-03T23:04:18.465Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-08-03T23:04:51.481Z",
      "eventType": "decision",
      "action": "create_replacement_order_on_return",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019fc9df-7042-7581-9a70-ba57b6a4f66f",
      "secondaryObjectId": null,
      "payload": {
        "reason": "manufacturer_setting_disabled",
        "performed": false,
        "entityType": "return"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:51.481Z",
      "eventType": "return_request",
      "action": "created",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Vantis",
      "organizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "objectId": "019fc9df-7042-7581-9a70-ba57b6a4f66f",
      "secondaryObjectId": null,
      "payload": {
        "itemCount": 2,
        "returnNumber": "RET-1",
        "salesOrganizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
        "manufacturerOrganizationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:04:53.455Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.com"
      },
      "route": "/login",
      "traceId": "00000000000000000000000000000000"
    },
    {
      "createdAt": "2026-08-03T23:04:55.419Z",
      "eventType": "transactional_email",
      "action": "return_submitted",
      "userEmail": null,
      "userId": null,
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": "019fc9df-7042-7581-9a70-ba57b6a4f66f",
      "secondaryObjectId": null,
      "payload": {
        "to": [
          "blair.bennett@corvetasurgical.com"
        ],
        "s3Path": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019fc9df-7f69-7388-9822-7219cd828939/",
        "subject": "Return Submitted - RET-1",
        "messageId": "dev-console-log",
        "attachmentFiles": [
          {
            "s3Key": "email-audit/b2c3d4e5-f6a7-8901-bcde-f12345678901/019fc9df-7f69-7388-9822-7219cd828939/attachments/1-RET-1-return-form-2026-08-03.pdf",
            "filename": "RET-1-return-form-2026-08-03.pdf"
          }
        ],
        "relatedEntityType": "return"
      },
      "route": null,
      "traceId": null
    },
    {
      "createdAt": "2026-08-03T23:05:04.000Z",
      "eventType": "user_log",
      "action": "user:login",
      "userEmail": "blair.bennett@corvetasurgical.com",
      "userId": "17b8c9d0-e1f2-3456-1234-567890123456",
      "organizationName": "Corveta Surgical Group",
      "organizationId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "objectId": null,
      "secondaryObjectId": null,
      "payload": {
        "email": "blair.bennett@corvetasurgical.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: Login and navigate to returns",
      "expectedAction": "user_log:user:login",
      "found": true
    },
    {
      "stepName": "Step 2: Submit return request with multiple item questionnaires",
      "expectedAction": "return_request:created",
      "found": true
    }
  ],
  "emailAssertions": []
}