Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-testing

Package Overview
Dependencies
Maintainers
21
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-testing - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

bin/api-testing.js

4

lib/actionapi.js

@@ -76,5 +76,3 @@ 'use strict';

*
* The request has not been sent when this method returns,
* and can still be modified like a superagent request.
* Call end() or then(), use use await to send the request.
* Call end(), then(), or use await to send the request.
*

@@ -81,0 +79,0 @@ * @param {Object} params

@@ -19,2 +19,41 @@ 'use strict';

};
/**
* Gets header assertion
*
* @param {Object} res Supertest Response object
* @param {string} header Name of header to check
* @param {string|RegExp} exp Expected header
* @param {?string} msg
*/
const getHeaderAssertion = (res, header, exp, msg) => {
if (/^\/.+\/$/.test(exp)) {
new _chai.Assertion(res.header[header.toLowerCase()], msg, true).to.match(exp);
} else {
new _chai.Assertion(res.header[header.toLowerCase()], msg, true).to.equal(exp);
}
};
/**
* Asserts whether a response's header was as expected
*
* @param {Object} res Supertest Response object
* @param {string} header Name of header to check
* @param {string|RegExp} exp Expected header
* @param {?string} msg
*/
assert.header = (res, header, exp, msg) => {
getHeaderAssertion(res, header, exp, msg);
};
/**
* Asserts whether a response's content type was as expected
*
* @param {Object} res Supertest Response object
* @param {string|RegExp} exp Expected content type
* @param {?string} msg
*/
assert.contentTypes = (res, exp, msg) => {
getHeaderAssertion(res, 'content-type', exp, msg);
};
});

@@ -36,5 +36,3 @@ 'use strict';

*
* The request has not been sent when this method returns,
* and can still be modified like a superagent request.
* Call end() or then(), or use await to send the request.
* Call end(), then(), or use await to send the request.
*

@@ -44,6 +42,6 @@ * @param {string} endpoint

* @param {Object|string} params
* @param {string} contentType
* @param {Object} headers
* @return {Promise<*>}
*/
async request(endpoint, method, params = {}, contentType = 'application/json') {
async request(endpoint, method, params = {}, headers = {}) {
let req;

@@ -54,3 +52,4 @@ endpoint = this.pathPrefix + endpoint;

req = this.req.get(endpoint)
.query(params);
.query(params)
.set(headers);
break;

@@ -60,3 +59,3 @@ case 'POST':

.send(params)
.set('Content-Type', contentType);
.set(headers);
break;

@@ -66,6 +65,7 @@ case 'PUT':

.send(params)
.set('Content-Type', contentType);
.set(headers);
break;
case 'DELETE':
req = this.req.del(endpoint);
req = this.req.del(endpoint)
.set(headers);
break;

@@ -79,2 +79,9 @@ default:

_objectKeysToLowerCase(headers) {
return Object.keys(headers).reduce((updatedHeaders, key) => {
updatedHeaders[key.toLowerCase()] = headers[key];
return updatedHeaders;
}, {});
}
/**

@@ -86,6 +93,7 @@ * Constructs a GET request and returns the

* @param {Object|null}params
* @param {Object} headers
* @return {Promise<*>}
*/
async get(endpoint, params = {}) {
return this.request(endpoint, 'GET', params);
async get(endpoint, params = {}, headers = {}) {
return this.request(endpoint, 'GET', params, headers);
}

@@ -99,7 +107,8 @@

* @param {Object|string} params
* @param {string} contentType
* @param {Object} headers
* @return {Promise<*>}
*/
async post(endpoint, params = {}, contentType = 'application/json') {
return this.request(endpoint, 'POST', params, contentType);
async post(endpoint, params = {}, headers = {}) {
const updatedHeaders = this._objectKeysToLowerCase(headers);
return this.request(endpoint, 'POST', params, Object.assign({ 'content-type': 'application/json' }, updatedHeaders));
}

@@ -113,7 +122,8 @@

* @param {Object|string} params
* @param {string} contentType
* @param {Object} headers
* @return {Promise<*>}
*/
async put(endpoint, params = {}, contentType = 'application/json') {
return this.request(endpoint, 'PUT', params, contentType);
async put(endpoint, params = {}, headers = {}) {
const updatedHeaders = this._objectKeysToLowerCase(headers);
return this.request(endpoint, 'PUT', params, Object.assign({ 'content-type': 'application/json' }, updatedHeaders));
}

@@ -126,6 +136,7 @@

* @param {string} endpoint
* @param {Object} headers
* @return {Promise<*>}
*/
async del(endpoint) {
return this.request(endpoint, 'DELETE');
async del(endpoint, headers = {}) {
return this.request(endpoint, 'DELETE', headers);
}

@@ -132,0 +143,0 @@ }

{
"name": "api-testing",
"version": "1.3.0",
"version": "1.4.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

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