{"id":24493073,"url":"https://github.com/open-node/restspec","last_synced_at":"2025-04-14T01:40:36.211Z","repository":{"id":20296036,"uuid":"23569651","full_name":"open-node/restspec","owner":"open-node","description":"restspec rest-api","archived":false,"fork":false,"pushed_at":"2022-12-09T19:19:09.000Z","size":44,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T12:50:15.492Z","etag":null,"topics":["api-test","rest-api-test","test-framework","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-node.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-02T07:42:19.000Z","updated_at":"2022-02-13T02:50:18.000Z","dependencies_parsed_at":"2023-01-13T20:53:46.376Z","dependency_job_id":null,"html_url":"https://github.com/open-node/restspec","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Frestspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Frestspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Frestspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Frestspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-node","download_url":"https://codeload.github.com/open-node/restspec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809039,"owners_count":21164893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-test","rest-api-test","test-framework","testing-tools"],"created_at":"2025-01-21T19:19:02.282Z","updated_at":"2025-04-14T01:40:36.168Z","avatar_url":"https://github.com/open-node.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restspec rest-api test\n\n## usage\n\n* npm install restspec --save-dev\n\n```js\nvar Restspec = require('restspec');\nnew Restspec(options);\n```\n\n## options\n\n* `name` String, This test's name.\n* `urlRoot` String, Url root eg. http://127.0.0.1\n* `cases` Array, Test cases.\n* `hooks` Object, Hooks function.\n  * `done` Function, Called when test cases exec done.\n* `globals.request.headers` Object,\n\n## case\n* `name` String, This is name of case\n* `uri` String, Request url is `urlRoot` concat `uri`. eg. /session\n* `verb` String, Enum `get`, `post`, `put`, `patch`, `delete` default `get`\n* `headers` Object, Request customer headers.\n* `data` Fixed, Request send data.\n* `expects`\n  * `Status` response.statusCode\n  * `JSON` assert response.body\n```js\n//case1. assert body\nJSON: {\n  id: 1,\n  name: 'Hello'\n}\n\n//case2. body is an array, assert one\nJSON: ['0', {\n  id: 1,\n  name: 'Hello'\n}]\n\n//case2. body is an array, assert all\nJSON: ['*', {\n  id: 1,\n  name: 'Hello'\n}]\n\n```\n  * `JSONTypes` assert response.body type\n  * `JSONLength` assert response.body length\n  * `Header` assert one response.headers\n```js\nHeader: ['x-content-record-total', '2']\n```\n  * `Headers` assert some response.headers\n```js\nHeaders: [\n  ['x-content-record-total', '2'],\n  ['content-type', 'application/json']\n]\n```\n\n## Advanced Usage\n\n```js\nJSON: {\n  // assert is require('assert')\n  id: function(actual, assert) {\n    assert.equal(typeof actual, 'number');\n    assert.equal(actual, 20);\n  }\n```\n\n\n```js\nvar case = {\n  name: 'This is name of case',\n  uri: '/session',\n  expects: {\n    Status: 201,\n    JSON: {\n      id: 1,\n      name: 'Hello world'\n    },\n    JSONTypes: ['parent', {\n      id: Number,\n      name: String\n    }]\n  }\n}\n```\n\n```js\nvar case = function(lastBody, lastRes) {\n  return {\n    name: 'This is function return case'\n    uri: '/session',\n    expects: {\n      Status: 201,\n      JSON: {\n        id: 1,\n        name: 'Hello world'\n      },\n      JSONTypes: ['parent', {\n        id: Number,\n        name: String\n      }]\n    }\n  }\n};\n```\n\n```js\nvar case = function(lastBody, lastRes) {\n  return new Promise(function(resolve, reject) {\n    return resolve({\n      name: 'This is function return case with promise'\n      uri: '/session',\n      expects: {\n        Status: 201,\n        JSON: {\n          id: 1,\n          name: 'Hello world'\n        },\n        JSONTypes: ['parent', {\n          id: Number,\n          name: String\n        }]\n      }\n    })\n  };\n};\n```\n\n```js\nvar case = async () =\u003e {\n  const user = await Model.findOne({ where: { id: 1 } });\n\n    // If the function is returned, it will be called.\n    return () =\u003e {\n      const { age } = user;\n\n      if (age \u003c= 18) return new Error(`Adult only: ${age}`);\n\n      return null;\n    };\n  };\n};\n```\n\n```js\nvar case = () =\u003e {\n  const age = 17;\n  // Error instances can be returned directly.\n  if (age \u003c= 18) return new Error(`Adult only: ${age}`);\n\n  return null;\n};\n```\n\n## Comment\n* cases run one by one\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Frestspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-node%2Frestspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Frestspec/lists"}