{
  "id": "out-004",
  "title": "Synced Lead LeadSource + Title PATCH propagates to HubSpot contact",
  "kind": "hubspot_sync",
  "linkedIssues": [],
  "provenance": {
    "businessScenario": "OUT-004 — following the OUT-001 path, PATCH a mapped field (LeadSource) plus a control field (Title) on a synced Lead and verify both propagate to the HubSpot contact (leadsource + jobtitle, §2.2). Title is the control proving the link fired.",
    "reportedBy": "HubSpot sync spec OUT-004 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "note": "[calibrated] Minimal Lead create; PATCH LeadSource+Title -> contact leadsource+jobtitle assertions unchanged (LeadSource 'Web' is a legal identity value)."
  },
  "steps": [
    {
      "id": "create-record",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Lead",
      "body": {
        "LastName": "O4{{__runId}}",
        "Company": "C4{{__runId}}",
        "Email": "o4-{{__runId}}@example.com",
        "HubSpot_Sync_Enabled__c": true
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-hubspot-id",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c FROM Lead WHERE Id = '{{steps.create-record.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 90000, "intervalMs": 3000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Id__c", "exists": true }
      ]
    },
    {
      "id": "patch-fields",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Lead/{{steps.create-record.response.body.id}}",
      "body": { "LeadSource": "Website Referral", "Title": "Eng-{{__runId}}" },
      "expectStatus": 204
    },
    {
      "id": "assert-hubspot",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/contacts/{{steps.wait-hubspot-id.response.body.records[0].HubSpot_Id__c}}?properties=leadsource,jobtitle",
      "expectStatus": 200,
      "poll": { "budgetMs": 90000, "intervalMs": 3000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.properties.jobtitle", "equals": "Eng-{{__runId}}" },
        { "path": "response.body.properties.leadsource", "equals": "Website Referral" }
      ]
    }
  ]
}
