{
  "id": "bi-conv-01",
  "title": "Lead convert migrates HubSpot_Id to Contact and auto-creates primary OCR",
  "kind": "hubspot_sync",
  "executionMode": "serial",
  "executionModeReason": "HubSpot contact materialization is queue-sensitive under the full-suite webhook burst and must run without competing case traffic.",
  "caseTimeoutMs": 540000,
  "linkedIssues": [
    2801,
    2830
  ],
  "provenance": {
    "businessScenario": "BI-CONV-01 — a synced (inbound-origin) Lead converts onto an existing Account; HubSpot_Id__c migrates to the resulting Contact and an OpportunityContactRole is auto-created with IsPrimary=true. Requires owner != system (root cause #2830); UX tracked in #2801.",
    "reportedBy": "HubSpot sync spec BI-CONV-01 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "note": "[calibrated] Rewrote convert: inbound-origin Lead with bound non-system owner (HS owner 44888233); pre-create Account with all required fields; POST /services/data/v63.0/actions/standard/convertLead with convertedStatus 'Open Opportunity' + accountId; assert response.body[0].isSuccess + outputValues.contactId/opportunityId, Contact.HubSpot_Id__c, primary OCR."
  },
  "steps": [
    {
      "id": "hs",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "conv01-{{__runId}}@example.com",
          "firstname": "Conv",
          "lastname": "One{{__runId}}",
          "hubspot_owner_id": "44888233"
        }
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "leadQ",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, OwnerId, HubSpot_Id__c FROM Lead WHERE HubSpot_Id__c = '{{steps.hs.response.body.id}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 240000,
        "intervalMs": 6000
      },
      "onTimeout": "fail",
      "diagnostics": {
        "connectorEvent": {
          "sourceObjectId": "{{steps.hs.response.body.id}}",
          "blockOnBacklog": true,
          "blockOnForeignClaimedBy": true,
          "foreignClaimedByPattern": "(MacBook|\\.local)"
        }
      },
      "assertions": [
        {
          "path": "response.body.totalSize",
          "atLeast": 1
        },
        {
          "path": "response.body.records[0].OwnerId",
          "exists": true
        }
      ]
    },
    {
      "id": "account-record-type",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id FROM _System_RecordType WHERE SobjectType = 'Account' AND Name = 'Customer' AND IsActive = true LIMIT 1",
      "expectStatus": 200,
      "assertions": [
        {
          "path": "response.body.totalSize",
          "atLeast": 1
        },
        {
          "path": "response.body.records[0].Id",
          "exists": true
        }
      ]
    },
    {
      "id": "account",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Account",
      "body": {
        "Name": "ConvAcct{{__runId}}",
        "Industry": "FSI-FinTech",
        "NumberOfEmployees": 120,
        "RecordTypeId": "{{steps.account-record-type.response.body.records[0].Id}}",
        "Region__c": "NA",
        "Vertical__c": "Payment",
        "Website": "https://convacct-{{__runId}}.example.com"
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "convert",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/actions/standard/convertLead",
      "body": {
        "inputs": [
          {
            "leadId": "{{steps.leadQ.response.body.records[0].Id}}",
            "convertedStatus": "Open Opportunity",
            "accountId": "{{steps.account.response.body.id}}"
          }
        ]
      },
      "expectStatus": 200,
      "assertions": [
        {
          "path": "response.body[0].isSuccess",
          "equals": true
        },
        {
          "path": "response.body[0].outputValues.contactId",
          "exists": true
        },
        {
          "path": "response.body[0].outputValues.opportunityId",
          "exists": true
        }
      ]
    },
    {
      "id": "contactQ",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, HubSpot_Id__c FROM Contact WHERE Id = '{{steps.convert.response.body[0].outputValues.contactId}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 6000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.records[0].HubSpot_Id__c",
          "equals": "{{steps.hs.response.body.id}}"
        }
      ]
    },
    {
      "id": "ocrQ",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id, IsPrimary, ContactId FROM OpportunityContactRole WHERE OpportunityId = '{{steps.convert.response.body[0].outputValues.opportunityId}}'",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 6000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.totalSize",
          "atLeast": 1
        },
        {
          "path": "response.body.records[0].IsPrimary",
          "equals": true
        }
      ]
    }
  ]
}
