{
  "id": "APR-004",
  "name": "Approval submit: engine reads ProcessDefinition and evaluates entry criteria without permission failure",
  "description": "Regression for #1870 / #1907 / #1911 — the approval engine was assigned ServiceContext (10) but CRUD bypass requires SystemContext (30) and RLS bypass requires SystemContext (30). Non-admin Submit calls crashed with permission errors on Process table reads/writes. After elevating to SystemContext, the engine must return 200 with a business-level response (entry criteria not met or success), never a 500 permission failure. This case submits an Account that does not match any approval process entry criteria and asserts the engine runs cleanly. Full non-admin verification was performed manually (see PR #1941 body).",
  "object": "Account",
  "method": "POST",
  "endpoint": "/services/data/v63.0/process/approvals",
  "setup": [
    {
      "type": "sql",
      "name": "Create minimal Account for APR-004",
      "sql": "INSERT INTO Account (Id, Name, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s)",
      "params": [
        "001APR004ACC00001",
        "APR-004 Approval Engine Test",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    }
  ],
  "payload": {
    "ObjectApiName": "Account",
    "requests": [
      {
        "actionType": "Submit",
        "contextId": "001APR004ACC00001",
        "comments": "E2E test: approval engine SecurityContext regression guard"
      }
    ]
  },
  "expects": {
    "status_code": 200
  },
  "response_assertions": [
    {
      "field": "0.entityId",
      "operator": "eq",
      "value": "001APR004ACC00001"
    }
  ],
  "teardown": [
    {
      "type": "sql",
      "name": "Clean up ProcessInstanceWorkitem if submit succeeded",
      "sql": "DELETE FROM ProcessInstanceWorkitem WHERE ProcessInstanceId IN (SELECT Id FROM ProcessInstance WHERE TargetObjectId = %s)",
      "params": ["001APR004ACC00001"]
    },
    {
      "type": "sql",
      "name": "Clean up ProcessInstanceNode if submit succeeded",
      "sql": "DELETE FROM ProcessInstanceNode WHERE ProcessInstanceId IN (SELECT Id FROM ProcessInstance WHERE TargetObjectId = %s)",
      "params": ["001APR004ACC00001"]
    },
    {
      "type": "sql",
      "name": "Clean up ProcessInstance if submit succeeded",
      "sql": "DELETE FROM ProcessInstance WHERE TargetObjectId = %s",
      "params": ["001APR004ACC00001"]
    },
    {
      "type": "sql",
      "name": "Delete test Account",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": ["001APR004ACC00001"]
    }
  ],
  "priority": "P0",
  "bug_ref": "#1870",
  "scene": "approval"
}
