{
  "id": "QUOTE-TENANT-CLONE-SKIP-INACCESSIBLE-LINE-ITEMS",
  "name": "apply-tenant → POST /sobjects/Quote skips clone rows whose Product2 target is missing while still creating the Quote",
  "description": "Runtime oracle for issue #2202. When a source Opportunity has multiple OpportunityLineItem rows and one of them carries a Product2Id that is missing/inaccessible to the non-polymorphic lookup validator, the Quote insert must still succeed and child-clone must persist only the valid source rows. This proves the new skip-on-inaccessible-target behavior end-to-end on the real tenant-overlay Quote child-clone path.",
  "object": "Quote",
  "method": "POST",
  "endpoint": "/services/data/v63.0/sobjects/Quote",
  "setup": [
    {
      "type": "sql",
      "name": "Create Account for skip case",
      "sql": "INSERT INTO Account (Id, Name, BillingCountryCode, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-skip-account-01",
        "Quote Tenant Skip Account",
        "{billing_country_code}",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Opportunity for skip case",
      "sql": "INSERT INTO Opportunity (Id, Name, AccountId, StageName, CloseDate, Amount, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-skip-opp-01",
        "Quote Tenant Skip Opp",
        "qtenant-skip-account-01",
        "Prospecting",
        "2026-12-31",
        18000,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create valid OpportunityLineItem that should clone",
      "sql": "INSERT INTO OpportunityLineItem (Id, OpportunityId, PricebookEntryId, Product2Id, Quantity, UnitPrice, ListPrice, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-skip-oli-valid-01",
        "qtenant-skip-opp-01",
        "01u5g00000196D9AAI",
        "01t5g000000liLsAAI",
        5,
        149.99,
        199.99,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create bad OpportunityLineItem whose Product2Id does not exist so clone must skip it",
      "sql": "INSERT INTO OpportunityLineItem (Id, OpportunityId, PricebookEntryId, Product2Id, Quantity, UnitPrice, ListPrice, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "qtenant-skip-oli-bad-01",
        "qtenant-skip-opp-01",
        "01u5g00000196D9AAI",
        "01t5g000000missing",
        9,
        299.99,
        349.99,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    }
  ],
  "payload": {
    "Name": "Quote Tenant Skip Clone Test",
    "OpportunityId": "qtenant-skip-opp-01"
  },
  "expects": {
    "status_code": 201
  },
  "extract": {
    "quote_id": "id"
  },
  "query_after": {
    "object": "quote_product__c",
    "id_field": "Quote__c",
    "record_id": "{quote_id}",
    "select_fields": ["Id", "Product__c", "Quantity__c", "Quote__c"],
    "response_assertions": [
      {
        "field": "totalSize",
        "operator": "equals",
        "value": 1,
        "comment": "Only the valid OpportunityLineItem should clone; the bad Product2Id row must be skipped instead of aborting Quote creation"
      }
    ],
    "assertions": [
      {
        "field": "Product__c",
        "operator": "equals",
        "value": "01t5g000000liLsAAI",
        "comment": "The surviving clone comes from the valid source line item"
      },
      {
        "field": "Quantity__c",
        "operator": "equals",
        "value": 5,
        "comment": "The valid source line item's mapped quantity is preserved"
      },
      {
        "field": "Quote__c",
        "operator": "equals",
        "value": "{quote_id}",
        "comment": "The valid clone still points at the created Quote"
      }
    ]
  },
  "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-skip-oli-valid-01"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM OpportunityLineItem WHERE Id = %s",
      "params": ["qtenant-skip-oli-bad-01"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": ["qtenant-skip-opp-01"]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": ["qtenant-skip-account-01"]
    }
  ],
  "priority": "P0",
  "bug_ref": "#2202",
  "scene": "quote_line"
}
