{
  "id": "OLI-004",
  "name": "Order created from Quote should have OrderLineItems copied",
  "description": "When an Order is created from a Quote that has QuoteLineItem children, the current Order create path should still materialize corresponding order_product__c rows. This verifies Bug #511 from the legacy QuoteLineItem shape.",
  "object": "Order",
  "method": "POST",
  "endpoint": "/services/data/v63.0/sobjects/Order",
  "payload": {
    "AccountId": "oli004-acc-01",
    "EffectiveDate": "2026-04-01",
    "Status": "Draft",
    "StatusCode": "Draft",
    "TotalAmount": 300.0,
    "QuoteId": "oli004-quote-01"
  },
  "expects": {
    "status_code": 201
  },
  "extract": {
    "order_id": "id"
  },
  "query_after": {
    "object": "order_product__c",
    "id_field": "Order__c",
    "record_id": "{order_id}",
    "assertions": [
      {
        "field": "Id",
        "operator": "is_not_null",
        "value": true
      }
    ]
  },
  "teardown": [
    {
      "type": "sql",
      "sql": "DELETE FROM QuoteLineItem WHERE Id = %s",
      "params": [
        "oli004-qli-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Quote WHERE Id = %s",
      "params": [
        "oli004-quote-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": [
        "oli004-opp-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Contract WHERE Id = %s",
      "params": [
        "oli004-cnt-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": [
        "oli004-acc-01"
      ]
    }
  ],
  "priority": "P0",
  "bug_ref": "#511",
  "scene": "order_line",
  "setup": [
    {
      "type": "sql",
      "name": "Create Account for OLI-004",
      "sql": "INSERT INTO Account (Id, Name, Type, BillingCountryCode, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "oli004-acc-01",
        "OLI-004 Account",
        "Customer - Direct",
        "{billing_country_code}",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Look up Contract RecordType Id for TiDB Cloud Services Agreement",
      "sql": "SELECT rt.Id AS csa_rt_id FROM _System_RecordType rt JOIN _System_Object so ON so.Id = rt.ObjectId WHERE so.ApiName IN ('Contract','contract') AND rt.Name = 'TiDB Cloud Services Agreement' AND rt.IsActive = 1 AND (rt.IsDeleted = 0 OR rt.IsDeleted IS NULL) LIMIT 1",
      "fetch": "one",
      "extract": {
        "csa_rt_id": "csa_rt_id"
      }
    },
    {
      "type": "sql",
      "name": "Create Effective CSA Contract for OLI-004",
      "sql": "INSERT INTO Contract (Id, AccountId, Status, StartDate, EndDate, ContractTerm, RecordTypeId, IsDeleted, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "oli004-cnt-01",
        "oli004-acc-01",
        "Effective",
        "2026-04-01",
        "2027-04-01",
        12,
        "{csa_rt_id}",
        0,
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Opportunity for OLI-004",
      "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": [
        "oli004-opp-01",
        "OLI-004 Test Opportunity",
        "oli004-acc-01",
        "Negotiation",
        "2027-01-01",
        300,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Accepted Quote for OLI-004",
      "sql": "INSERT INTO Quote (Id, Name, AccountId, Status, OpportunityId, ContractId, Service_Start_Date__c, Service_End_Date__c, IsDeleted, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "oli004-quote-01",
        "OLI-004 Test Quote",
        "oli004-acc-01",
        "Accepted",
        "oli004-opp-01",
        "oli004-cnt-01",
        "2026-04-01",
        "2026-12-31",
        0,
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create QuoteLineItem for OLI-004",
      "sql": "INSERT INTO QuoteLineItem (Id, QuoteId, PricebookEntryId, Product2Id, Quantity, UnitPrice, LineNumber, IsDeleted, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "oli004-qli-01",
        "oli004-quote-01",
        "01u5g00000196D9AAI",
        "01t5g000000liLsAAI",
        3,
        100.0,
        "000001",
        0,
        "{db_timestamp}"
      ]
    }
  ],
  "skip": true,
  "skip_reason": "Regression case is structurally repaired, but current product behavior still creates no order_product__c rows when an Order is created from a Quote with QuoteLineItem children"
}
