#!/usr/bin/env bash
# Return a response generated by a JavaScript template with a 2-minute delay.
# Assumes MOCKSERVER_URL is set (defaults to http://localhost:1080).

curl -X PUT "${MOCKSERVER_URL:-http://localhost:1080}/mockserver/expectation" \
-d '{
  "httpRequest": {
    "path": "/some/path"
  },
  "httpResponseTemplate": {
    "template": "if (request.method === '\''POST'\'' && request.path === '\''/somePath'\'') { return {'\''statusCode'\'': 200, '\''body'\'': {name: '\''value'\''}}; } else { return {'\''statusCode'\'': 406, '\''body'\'': request.body};}",
    "templateType": "JAVASCRIPT",
    "delay": {
      "timeUnit": "MINUTES",
      "value": 2
    }
  }
}'
