{
  "id": "LC-PREVIEW-001",
  "name": "Lead Convert preview returns Opportunity Campaign attribution",
  "description": "POST /actions/standard/convertLead/preview/record-create-fields should execute the standard action registry, permission gate, Flow preview executor, and return the CampaignId assigned to the new Opportunity without performing conversion DML.",
  "setup": [
    {
      "type": "sql",
      "sql": "DELETE FROM `CampaignMember` WHERE Id = '00vPVW000000001AAA'",
      "expected_status": 200
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Campaign` WHERE Id = '701PVW000000001AAA'",
      "expected_status": 200
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Lead` WHERE Id = '00QPVW000000001AAA'",
      "expected_status": 200
    },
    {
      "type": "sql",
      "sql": "INSERT INTO `Campaign` (Id, Name, Type, Status, IsActive, AmountAllOpportunities, AmountWonOpportunities, NumberOfContacts, NumberOfConvertedLeads, NumberOfLeads, NumberOfOpportunities, NumberOfWonOpportunities, OwnerId, CreatedById, CreatedDate, LastModifiedById, LastModifiedDate, SystemModstamp, IsDeleted) VALUES ('701PVW000000001AAA', 'LC Preview Campaign', 'Email', 'In Progress', true, 0, 0, 0, 0, 0, 0, 0, '10000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000001', NOW(), '10000000-0000-0000-0000-000000000001', NOW(), NOW(), false)",
      "expected_status": 200,
      "id_var": "campaign_id",
      "id_value": "701PVW000000001AAA"
    },
    {
      "type": "sql",
      "sql": "INSERT INTO `Lead` (Id, FirstName, LastName, Company, Email, Status, IsConverted, OwnerId, CreatedById, CreatedDate, LastModifiedById, LastModifiedDate, SystemModstamp, IsDeleted) VALUES ('00QPVW000000001AAA', 'LCPreview', 'Attribution', 'LC Preview Co', 'lc-preview@example.com', 'Open', false, '10000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000001', NOW(), '10000000-0000-0000-0000-000000000001', NOW(), NOW(), false)",
      "expected_status": 200,
      "id_var": "lead_id",
      "id_value": "00QPVW000000001AAA"
    },
    {
      "type": "sql",
      "sql": "INSERT INTO `CampaignMember` (Id, CampaignId, LeadId, Status, CreatedById, CreatedDate, LastModifiedById, LastModifiedDate, SystemModstamp, IsDeleted) VALUES ('00vPVW000000001AAA', '701PVW000000001AAA', '00QPVW000000001AAA', 'Responded', '10000000-0000-0000-0000-000000000001', NOW(), '10000000-0000-0000-0000-000000000001', NOW(), NOW(), false)",
      "expected_status": 200,
      "id_var": "campaign_member_id",
      "id_value": "00vPVW000000001AAA"
    }
  ],
  "object": "LeadConvert",
  "method": "POST",
  "endpoint": "/services/data/v63.0/actions/standard/convertLead/preview/record-create-fields",
  "payload": {
    "inputs": [
      {
        "leadId": "{lead_id}",
        "convertedStatus": "Customer",
        "opportunityName": "LC Preview Opportunity {run_uuid}"
      }
    ],
    "recordCreateFields": [
      {
        "objectApiName": "Opportunity",
        "fieldApiName": "CampaignId"
      }
    ]
  },
  "expects": {
    "status_code": 200
  },
  "response_assertions": [
    {
      "field": "0.isSuccess",
      "operator": "eq",
      "value": true
    },
    {
      "field": "0.outputValues.recordCreates.0.objectApiName",
      "operator": "eq",
      "value": "Opportunity"
    },
    {
      "field": "0.outputValues.recordCreates.0.fields.CampaignId",
      "operator": "eq",
      "value": "{campaign_id}"
    }
  ],
  "teardown": [
    {
      "type": "sql",
      "sql": "DELETE FROM `CampaignMember` WHERE Id = '00vPVW000000001AAA'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Campaign` WHERE Id = '701PVW000000001AAA'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Lead` WHERE Id = '00QPVW000000001AAA'"
    }
  ],
  "priority": "P1",
  "bug_ref": "#2154",
  "scene": "lead_convert"
}
