{
  "id": "fix-2790",
  "title": "Account/Opp outbound gate dropped HubSpot_Id precondition",
  "kind": "hubspot_sync",
  "linkedIssues": [
    2790
  ],
  "provenance": {
    "businessScenario": "FIX-2790 — re-prove #2790: an Account/Opportunity with no pre-existing HubSpot_Id__c can still outbound on first save (the gate no longer requires a pre-stored HubSpot_Id). Create native Account with no HubSpot_Id set, wait for its HubSpot_Id__c writeback, then create the Opportunity with no HubSpot_Id set and poll its writeback. PASS (verbatim NEW runbook H FIX-2790): can outbound without HubSpot_Id. Either not written back after the parent Account link is finalized = FAIL (#2790 reproduced, gate still requires HubSpot_Id precondition).",
    "reportedBy": "HubSpot sync spec FIX-2790 (hubspot-nexuscrm-sync-CASE-EXEC-SELFCONTAINED)",
    "capturedAt": "2026-06-18",
    "calibrated": "[calibrated] Account create now carries required NX fields (Industry/NumberOfEmployees/RecordTypeId/Region__c/Vertical__c/Website). Wait for Account HubSpot_Id__c before creating the Opportunity so the deal association target link is finalized before Opportunity outbound."
  },
  "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": "Fx2790A-{{__runId}}",
        "Industry": "FSI-FinTech",
        "NumberOfEmployees": 120,
        "RecordTypeId": "{{steps.account-record-type.response.body.records[0].Id}}",
        "Region__c": "NA",
        "Vertical__c": "Payment",
        "Website": "https://fx2790-{{__runId}}.example.com",
        "ApprovalStatus__c": "Approved"
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "wait-account-writeback",
      "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": 6000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.records[0].HubSpot_Id__c",
          "exists": true
        }
      ]
    },
    {
      "id": "create-opp",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "POST",
      "path": "/services/data/v63.0/sobjects/Opportunity",
      "body": {
        "Name": "Fx2790O-{{__runId}}",
        "StageName": "Prospecting",
        "ARR_Amount_USD__c": 100000,
        "Launch_Date__c": "2026-12-31",
        "CloseDate": "2026-12-31",
        "AccountId": "{{steps.create-account.response.body.id}}"
      },
      "expectStatusRange": [
        200,
        299
      ],
      "assertions": [
        {
          "path": "response.body.id",
          "exists": true
        }
      ]
    },
    {
      "id": "wait-opp-writeback",
      "system": "nexuscrm",
      "authRole": "admin",
      "method": "GET",
      "path": "/services/data/v63.0/query?q=SELECT HubSpot_Id__c FROM Opportunity WHERE Id='{{steps.create-opp.response.body.id}}' LIMIT 1",
      "expectStatus": 200,
      "poll": {
        "budgetMs": 90000,
        "intervalMs": 6000
      },
      "onTimeout": "fail",
      "assertions": [
        {
          "path": "response.body.records[0].HubSpot_Id__c",
          "exists": true
        }
      ]
    }
  ]
}
