Socket
Socket
Sign inDemoInstall

api-test

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-test - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

test/api-test/user-signup+login.md

7

classes/Case.js

@@ -25,2 +25,7 @@ 'use strict'

/**
* @property {string}
*/
Case.prototype.postUrl
/**
* @property {Obj}

@@ -61,3 +66,3 @@ */

request({
url: options.baseUrl + testName,
url: options.baseUrl + (that.postUrl || testName),
method: 'POST',

@@ -64,0 +69,0 @@ json: post

16

classes/Obj.js

@@ -91,4 +91,12 @@ 'use strict'

Obj.empty = new Obj(0)
Obj.empty.push('empty')
/**
* Get an empty Obj already parsed
* This obj, when parsed, will give `{}`
* @returns {Obj}
*/
Obj.empty = function () {
var obj = new Obj(0)
obj.push('({})')
return obj.parse()
}

@@ -278,4 +286,2 @@ module.exports = Obj

return true
}
Obj.empty.parse()
}
{
"name": "api-test",
"version": "1.1.0",
"version": "1.2.0",
"author": "Sitegui <sitegui@sitegui.com.br>",

@@ -5,0 +5,0 @@ "description": "API testing made simple",

@@ -230,10 +230,11 @@ /**

function parseCasePost(testCase, els, i) {
if (checkHeader(els[i], 3, 'Post')) {
if (checkHeader(els[i], 3, /^Post( |$)/)) {
if (!(els[i + 1] instanceof Obj)) {
throw new ParseError('Expected an {obj}', els[i + 1])
}
testCase.postUrl = els[i].value === 'Post' ? '' : els[i].value.substr(4).trim()
testCase.post = els[i + 1].parse()
i += 2
} else {
testCase.post = Obj.empty
testCase.post = Obj.empty()
}

@@ -252,3 +253,3 @@ return i

function parseCaseOut(testCase, els, i) {
if (checkHeader(els[i], 3) && els[i].value.match(/^Out( \d{3})?$/)) {
if (checkHeader(els[i], 3, /^Out( \d{3})?$/)) {
if (!(els[i + 1] instanceof Obj)) {

@@ -261,3 +262,3 @@ throw new ParseError('Expected an {obj}', els[i + 1])

} else {
testCase.out = Obj.empty
testCase.out = Obj.empty()
testCase.statusCode = 200

@@ -293,7 +294,17 @@ }

* @param {number} level
* @param {string} [value] default: no value checking
* @param {(string|RegExp)} [value] default: no value checking
* @returns {boolean}
*/
function checkHeader(x, level, value) {
return x instanceof Header && x.level === level && (!value || x.value === value)
if (!(x instanceof Header) || x.level !== level) {
return false
}
if (value) {
if (value instanceof RegExp) {
return value.test(x.value)
} else {
return value === x.value
}
}
return true
}

@@ -87,3 +87,3 @@ # API Test

* `Post`: the JSON body to send by POST. Must start with a header like `### Post`. Default: empty JSON object `{}`
* `Post`: the JSON body to send by POST. Must start with a header like `### Post [_url_]`. Default: empty JSON object `{}`. The _url_ is optional and defaults to the test name
* `Out`: the expected JSON output. Must start with a header like `### Out [_statusCode_]`. Default: no output checking. The _statusCode_ is optional and defaults to 200

@@ -182,3 +182,2 @@ * `Finds`: optional DB assertions. Must start with a header like `### Find in _collection_`

## TODO
* Make request to arbitrary endpoints in a test case
* Make keys less restrictive
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc