{
  "id": "VAL-005",
  "name": "Cross-object ValidationRule blocks Quote create",
  "description": "Regression for #1719. A ValidationRule on Quote that references Opportunity.StageName must evaluate through the foreign key and block create when the parent Opportunity is still in Prospecting.",
  "object": "Quote",
  "method": "POST",
  "endpoint": "/services/data/v63.0/sobjects/Quote",
  "setup": [
    {
      "type": "sql",
      "name": "Delete stale VAL-005 validation rule if it exists",
      "sql": "DELETE FROM _System_ValidationRule WHERE Name = %s",
      "params": [
        "VAL005_QuoteStageBlocked"
      ]
    },
    {
      "type": "sql",
      "name": "Create fixed Opportunity for VAL-005",
      "sql": "INSERT INTO Opportunity (Id, Name, StageName, CloseDate, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "val005-opp-01",
        "VAL-005 Opportunity",
        "Prospecting",
        "2026-12-31",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "method": "POST",
      "endpoint": "/services/data/v63.0/metadata/validation-rules",
      "payload": {
        "objectApiName": "Quote",
        "name": "VAL005_QuoteStageBlocked",
        "active": true,
        "condition": "Opportunity.StageName == \"Prospecting\"",
        "errorMessage": "Quote cannot be created while Opportunity is still Prospecting."
      },
      "extract": {
        "validation_rule_id": "id"
      }
    }
  ],
  "payload": {
    "Name": "VAL-005 Quote {timestamp}",
    "OpportunityId": "val005-opp-01",
    "Status": "Draft"
  },
  "expects": {
    "status_code": 400
  },
  "response_assertions": [
    {
      "field": "0.message",
      "operator": "contains",
      "value": "Quote cannot be created while Opportunity is still Prospecting."
    }
  ],
  "teardown": [
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/metadata/validation-rules/{validation_rule_id}"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": [
        "val005-opp-01"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM _System_ValidationRule WHERE Name = %s",
      "params": [
        "VAL005_QuoteStageBlocked"
      ]
    }
  ],
  "priority": "P0",
  "bug_ref": "#1719",
  "scene": "validation",
  "timeout_seconds": 90,
  "skip": true,
  "skip_reason": "Regression case added from recent UAT-Test P0 fixes, but current product behavior on main still evaluates cross-object ValidationRule references on Quote as INTERNAL_ERROR"
}
