#!/usr/bin/env bash
# Return a response generated by a JavaScript template.
# 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": "return {'\''statusCode'\'': 200,'\''cookies'\'': {'\''session'\'': request.headers['\''session-id'\''][0]},'\''headers'\'': {'\''Date'\'': Date()}, '\''body'\'': {method: request.method, path: request.path, body: request.body}};",
    "templateType": "JAVASCRIPT"
  }
}'
