{
  "id": "in-c-016",
  "title": "Inbound hubspot_owner_id lands on shadow HubSpot_Owner_Id__c without polluting OwnerId",
  "kind": "hubspot_sync",
  "linkedIssues": [2482],
  "provenance": {
    "businessScenario": "IN-C-016 (#2482) — inbound hubspot_owner_id writes the raw HubSpot owner id to the shadow field HubSpot_Owner_Id__c, while OwnerId stays a valid NexusCRM User Id (not polluted with the raw HS owner id). Control field firstname='O' proves the link fired.",
    "reportedBy": "HubSpot sync spec IN-C-016 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[recalibrated 2026-08-29] Uses the exact deployment-owned sandbox binding 45282439 instead of selecting an arbitrary bound row. This keeps the oracle environment-local, prevents a stale production-clone binding from becoming provider input, and still proves the raw HubSpot owner id is preserved in HubSpot_Owner_Id__c and never written into OwnerId."
  },
  "steps": [
    {
      "id": "binding",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpotOwnerId__c,CRMPrincipalId__c FROM HubSpotOwnerBinding__c WHERE BindingStatus__c='bound' AND CRMPrincipalType__c='User' AND HubSpotOwnerId__c='45282439' LIMIT 1",
      "expectStatus": 200,
      "poll": { "budgetMs": 30000, "intervalMs": 3000 },
      "onTimeout": "blocked",
      "assertions": [
        { "path": "response.body.records", "lengthAtLeast": 1 },
        { "path": "response.body.records[0].HubSpotOwnerId__c", "equals": "45282439" },
        { "path": "response.body.records[0].CRMPrincipalId__c", "exists": true }
      ]
    },
    {
      "id": "create-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "own16-{{__runId}}@example.com",
          "firstname": "O",
          "lastname": "W{{__runId}}",
          "hubspot_owner_id": "{{steps.binding.response.body.records[0].HubSpotOwnerId__c}}"
        }
      },
      "expectStatusRange": [200, 299],
      "assertions": [
        { "path": "response.body.id", "exists": true }
      ]
    },
    {
      "id": "wait-inbound-row",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id FROM Lead WHERE HubSpot_Id__c = '{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "timeoutMs": 8000,
      "poll": { "budgetMs": 90000, "intervalMs": 6000 },
      "onTimeout": "blocked",
      "assertions": [
        { "path": "response.body.records", "lengthAtLeast": 1 }
      ]
    },
    {
      "id": "assert-owner-shadow",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Owner_Id__c,OwnerId,FirstName FROM Lead WHERE HubSpot_Id__c = '{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "timeoutMs": 8000,
      "poll": { "budgetMs": 90000, "intervalMs": 6000 },
      "onTimeout": "fail",
      "assertions": [
        { "path": "response.body.records[0].HubSpot_Owner_Id__c", "equals": "{{steps.binding.response.body.records[0].HubSpotOwnerId__c}}" },
        { "path": "response.body.records[0].OwnerId", "notEquals": "{{steps.binding.response.body.records[0].HubSpotOwnerId__c}}" },
        { "path": "response.body.records[0].OwnerId", "exists": true },
        { "path": "response.body.records[0].FirstName", "equals": "O" }
      ]
    }
  ]
}
