{
  "id": "in-c-fields",
  "title": "Inbound HubSpot contact populates Lead mapped fields per oracle",
  "kind": "hubspot_sync",
  "caseTimeoutMs": 600000,
  "linkedIssues": [3016],
  "provenance": {
    "businessScenario": "IN-C-FIELDS — create a HubSpot contact filling representative §2.1 inbound-mapped fields and verify each NexusCRM Lead target field equals the oracle: identity overwrite, valueMap passthrough (Country/State), CASE transforms (hs_analytics_source->Hubspot_Original_Source__c, salesforce_industry->Industry whitelist), and country-derived Region__c. region__c is intentionally left BLANK so Region__c is derived from the country: country_picklist__sfdc_='United States' -> CountryCode 'US' (Lead_SetCountryCodeFromCountry) -> Region__c 'NA' (Lead_Quick_Set_Region looks up Countries_Region__c(Name='US').Region_Name__c, which only fires when Region__c is null). Sending region__c='APAC' alongside a US country was self-contradictory and pre-empted the country derivation; assert Region__c='NA' instead. The hubspot_owner_id -> HubSpot_Owner_Id__c owner-shadow mapping is intentionally NOT asserted here: this lead is reassigned by the region rule to the region owner, and the owner-shadow before-save flow clears HubSpot_Owner_Id__c when that owner has no HubSpotOwnerBinding (by design). The owner_id -> shadow mapping is covered by in-owner-01 (bound owner, no region reassignment). Read-only fields excluded; write-once verified non-overwrite separately.",
    "reportedBy": "HubSpot sync spec IN-C-FIELDS (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[recalibrated 2026-08-26] The United-States contact leaves region__c blank so country lookup derives Country=United States and Region__c=NA. Industry=FSI-FinTech is asserted directly. A final 60-second readback retains the settled Country/Industry oracle from #3016 without restoring duplicate API-shaped cases. Owner shadow remains intentionally outside this case because assignment may move the owner to an unbound regional user."
  },
  "steps": [
    {
      "id": "create-contact",
      "system": "hubspot",
      "method": "POST",
      "path": "/crm/v3/objects/contacts",
      "body": {
        "properties": {
          "email": "inc-fields-{{__runId}}@example.com",
          "lastname": "Fields{{__runId}}",
          "company": "Acme Inc",
          "firstname": "Grace",
          "jobtitle": "VP Eng",
          "rating": "SKA",
          "leadsource": "Organic Search",
          "hs_lead_status": "OPEN",
          "country_picklist__sfdc_": "United States",
          "state_picklist__sfdc_": "California",
          "hs_analytics_source": "ORGANIC_SEARCH",
          "lifecyclestage": "lead",
          "salesforce_industry": "FSI-FinTech",
          "hubspot_owner_id": "44888233"
        }
      },
      "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,
      "poll": {
        "budgetMs": 180000,
        "intervalMs": 6000
      },
      "onTimeout": "blocked",
      "assertions": [
        {
          "path": "response.body.records",
          "lengthAtLeast": 1
        }
      ],
      "timeoutMs": 8000
    },
    {
      "id": "assert-fields",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Id,Company,Email,FirstName,LastName,Title,Rating,LeadSource,Status,Country,State,Industry,Hubspot_Original_Source__c,Region__c,Lifecycle_Stage__c,HubSpot_Owner_Id__c FROM Lead WHERE HubSpot_Id__c = '{{steps.create-contact.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 180000,
        "intervalMs": 6000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.records[0].Company",
          "equals": "Acme Inc"
        },
        {
          "path": "response.body.records[0].FirstName",
          "equals": "Grace"
        },
        {
          "path": "response.body.records[0].LastName",
          "equals": "Fields{{__runId}}"
        },
        {
          "path": "response.body.records[0].Title",
          "equals": "VP Eng"
        },
        {
          "path": "response.body.records[0].Rating",
          "equals": "SKA"
        },
        {
          "path": "response.body.records[0].LeadSource",
          "equals": "Organic Search"
        },
        {
          "path": "response.body.records[0].Status",
          "equals": "OPEN"
        },
        {
          "path": "response.body.records[0].Country",
          "equals": "United States"
        },
        {
          "path": "response.body.records[0].State",
          "equals": "California"
        },
        {
          "path": "response.body.records[0].Industry",
          "equals": "FSI-FinTech"
        },
        {
          "path": "response.body.records[0].Hubspot_Original_Source__c",
          "equals": "Organic Search"
        },
        {
          "path": "response.body.records[0].Region__c",
          "equals": "NA"
        },
        {
          "path": "response.body.records[0].Lifecycle_Stage__c",
          "equals": "lead"
        },
        {
          "path": "response.body.records[0].Email",
          "includes": "@example.com"
        }
      ],
      "timeoutMs": 8000
    },
    {
      "id": "assert-fields-settled",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT Company,Email,FirstName,LastName,Title,Country,State,Industry,Region__c FROM Lead WHERE HubSpot_Id__c='{{steps.create-contact.response.body.id}}' LIMIT 1",
      "delayMs": 60000,
      "expectStatus": 200,
      "assertions": [
        { "path": "response.body.records[0].Company", "equals": "Acme Inc" },
        { "path": "response.body.records[0].FirstName", "equals": "Grace" },
        { "path": "response.body.records[0].LastName", "equals": "Fields{{__runId}}" },
        { "path": "response.body.records[0].Title", "equals": "VP Eng" },
        { "path": "response.body.records[0].Country", "equals": "United States" },
        { "path": "response.body.records[0].State", "equals": "California" },
        { "path": "response.body.records[0].Industry", "equals": "FSI-FinTech" },
        { "path": "response.body.records[0].Region__c", "equals": "NA" },
        { "path": "response.body.records[0].Email", "equals": "inc-fields-{{__runId}}@example.com", "caseInsensitive": true }
      ]
    }
  ]
}
