{
  "id": "out-003",
  "title": "Synced Opportunity Name PATCH updates HubSpot deal dealname",
  "kind": "hubspot_sync",
  "linkedIssues": [3161],
  "provenance": {
    "businessScenario": "OUT-003 — a previously outbound-synced Opportunity is PATCHed on Name; verify HubSpot dealname updates (Name->dealname identity, §2.4).",
    "reportedBy": "HubSpot sync spec OUT-003 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "note": "[recalibrated 2026-07-22] Wait for the parent Account's finalized HubSpot company link before creating the Opportunity. Opportunity outbound currently has no automatic retry when the parent link lands after the first attempt (#3161), so parent readiness is a business precondition and times out as blocked. Opp create still uses verified required fields (Name+CloseDate+StageName=Prospecting); Name->dealname identity assertion is unchanged."
  },
  "steps": [
    {
      "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": "create-account",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Account",
      "body": {
        "Name": "Out003Acct {{__runId}}",
        "Industry": "FSI-FinTech",
        "NumberOfEmployees": 250,
        "RecordTypeId": "{{steps.account-record-type.response.body.records[0].Id}}",
        "Region__c": "NA",
        "Vertical__c": "Payment",
        "Website": "https://out003-acct-{{__runId}}.example.com",
        "ApprovalStatus__c": "Approved"
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "wait-account-hubspot-link",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c FROM Account WHERE Id = '{{steps.create-account.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 3000
      },
      "onTimeout": "blocked",
      "assertions": [
        {
          "path": "response.body.records[0].HubSpot_Id__c",
          "exists": true
        }
      ]
    },
    {
      "id": "create-record",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Opportunity",
      "body": {
        "Name": "OutOpp003 {{__runId}}",
        "AccountId": "{{steps.create-account.response.body.id}}",
        "StageName": "Prospecting",
        "ARR_Amount_USD__c": 100000,
        "Launch_Date__c": "2026-12-31",
        "CloseDate": "2026-09-30",
        "Type": "New Subscription",
        "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 Opportunity 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-name",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "PATCH",
      "path": "/services/data/v63.0/sobjects/Opportunity/{{steps.create-record.response.body.id}}",
      "body": {
        "Name": "OppRenamed-{{__runId}}"
      },
      "expectStatus": 204
    },
    {
      "id": "assert-hubspot",
      "system": "hubspot",
      "method": "GET",
      "path": "/crm/v3/objects/deals/{{steps.wait-hubspot-id.response.body.records[0].HubSpot_Id__c}}?properties=dealname",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 3000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.properties.dealname",
          "equals": "OppRenamed-{{__runId}}"
        }
      ]
    }
  ]
}
