{
  "version": 13,
  "name": "checks",
  "description": "Checks: every kind of check on a request, and the assertion helpers in code.",
  "tags": [
    "checks"
  ],
  "globals": [
    {
      "name": "$baseUrl",
      "value": "https://dummyjson.com"
    },
    {
      "name": "$echoApi",
      "value": "https://httpbin.org"
    },
    {
      "name": "$searchTerm",
      "value": "phone"
    }
  ],
  "globalFunctions": "// Assertion helpers, built on check(label, pass, details).\n// Each records a pass / fail line in the log and the report.\n// A failed one fails its step when the step is done;\n// the code keeps running. Change them or add your own.\n// r defaults to the last response.\n\nfunction assertTrue(value, label = \"is true\") {\n  return check(label, Boolean(value), { actual: value, expected: true });\n}\n\nfunction assertEqual(actual, expected, label = \"equals \" + JSON.stringify(expected)) {\n  return check(label, isEqual(actual, expected), { actual, expected });\n}\n\nfunction assertNotEqual(actual, unexpected, label = \"does not equal \" + JSON.stringify(unexpected)) {\n  return check(label, !isEqual(actual, unexpected), { actual, expected: \"not \" + JSON.stringify(unexpected) });\n}\n\n// text contains a part, or a list contains an item\nfunction assertContains(haystack, needle, label = \"contains \" + JSON.stringify(needle)) {\n  const pass = Array.isArray(haystack) ? haystack.some((x) => isEqual(x, needle)) : String(haystack).includes(needle);\n  return check(label, pass, { actual: haystack, expected: needle });\n}\n\nfunction assertMatch(text, regex, label = \"matches \" + regex) {\n  return check(label, new RegExp(regex).test(String(text)), { actual: text, expected: String(regex) });\n}\n\nfunction assertLessThan(actual, limit, label = \"< \" + limit) {\n  return check(label, Number(actual) < Number(limit), { actual, expected: \"< \" + limit });\n}\n\nfunction assertGreaterThan(actual, limit, label = \"> \" + limit) {\n  return check(label, Number(actual) > Number(limit), { actual, expected: \"> \" + limit });\n}\n\n// expected: 200, \"2xx\", or a list such as [200, 201]\nfunction assertStatus(expected, r = response) {\n  const list = [].concat(expected).map(String);\n  const status = String(r && r.status);\n  const pass = list.some((e) => e === status || (/^[1-5]xx$/i.test(e) && e[0] === status[0]));\n  return check(\"status is \" + list.join(\" or \"), pass, { actual: r && r.status, expected });\n}\n\nfunction assertTimeBelow(ms, r = response) {\n  return check(\"time < \" + ms + \" ms\", Boolean(r) && r.timeMs < ms, { actual: r && r.timeMs, expected: \"< \" + ms });\n}\n\n// without expected, the header only has to exist\nfunction assertHeader(name, expected, r = response) {\n  const value = r ? r.headers[String(name).toLowerCase()] : undefined;\n  if (expected === undefined) return check(\"header \" + name + \" exists\", value !== undefined, { actual: value });\n  return check(\"header \" + name + \" equals \" + expected, String(value) === String(expected), { actual: value, expected });\n}\n\n// e.g. assertJsonPath(\"$.items[0].id\", 42); without expected, the value only has to exist\nfunction assertJsonPath(path, expected, r = response) {\n  const value = jsonPath(path, r);\n  if (expected === undefined) return check(path + \" exists\", value !== undefined, { actual: value });\n  return check(path + \" equals \" + JSON.stringify(expected), isEqual(value, expected), { actual: value, expected });\n}\n\n// schema: a JSON Schema object\nfunction assertSchema(schema, r = response) {\n  const result = validateSchema(r, schema);\n  return check(\"matches the JSON Schema\", result.valid, { error: result.errors || undefined });\n}\n",
  "libraries": [],
  "activeEnvironment": "",
  "auth": {
    "type": "none"
  },
  "settings": {},
  "data": {
    "file": ""
  },
  "cookies": [],
  "steps": [
    {
      "id": "search",
      "type": "request",
      "name": "Search products",
      "conditional": "true",
      "method": "GET",
      "url": "$baseUrl/products/search",
      "params": [
        {
          "name": "q",
          "value": "$searchTerm"
        },
        {
          "name": "limit",
          "value": "5"
        }
      ],
      "headers": [],
      "bodyMode": "raw",
      "body": "",
      "multipart": [],
      "bodyFile": {
        "path": "",
        "contentType": ""
      },
      "followRedirects": true,
      "httpVersion": "inherit",
      "auth": {
        "type": "inherit"
      },
      "extract": [],
      "checks": [
        {
          "enabled": true,
          "target": "status",
          "path": "",
          "op": "equals",
          "value": "2xx"
        },
        {
          "enabled": true,
          "target": "time",
          "path": "",
          "op": "lt",
          "value": "3000"
        },
        {
          "enabled": true,
          "target": "header",
          "path": "content-type",
          "op": "contains",
          "value": "application/json"
        },
        {
          "enabled": true,
          "target": "body",
          "path": "",
          "op": "contains",
          "value": "\"products\""
        },
        {
          "enabled": true,
          "target": "json",
          "path": "$.products",
          "op": "length",
          "value": "5"
        },
        {
          "enabled": true,
          "target": "json",
          "path": "$.total",
          "op": "gt",
          "value": "0"
        },
        {
          "enabled": true,
          "target": "json",
          "path": "$.products[0].category",
          "op": "matches",
          "value": "/^[a-z-]+$/"
        },
        {
          "enabled": true,
          "target": "schema",
          "path": "",
          "op": "valid",
          "value": "{\n  \"type\": \"object\",\n  \"required\": [\n    \"products\",\n    \"total\"\n  ],\n  \"properties\": {\n    \"products\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"required\": [\n          \"id\",\n          \"title\",\n          \"price\"\n        ]\n      }\n    },\n    \"total\": {\n      \"type\": \"integer\",\n      \"minimum\": 1\n    }\n  }\n}"
        }
      ],
      "loop": {
        "enabled": false,
        "count": 5,
        "untilStatus": 200,
        "intervalMs": 1000
      },
      "saveResponse": {
        "enabled": false,
        "path": "",
        "onlyOk": true
      }
    },
    {
      "id": "assertions",
      "type": "code",
      "name": "Assertions in code",
      "conditional": "true",
      "code": "// The assertion helpers live in Functions (built on check()).\nassertStatus(200);\nassertJsonPath(\"$.products[0].id\", jsonPath(\"$.products[0].id\"));\nassertTimeBelow(3000);\n\n// Your own check: a pass / fail line in the log, the code keeps running.\nconst prices = jsonPath(\"$.products[*].price\");\ncheck(\"every price is positive\", prices.every((p) => p > 0), { actual: prices });",
      "requests": []
    },
    {
      "id": "xml",
      "type": "request",
      "name": "Read an XML document",
      "conditional": "true",
      "method": "GET",
      "url": "$echoApi/xml",
      "params": [],
      "headers": [],
      "bodyMode": "raw",
      "body": "",
      "multipart": [],
      "bodyFile": {
        "path": "",
        "contentType": ""
      },
      "followRedirects": true,
      "httpVersion": "inherit",
      "auth": {
        "type": "inherit"
      },
      "extract": [],
      "checks": [
        {
          "enabled": true,
          "target": "status",
          "path": "",
          "op": "equals",
          "value": "200"
        },
        {
          "enabled": true,
          "target": "xpath",
          "path": "/slideshow/@title",
          "op": "equals",
          "value": "Sample Slide Show"
        },
        {
          "enabled": true,
          "target": "xpath",
          "path": "//slide",
          "op": "count",
          "value": "2"
        }
      ],
      "loop": {
        "enabled": false,
        "count": 5,
        "untilStatus": 200,
        "intervalMs": 1000
      },
      "saveResponse": {
        "enabled": false,
        "path": "",
        "onlyOk": true
      }
    }
  ]
}
