{
  "id": "QUOTE-TENANT-INHERIT-FROM-OPPORTUNITY",
  "name": "apply-tenant → POST /sobjects/Quote inherits AccountId from the referenced Opportunity (issue #1847 inheritance half)",
  "description": "Inheritance half of the cutover proof — pairs with QUOTE-TENANT-CLONE-LINE-ITEMS (quote_line scene) which covers the child-clone half. Round-4 reviewer flagged that a single query_after can only assert one object, so the two halves live in separate cases. Here we POST a Quote carrying only OpportunityId (no AccountId) and prove the insertInheritFromLookup rule fires by asserting the created Quote.AccountId equals the source Opportunity's AccountId. If the applier, the rule seed, or the Retrieve path ever regresses, this case fails. Access-denied semantics are covered separately by the unit-level TestIsBenignInheritanceRetrieveError class (records package).",
  "object": "Quote",
  "method": "POST",
  "endpoint": "/services/data/v63.0/sobjects/Quote",
  "setup": [
    {
      "type": "sql",
      "name": "Create Account (will be inherited onto Quote)",
      "sql": "INSERT INTO Account (Id, Name, BillingCountryCode, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-account-01",
        "Quote Tenant Inherit Account",
        "{billing_country_code}",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Opportunity (parent for inheritance — AccountId, Description, CurrencyIsoCode land on Quote)",
      "sql": "INSERT INTO Opportunity (Id, Name, AccountId, StageName, CloseDate, Amount, Description, CurrencyIsoCode, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-opp-01",
        "Quote Tenant Inherit Opp",
        "qtenant-account-01",
        "Prospecting",
        "2026-12-31",
        25000,
        "Parent opportunity for tenant-path inheritance test",
        "USD",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create OpportunityLineItem (source for child-clone → quote_product__c)",
      "sql": "INSERT INTO OpportunityLineItem (Id, OpportunityId, PricebookEntryId, Product2Id, Quantity, UnitPrice, ListPrice, Discount, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-oli-01",
        "qtenant-opp-01",
        "01u5g00000196D9AAI",
        "01t5g000000liLsAAI",
        3,
        99.99,
        120.00,
        10.00,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    }
  ],
  "payload": {
    "Name": "Quote Tenant Inherit Test",
    "OpportunityId": "qtenant-opp-01"
  },
  "expects": {
    "status_code": 201
  },
  "extract": {
    "quote_id": "id"
  },
  "query_after": {
    "object": "Quote",
    "record_id": "{quote_id}",
    "assertions": [
      {
        "field": "AccountId",
        "operator": "equals",
        "value": "qtenant-account-01",
        "comment": "Inheritance rule Opportunity.AccountId → Quote.AccountId fired"
      },
      {
        "field": "OpportunityId",
        "operator": "equals",
        "value": "qtenant-opp-01",
        "comment": "User-supplied FK preserved"
      },
      {
        "field": "Description",
        "operator": "equals",
        "value": "Parent opportunity for tenant-path inheritance test",
        "comment": "Inheritance rule Opportunity.Description → Quote.Description fired — proves inheritance walks beyond the single-field happy path (round-6 reviewer asked for live-path coverage across multiple seed rules)"
      },
      {
        "field": "Status",
        "operator": "equals",
        "value": "Pending",
        "comment": "Constant-default rule (sourceField=\"\", targetField=Status, defaultValue=Pending) fires when Quote.Status is blank on insert — the cutover preserves the legacy mergeQuoteDefaultsFromOpportunity explicit Status=Pending assignment"
      }
    ]
  },
  "teardown": [
    {
      "type": "sql",
      "sql": "DELETE FROM quote_product__c WHERE Quote__c = %s",
      "params": ["{quote_id}"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Quote WHERE Id = %s",
      "params": ["{quote_id}"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM OpportunityLineItem WHERE Id = %s",
      "params": ["qtenant-oli-01"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": ["qtenant-opp-01"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": ["qtenant-account-01"]
    }
  ],
  "priority": "P0",
  "bug_ref": "#1847",
  "scene": "quote"
}
