{
  "version": 12,
  "name": "04_checks_catalogue",
  "description": "Example: one request per check target, showing the operators of each — status, time, header, body, json, xpath and JSON schema. No code needed: checks live on the request.",
  "globals": [
    {
      "name": "$baseUrl",
      "value": "https://httpbin.org"
    },
    {
      "name": "$dummy",
      "value": "https://dummyjson.com"
    }
  ],
  "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": [],
  "tags": [
    "example",
    "checks",
    "assertions"
  ],
  "steps": [
    {
      "checks": [
        {
          "op": "equals",
          "target": "status",
          "value": "201"
        },
        {
          "op": "equals",
          "target": "status",
          "value": "2xx"
        },
        {
          "op": "equals",
          "target": "status",
          "value": "200-299"
        },
        {
          "op": "equals",
          "target": "status",
          "value": "200, 201"
        },
        {
          "op": "notEquals",
          "target": "status",
          "value": "500"
        }
      ],
      "id": "status-checks",
      "method": "GET",
      "name": "Status: exact, class, range, list, notEquals",
      "type": "request",
      "url": "$baseUrl/status/201"
    },
    {
      "checks": [
        {
          "op": "equals",
          "target": "status",
          "value": "404"
        }
      ],
      "id": "expected-404",
      "method": "GET",
      "name": "Status: a negative test expecting 404",
      "type": "request",
      "url": "$baseUrl/status/404"
    },
    {
      "checks": [
        {
          "op": "gte",
          "target": "time",
          "value": "1000"
        },
        {
          "op": "lt",
          "target": "time",
          "value": "10000"
        }
      ],
      "id": "time-checks",
      "method": "GET",
      "name": "Time: response time limits",
      "type": "request",
      "url": "$baseUrl/delay/1"
    },
    {
      "checks": [
        {
          "op": "exists",
          "path": "Content-Type",
          "target": "header",
          "value": ""
        },
        {
          "op": "notExists",
          "path": "X-Not-There",
          "target": "header",
          "value": ""
        },
        {
          "op": "equals",
          "path": "Content-Type",
          "target": "header",
          "value": "application/json"
        },
        {
          "op": "notContains",
          "path": "Content-Type",
          "target": "header",
          "value": "xml"
        },
        {
          "op": "matches",
          "path": "Content-Length",
          "target": "header",
          "value": "^\\d+$"
        }
      ],
      "id": "header-checks",
      "method": "GET",
      "name": "Header: exists, notExists, equals, contains, matches",
      "type": "request",
      "url": "$baseUrl/json"
    },
    {
      "checks": [
        {
          "op": "contains",
          "target": "body",
          "value": "Disallow: /deny"
        },
        {
          "op": "notContains",
          "target": "body",
          "value": "Allow: /"
        },
        {
          "op": "matches",
          "target": "body",
          "value": "User-agent: \\*"
        },
        {
          "op": "equals",
          "target": "body",
          "value": "User-agent: *\nDisallow: /deny\n"
        }
      ],
      "id": "body-checks",
      "method": "GET",
      "name": "Body: contains, notContains, matches, equals",
      "type": "request",
      "url": "$baseUrl/robots.txt"
    },
    {
      "checks": [
        {
          "op": "equals",
          "path": "$.id",
          "target": "json",
          "value": "1"
        },
        {
          "op": "type",
          "path": "$.title",
          "target": "json",
          "value": "string"
        },
        {
          "op": "type",
          "path": "$.price",
          "target": "json",
          "value": "number"
        },
        {
          "op": "type",
          "path": "$.tags",
          "target": "json",
          "value": "array"
        },
        {
          "op": "gt",
          "path": "$.price",
          "target": "json",
          "value": "0"
        },
        {
          "op": "lte",
          "path": "$.rating",
          "target": "json",
          "value": "5"
        },
        {
          "op": "length",
          "path": "$.images",
          "target": "json",
          "value": "1"
        },
        {
          "op": "notExists",
          "path": "$.discontinued",
          "target": "json",
          "value": ""
        },
        {
          "op": "exists",
          "path": "$.reviews[0].rating",
          "target": "json",
          "value": ""
        }
      ],
      "id": "json-checks",
      "method": "GET",
      "name": "JSON path: equals, type, length, numeric compare",
      "type": "request",
      "url": "$dummy/products/1"
    },
    {
      "checks": [
        {
          "op": "equals",
          "path": "/slideshow/@title",
          "target": "xpath",
          "value": "Sample Slide Show"
        },
        {
          "op": "count",
          "path": "//slide",
          "target": "xpath",
          "value": "2"
        },
        {
          "op": "contains",
          "path": "//slide[2]/title",
          "target": "xpath",
          "value": "Overview"
        },
        {
          "op": "exists",
          "path": "//slideshow/@author",
          "target": "xpath",
          "value": ""
        }
      ],
      "id": "xpath-checks",
      "method": "GET",
      "name": "XPath on an XML response",
      "type": "request",
      "url": "$baseUrl/xml"
    },
    {
      "checks": [
        {
          "op": "valid",
          "target": "schema",
          "value": "{\"type\":\"object\",\"required\":[\"id\",\"firstName\",\"lastName\",\"age\",\"email\"],\"properties\":{\"id\":{\"type\":\"integer\"},\"firstName\":{\"type\":\"string\",\"minLength\":1},\"lastName\":{\"type\":\"string\"},\"age\":{\"type\":\"integer\",\"minimum\":0},\"email\":{\"type\":\"string\",\"pattern\":\"@\"}}}"
        }
      ],
      "id": "schema-check",
      "method": "GET",
      "name": "JSON Schema validation (contract test)",
      "params": [
        {
          "name": "select",
          "value": "firstName,lastName,age,email"
        }
      ],
      "type": "request",
      "url": "$dummy/users/1"
    }
  ]
}
