{
  "id": "APR-002",
  "name": "Approver calling Approve twice on same request should return error",
  "description": "Approver calling Approve on an already-approved request should return error, not 200. Bug: New - approval state management not tested.",
  "object": "Quote",
  "method": "POST",
  "endpoint": "/services/data/v63.0/process/approvals",
  "setup": [
    {
      "type": "sql",
      "name": "Create Account for APR-002",
      "sql": "INSERT INTO Account (Id, Name, Type, BillingCountryCode, IsDeleted, CreatedDate, LastModifiedDate, SystemModstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
      "params": [
        "001APR002ACC00001",
        "APR-002 Test Account",
        "Customer - Direct",
        "US",
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "type": "sql",
      "name": "Create Opportunity for APR-002",
      "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": [
        "006APR002OPP00001",
        "APR-002 Test Opportunity",
        "001APR002ACC00001",
        "Prospecting",
        "{today}",
        1000,
        0,
        "{db_timestamp}",
        "{db_timestamp}",
        "{db_timestamp}"
      ]
    },
    {
      "method": "POST",
      "endpoint": "/services/data/v63.0/sobjects/Quote",
      "object": "Quote",
      "payload": {
        "Name": "APR-002 Test Quote",
        "OpportunityId": "006APR002OPP00001",
        "AccountId": "001APR002ACC00001",
        "Status": "Draft"
      },
      "id_var": "quote_id",
      "extract": {
        "quote_id": "id"
      }
    }
  ],
  "payload": {
    "actionType": "Submit",
    "contextId": "{quote_id}",
    "comments": "Please approve this quote"
  },
  "expects": {
    "status_code": 200
  },
  "approval_step": {
    "action": "approve",
    "name": "Approve the submitted request",
    "endpoint": "/services/data/v63.0/process/approvals",
    "payload": {
      "actionType": "Approve",
      "contextId": "{quote_id}",
      "comments": "Approved"
    },
    "expects": {
      "status_code": 200
    }
  },
  "retry_approval": {
    "name": "Approve the same request again",
    "endpoint": "/services/data/v63.0/process/approvals",
    "payload": {
      "actionType": "Approve",
      "contextId": "{quote_id}",
      "comments": "Trying to approve again"
    },
    "expects": {
      "status_code": 400,
      "body_contains": "already approved"
    }
  },
  "teardown": [
    {
      "method": "DELETE",
      "endpoint": "/services/data/v63.0/sobjects/Quote/{quote_id}"
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Opportunity WHERE Id = %s",
      "params": [
        "006APR002OPP00001"
      ]
    },
    {
      "type": "sql",
      "sql": "DELETE FROM Account WHERE Id = %s",
      "params": [
        "001APR002ACC00001"
      ]
    }
  ],
  "priority": "P2",
  "bug_ref": "New",
  "scene": "approval",
  "skip": true,
  "skip_reason": "Runner now supports chained approval requests, but current product behavior still returns 500 on the initial Submit call to /process/approvals before the approve-twice assertion path can execute"
}
