{
  "id": "LC-TENANT-OCR-ROLE-DEFAULT",
  "name": "Tenant ActionFieldDefault supplies OCR Role during Lead Convert",
  "description": "Regression for #2110. After the PingCAP tenant overlay is applied, convertLead should create the primary OpportunityContactRole with the tenant-owned Role default and no platform hardcoded role value.",
  "object": "LeadConvert",
  "method": "POST",
  "endpoint": "/services/data/v63.0/actions/standard/convertLead",
  "setup": [
    {
      "type": "sql",
      "sql": "UPDATE `_System_ActionFieldDefault` SET IsActive=0, IsDeleted=1 WHERE Id = 'afd_convertlead_ocr_role_e2e'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM OpportunityContactRole WHERE OpportunityId = 'lc-tenant-ocr-opp'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = 'lc-tenant-ocr-opp'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Contact WHERE Email = 'lc-tenant-ocr-contact@example.test'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Lead` WHERE Id = 'lc-tenant-ocr-lead'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = 'lc-tenant-ocr-acct'"
    },
    {
      "type": "sql",
      "sql": "INSERT INTO Account (Id, Name, OwnerId, CreatedDate, LastModifiedDate, SystemModstamp, IsDeleted) VALUES ('lc-tenant-ocr-acct', 'LC Tenant OCR Account', '10000000-0000-0000-0000-000000000001', NOW(), NOW(), NOW(), 0)"
    },
    {
      "type": "sql",
      "sql": "INSERT INTO `Lead` (Id, FirstName, LastName, Company, Email, Status, OwnerId, CreatedDate, LastModifiedDate, SystemModstamp, IsDeleted) VALUES ('lc-tenant-ocr-lead', 'Tenant', 'OCR', 'LC Tenant OCR Account', 'lc-tenant-ocr-contact@example.test', 'Qualified', '10000000-0000-0000-0000-000000000001', NOW(), NOW(), NOW(), 0)"
    }
  ],
  "payload": {
    "inputs": [
      {
        "leadId": "lc-tenant-ocr-lead",
        "accountId": "lc-tenant-ocr-acct",
        "convertedStatus": "Customer",
        "opportunityName": "LC Tenant OCR Opportunity"
      }
    ]
  },
  "expects": {
    "status_code": 200
  },
  "extract": {
    "opportunity_id": "0.outputValues.opportunityId",
    "contact_id": "0.outputValues.contactId"
  },
  "query_after": {
    "object": "OpportunityContactRole",
    "id_field": "OpportunityId",
    "record_id": "{opportunity_id}",
    "select_fields": [
      "ContactId",
      "Role",
      "IsPrimary"
    ],
    "assertions": [
      {
        "field": "ContactId",
        "operator": "eq",
        "value": "{contact_id}"
      },
      {
        "field": "Role",
        "operator": "eq",
        "value": "Decision_Maker"
      },
      {
        "field": "IsPrimary",
        "operator": "eq",
        "value": true
      }
    ]
  },
  "teardown": [
    {
      "type": "sql",
      "sql": "DELETE FROM OpportunityContactRole WHERE OpportunityId = '{opportunity_id}'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = '{opportunity_id}'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Contact WHERE Id = '{contact_id}'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM `Lead` WHERE Id = 'lc-tenant-ocr-lead'"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = 'lc-tenant-ocr-acct'"
    }
  ],
  "priority": "P1",
  "bug_ref": "#2110",
  "scene": "lead_convert"
}
