mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Change endpoint from persons to people
This commit is contained in:
22
backend/apis/nodejs/node_modules/supertest/LICENSE
generated
vendored
Normal file
22
backend/apis/nodejs/node_modules/supertest/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
338
backend/apis/nodejs/node_modules/supertest/README.md
generated
vendored
Normal file
338
backend/apis/nodejs/node_modules/supertest/README.md
generated
vendored
Normal file
@ -0,0 +1,338 @@
|
||||
# [SuperTest](https://ladjs.github.io/superagent/)
|
||||
|
||||
[![code coverage][coverage-badge]][coverage]
|
||||
[![Build Status][travis-badge]][travis]
|
||||
[![Dependencies][dependencies-badge]][dependencies]
|
||||
[![PRs Welcome][prs-badge]][prs]
|
||||
[![MIT License][license-badge]][license]
|
||||
|
||||
> HTTP assertions made easy via [superagent](http://github.com/ladjs/superagent). Maintained for [Forward Email](https://github.com/forwardemail) and [Lad](https://github.com/ladjs).
|
||||
|
||||
## About
|
||||
|
||||
The motivation with this module is to provide a high-level abstraction for testing
|
||||
HTTP, while still allowing you to drop down to the [lower-level API](https://ladjs.github.io/superagent/) provided by superagent.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Install SuperTest as an npm module and save it to your package.json file as a development dependency:
|
||||
|
||||
```bash
|
||||
npm install supertest --save-dev
|
||||
```
|
||||
|
||||
Once installed it can now be referenced by simply calling ```require('supertest');```
|
||||
|
||||
## Example
|
||||
|
||||
You may pass an `http.Server`, or a `Function` to `request()` - if the server is not
|
||||
already listening for connections then it is bound to an ephemeral port for you so
|
||||
there is no need to keep track of ports.
|
||||
|
||||
SuperTest works with any test framework, here is an example without using any
|
||||
test framework at all:
|
||||
|
||||
```js
|
||||
const request = require('supertest');
|
||||
const express = require('express');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.get('/user', function(req, res) {
|
||||
res.status(200).json({ name: 'john' });
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/user')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Content-Length', '15')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
```
|
||||
|
||||
To enable http2 protocol, simply append an options to `request` or `request.agent`:
|
||||
|
||||
```js
|
||||
const request = require('supertest');
|
||||
const express = require('express');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.get('/user', function(req, res) {
|
||||
res.status(200).json({ name: 'john' });
|
||||
});
|
||||
|
||||
request(app, { http2: true })
|
||||
.get('/user')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Content-Length', '15')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
request.agent(app, { http2: true })
|
||||
.get('/user')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Content-Length', '15')
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
```
|
||||
|
||||
Here's an example with mocha, note how you can pass `done` straight to any of the `.expect()` calls:
|
||||
|
||||
```js
|
||||
describe('GET /user', function() {
|
||||
it('responds with json', function(done) {
|
||||
request(app)
|
||||
.get('/user')
|
||||
.set('Accept', 'application/json')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
You can use `auth` method to pass HTTP username and password in the same way as in the [superagent](http://ladjs.github.io/superagent/#authentication):
|
||||
|
||||
```js
|
||||
describe('GET /user', function() {
|
||||
it('responds with json', function(done) {
|
||||
request(app)
|
||||
.get('/user')
|
||||
.auth('username', 'password')
|
||||
.set('Accept', 'application/json')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
One thing to note with the above statement is that superagent now sends any HTTP
|
||||
error (anything other than a 2XX response code) to the callback as the first argument if
|
||||
you do not add a status code expect (i.e. `.expect(302)`).
|
||||
|
||||
If you are using the `.end()` method `.expect()` assertions that fail will
|
||||
not throw - they will return the assertion as an error to the `.end()` callback. In
|
||||
order to fail the test case, you will need to rethrow or pass `err` to `done()`, as follows:
|
||||
|
||||
```js
|
||||
describe('POST /users', function() {
|
||||
it('responds with json', function(done) {
|
||||
request(app)
|
||||
.post('/users')
|
||||
.send({name: 'john'})
|
||||
.set('Accept', 'application/json')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(function(err, res) {
|
||||
if (err) return done(err);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
You can also use promises:
|
||||
|
||||
```js
|
||||
describe('GET /users', function() {
|
||||
it('responds with json', function() {
|
||||
return request(app)
|
||||
.get('/users')
|
||||
.set('Accept', 'application/json')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.then(response => {
|
||||
expect(response.body.email).toEqual('foo@bar.com');
|
||||
})
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Or async/await syntax:
|
||||
|
||||
```js
|
||||
describe('GET /users', function() {
|
||||
it('responds with json', async function() {
|
||||
const response = await request(app)
|
||||
.get('/users')
|
||||
.set('Accept', 'application/json')
|
||||
expect(response.headers["Content-Type"]).toMatch(/json/);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body.email).toEqual('foo@bar.com');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Expectations are run in the order of definition. This characteristic can be used
|
||||
to modify the response body or headers before executing an assertion.
|
||||
|
||||
```js
|
||||
describe('POST /user', function() {
|
||||
it('user.name should be an case-insensitive match for "john"', function(done) {
|
||||
request(app)
|
||||
.post('/user')
|
||||
.send('name=john') // x-www-form-urlencoded upload
|
||||
.set('Accept', 'application/json')
|
||||
.expect(function(res) {
|
||||
res.body.id = 'some fixed id';
|
||||
res.body.name = res.body.name.toLowerCase();
|
||||
})
|
||||
.expect(200, {
|
||||
id: 'some fixed id',
|
||||
name: 'john'
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Anything you can do with superagent, you can do with supertest - for example multipart file uploads!
|
||||
|
||||
```js
|
||||
request(app)
|
||||
.post('/')
|
||||
.field('name', 'my awesome avatar')
|
||||
.field('complex_object', '{"attribute": "value"}', {contentType: 'application/json'})
|
||||
.attach('avatar', 'test/fixtures/avatar.jpg')
|
||||
...
|
||||
```
|
||||
|
||||
Passing the app or url each time is not necessary, if you're testing
|
||||
the same host you may simply re-assign the request variable with the
|
||||
initialization app or url, a new `Test` is created per `request.VERB()` call.
|
||||
|
||||
```js
|
||||
request = request('http://localhost:5555');
|
||||
|
||||
request.get('/').expect(200, function(err){
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
request.get('/').expect('heya', function(err){
|
||||
console.log(err);
|
||||
});
|
||||
```
|
||||
|
||||
Here's an example with mocha that shows how to persist a request and its cookies:
|
||||
|
||||
```js
|
||||
const request = require('supertest');
|
||||
const should = require('should');
|
||||
const express = require('express');
|
||||
const cookieParser = require('cookie-parser');
|
||||
|
||||
describe('request.agent(app)', function() {
|
||||
const app = express();
|
||||
app.use(cookieParser());
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.cookie('cookie', 'hey');
|
||||
res.send();
|
||||
});
|
||||
|
||||
app.get('/return', function(req, res) {
|
||||
if (req.cookies.cookie) res.send(req.cookies.cookie);
|
||||
else res.send(':(')
|
||||
});
|
||||
|
||||
const agent = request.agent(app);
|
||||
|
||||
it('should save cookies', function(done) {
|
||||
agent
|
||||
.get('/')
|
||||
.expect('set-cookie', 'cookie=hey; Path=/', done);
|
||||
});
|
||||
|
||||
it('should send cookies', function(done) {
|
||||
agent
|
||||
.get('/return')
|
||||
.expect('hey', done);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
There is another example that is introduced by the file [agency.js](https://github.com/ladjs/superagent/blob/master/test/node/agency.js)
|
||||
|
||||
Here is an example where 2 cookies are set on the request.
|
||||
|
||||
```js
|
||||
agent(app)
|
||||
.get('/api/content')
|
||||
.set('Cookie', ['nameOne=valueOne;nameTwo=valueTwo'])
|
||||
.send()
|
||||
.expect(200)
|
||||
.end((err, res) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
expect(res.text).to.be.equal('hey');
|
||||
return done();
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
You may use any [superagent](http://github.com/ladjs/superagent) methods,
|
||||
including `.write()`, `.pipe()` etc and perform assertions in the `.end()` callback
|
||||
for lower-level needs.
|
||||
|
||||
### .expect(status[, fn])
|
||||
|
||||
Assert response `status` code.
|
||||
|
||||
### .expect(status, body[, fn])
|
||||
|
||||
Assert response `status` code and `body`.
|
||||
|
||||
### .expect(body[, fn])
|
||||
|
||||
Assert response `body` text with a string, regular expression, or
|
||||
parsed body object.
|
||||
|
||||
### .expect(field, value[, fn])
|
||||
|
||||
Assert header `field` `value` with a string or regular expression.
|
||||
|
||||
### .expect(function(res) {})
|
||||
|
||||
Pass a custom assertion function. It'll be given the response object to check. If the check fails, throw an error.
|
||||
|
||||
```js
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(hasPreviousAndNextKeys)
|
||||
.end(done);
|
||||
|
||||
function hasPreviousAndNextKeys(res) {
|
||||
if (!('next' in res.body)) throw new Error("missing next key");
|
||||
if (!('prev' in res.body)) throw new Error("missing prev key");
|
||||
}
|
||||
```
|
||||
|
||||
### .end(fn)
|
||||
|
||||
Perform the request and invoke `fn(err, res)`.
|
||||
|
||||
## Notes
|
||||
|
||||
Inspired by [api-easy](https://github.com/flatiron/api-easy) minus vows coupling.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/ladjs/supertest.svg
|
||||
[coverage]: https://codecov.io/gh/ladjs/supertest
|
||||
[travis-badge]: https://travis-ci.org/ladjs/supertest.svg?branch=master
|
||||
[travis]: https://travis-ci.org/ladjs/supertest
|
||||
[dependencies-badge]: https://david-dm.org/ladjs/supertest/status.svg
|
||||
[dependencies]: https://david-dm.org/ladjs/supertest
|
||||
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
||||
[prs]: http://makeapullrequest.com
|
||||
[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
|
||||
[license]: https://github.com/ladjs/supertest/blob/master/LICENSE
|
61
backend/apis/nodejs/node_modules/supertest/index.js
generated
vendored
Normal file
61
backend/apis/nodejs/node_modules/supertest/index.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const methods = require('methods');
|
||||
let http2;
|
||||
try {
|
||||
http2 = require('http2'); // eslint-disable-line global-require
|
||||
} catch (_) {
|
||||
// eslint-disable-line no-empty
|
||||
}
|
||||
const Test = require('./lib/test.js');
|
||||
const agent = require('./lib/agent.js');
|
||||
|
||||
/**
|
||||
* Test against the given `app`,
|
||||
* returning a new `Test`.
|
||||
*
|
||||
* @param {Function|Server|String} app
|
||||
* @return {Test}
|
||||
* @api public
|
||||
*/
|
||||
module.exports = function(app, options = {}) {
|
||||
const obj = {};
|
||||
|
||||
if (typeof app === 'function') {
|
||||
if (options.http2) {
|
||||
if (!http2) {
|
||||
throw new Error(
|
||||
'supertest: this version of Node.js does not support http2'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methods.forEach(function(method) {
|
||||
obj[method] = function(url) {
|
||||
var test = new Test(app, method, url, options.http2);
|
||||
if (options.http2) {
|
||||
test.http2();
|
||||
}
|
||||
return test;
|
||||
};
|
||||
});
|
||||
|
||||
// Support previous use of del
|
||||
obj.del = obj.delete;
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose `Test`
|
||||
*/
|
||||
module.exports.Test = Test;
|
||||
|
||||
/**
|
||||
* Expose the agent function
|
||||
*/
|
||||
module.exports.agent = agent;
|
89
backend/apis/nodejs/node_modules/supertest/lib/agent.js
generated
vendored
Normal file
89
backend/apis/nodejs/node_modules/supertest/lib/agent.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const { agent: Agent } = require('superagent');
|
||||
const methods = require('methods');
|
||||
const http = require('http');
|
||||
let http2;
|
||||
try {
|
||||
http2 = require('http2'); // eslint-disable-line global-require
|
||||
} catch (_) {
|
||||
// eslint-disable-line no-empty
|
||||
}
|
||||
const Test = require('./test.js');
|
||||
|
||||
/**
|
||||
* Initialize a new `TestAgent`.
|
||||
*
|
||||
* @param {Function|Server} app
|
||||
* @param {Object} options
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function TestAgent(app, options = {}) {
|
||||
if (!(this instanceof TestAgent)) return new TestAgent(app, options);
|
||||
|
||||
const agent = new Agent(options);
|
||||
Object.assign(this, agent);
|
||||
|
||||
this._options = options;
|
||||
|
||||
if (typeof app === 'function') {
|
||||
if (options.http2) {
|
||||
if (!http2) {
|
||||
throw new Error(
|
||||
'supertest: this version of Node.js does not support http2'
|
||||
);
|
||||
}
|
||||
app = http2.createServer(app); // eslint-disable-line no-param-reassign
|
||||
} else {
|
||||
app = http.createServer(app); // eslint-disable-line no-param-reassign
|
||||
}
|
||||
}
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherits from `Agent.prototype`.
|
||||
*/
|
||||
|
||||
Object.setPrototypeOf(TestAgent.prototype, Agent.prototype);
|
||||
|
||||
// set a host name
|
||||
TestAgent.prototype.host = function(host) {
|
||||
this._host = host;
|
||||
return this;
|
||||
};
|
||||
|
||||
// override HTTP verb methods
|
||||
methods.forEach(function(method) {
|
||||
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
|
||||
const req = new Test(this.app, method.toUpperCase(), url);
|
||||
if (this._options.http2) {
|
||||
req.http2();
|
||||
}
|
||||
|
||||
if (this._host) {
|
||||
req.set('host', this._host);
|
||||
}
|
||||
|
||||
req.on('response', this._saveCookies.bind(this));
|
||||
req.on('redirect', this._saveCookies.bind(this));
|
||||
req.on('redirect', this._attachCookies.bind(this, req));
|
||||
this._setDefaults(req);
|
||||
this._attachCookies(req);
|
||||
|
||||
return req;
|
||||
};
|
||||
});
|
||||
|
||||
TestAgent.prototype.del = TestAgent.prototype.delete;
|
||||
|
||||
/**
|
||||
* Expose `Agent`.
|
||||
*/
|
||||
|
||||
module.exports = TestAgent;
|
361
backend/apis/nodejs/node_modules/supertest/lib/test.js
generated
vendored
Normal file
361
backend/apis/nodejs/node_modules/supertest/lib/test.js
generated
vendored
Normal file
@ -0,0 +1,361 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const { inspect } = require('util');
|
||||
const http = require('http');
|
||||
const { STATUS_CODES } = require('http');
|
||||
const { Server } = require('tls');
|
||||
const { deepStrictEqual } = require('assert');
|
||||
const { Request } = require('superagent');
|
||||
let http2;
|
||||
try {
|
||||
http2 = require('http2'); // eslint-disable-line global-require
|
||||
} catch (_) {
|
||||
// eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
/** @typedef {import('superagent').Response} Response */
|
||||
|
||||
class Test extends Request {
|
||||
/**
|
||||
* Initialize a new `Test` with the given `app`,
|
||||
* request `method` and `path`.
|
||||
*
|
||||
* @param {Server} app
|
||||
* @param {String} method
|
||||
* @param {String} path
|
||||
* @api public
|
||||
*/
|
||||
constructor (app, method, path, optHttp2) {
|
||||
super(method.toUpperCase(), path);
|
||||
|
||||
if (typeof app === 'function') {
|
||||
if (optHttp2) {
|
||||
app = http2.createServer(app); // eslint-disable-line no-param-reassign
|
||||
} else {
|
||||
app = http.createServer(app); // eslint-disable-line no-param-reassign
|
||||
}
|
||||
}
|
||||
|
||||
this.redirects(0);
|
||||
this.buffer();
|
||||
this.app = app;
|
||||
this._asserts = [];
|
||||
this.url = typeof app === 'string'
|
||||
? app + path
|
||||
: this.serverAddress(app, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL, extracted from a server.
|
||||
*
|
||||
* @param {Server} app
|
||||
* @param {String} path
|
||||
* @returns {String} URL address
|
||||
* @api private
|
||||
*/
|
||||
serverAddress(app, path) {
|
||||
const addr = app.address();
|
||||
|
||||
if (!addr) this._server = app.listen(0);
|
||||
const port = app.address().port;
|
||||
const protocol = app instanceof Server ? 'https' : 'http';
|
||||
return protocol + '://127.0.0.1:' + port + path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expectations:
|
||||
*
|
||||
* .expect(200)
|
||||
* .expect(200, fn)
|
||||
* .expect(200, body)
|
||||
* .expect('Some body')
|
||||
* .expect('Some body', fn)
|
||||
* .expect(['json array body', { key: 'val' }])
|
||||
* .expect('Content-Type', 'application/json')
|
||||
* .expect('Content-Type', 'application/json', fn)
|
||||
* .expect(fn)
|
||||
* .expect([200, 404])
|
||||
*
|
||||
* @return {Test}
|
||||
* @api public
|
||||
*/
|
||||
expect(a, b, c) {
|
||||
// callback
|
||||
if (typeof a === 'function') {
|
||||
this._asserts.push(wrapAssertFn(a));
|
||||
return this;
|
||||
}
|
||||
if (typeof b === 'function') this.end(b);
|
||||
if (typeof c === 'function') this.end(c);
|
||||
|
||||
// status
|
||||
if (typeof a === 'number') {
|
||||
this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a)));
|
||||
// body
|
||||
if (typeof b !== 'function' && arguments.length > 1) {
|
||||
this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// multiple statuses
|
||||
if (Array.isArray(a) && a.length > 0 && a.every(val => typeof val === 'number')) {
|
||||
this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a)));
|
||||
return this;
|
||||
}
|
||||
|
||||
// header field
|
||||
if (typeof b === 'string' || typeof b === 'number' || b instanceof RegExp) {
|
||||
this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, { name: '' + a, value: b })));
|
||||
return this;
|
||||
}
|
||||
|
||||
// body
|
||||
this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defer invoking superagent's `.end()` until
|
||||
* the server is listening.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @api public
|
||||
*/
|
||||
end(fn) {
|
||||
const server = this._server;
|
||||
|
||||
super.end((err, res) => {
|
||||
const localAssert = () => {
|
||||
this.assert(err, res, fn);
|
||||
};
|
||||
|
||||
if (server && server._handle) return server.close(localAssert);
|
||||
|
||||
localAssert();
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions and invoke `fn(err, res)`.
|
||||
*
|
||||
* @param {?Error} resError
|
||||
* @param {Response} res
|
||||
* @param {Function} fn
|
||||
* @api private
|
||||
*/
|
||||
assert(resError, res, fn) {
|
||||
let errorObj;
|
||||
|
||||
// check for unexpected network errors or server not running/reachable errors
|
||||
// when there is no response and superagent sends back a System Error
|
||||
// do not check further for other asserts, if any, in such case
|
||||
// https://nodejs.org/api/errors.html#errors_common_system_errors
|
||||
const sysErrors = {
|
||||
ECONNREFUSED: 'Connection refused',
|
||||
ECONNRESET: 'Connection reset by peer',
|
||||
EPIPE: 'Broken pipe',
|
||||
ETIMEDOUT: 'Operation timed out'
|
||||
};
|
||||
|
||||
if (!res && resError) {
|
||||
if (resError instanceof Error && resError.syscall === 'connect'
|
||||
&& Object.getOwnPropertyNames(sysErrors).indexOf(resError.code) >= 0) {
|
||||
errorObj = new Error(resError.code + ': ' + sysErrors[resError.code]);
|
||||
} else {
|
||||
errorObj = resError;
|
||||
}
|
||||
}
|
||||
|
||||
// asserts
|
||||
for (let i = 0; i < this._asserts.length && !errorObj; i += 1) {
|
||||
errorObj = this._assertFunction(this._asserts[i], res);
|
||||
}
|
||||
|
||||
// set unexpected superagent error if no other error has occurred.
|
||||
if (!errorObj && resError instanceof Error && (!res || resError.status !== res.status)) {
|
||||
errorObj = resError;
|
||||
}
|
||||
|
||||
fn.call(this, errorObj || null, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions on a response body and return an Error upon failure.
|
||||
*
|
||||
* @param {Mixed} body
|
||||
* @param {Response} res
|
||||
* @return {?Error}
|
||||
* @api private
|
||||
*/// eslint-disable-next-line class-methods-use-this
|
||||
_assertBody(body, res) {
|
||||
const isRegexp = body instanceof RegExp;
|
||||
|
||||
// parsed
|
||||
if (typeof body === 'object' && !isRegexp) {
|
||||
try {
|
||||
deepStrictEqual(body, res.body);
|
||||
} catch (err) {
|
||||
const a = inspect(body);
|
||||
const b = inspect(res.body);
|
||||
return error('expected ' + a + ' response body, got ' + b, body, res.body);
|
||||
}
|
||||
} else if (body !== res.text) {
|
||||
// string
|
||||
const a = inspect(body);
|
||||
const b = inspect(res.text);
|
||||
|
||||
// regexp
|
||||
if (isRegexp) {
|
||||
if (!body.test(res.text)) {
|
||||
return error('expected body ' + b + ' to match ' + body, body, res.body);
|
||||
}
|
||||
} else {
|
||||
return error('expected ' + a + ' response body, got ' + b, body, res.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions on a response header and return an Error upon failure.
|
||||
*
|
||||
* @param {Object} header
|
||||
* @param {Response} res
|
||||
* @return {?Error}
|
||||
* @api private
|
||||
*/// eslint-disable-next-line class-methods-use-this
|
||||
_assertHeader(header, res) {
|
||||
const field = header.name;
|
||||
const actual = res.header[field.toLowerCase()];
|
||||
const fieldExpected = header.value;
|
||||
|
||||
if (typeof actual === 'undefined') return new Error('expected "' + field + '" header field');
|
||||
// This check handles header values that may be a String or single element Array
|
||||
if ((Array.isArray(actual) && actual.toString() === fieldExpected)
|
||||
|| fieldExpected === actual) {
|
||||
return;
|
||||
}
|
||||
if (fieldExpected instanceof RegExp) {
|
||||
if (!fieldExpected.test(actual)) {
|
||||
return new Error('expected "' + field + '" matching '
|
||||
+ fieldExpected + ', got "' + actual + '"');
|
||||
}
|
||||
} else {
|
||||
return new Error('expected "' + field + '" of "' + fieldExpected + '", got "' + actual + '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions on the response status and return an Error upon failure.
|
||||
*
|
||||
* @param {Number} status
|
||||
* @param {Response} res
|
||||
* @return {?Error}
|
||||
* @api private
|
||||
*/// eslint-disable-next-line class-methods-use-this
|
||||
_assertStatus(status, res) {
|
||||
if (res.status !== status) {
|
||||
const a = STATUS_CODES[status];
|
||||
const b = STATUS_CODES[res.status];
|
||||
return new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions on the response status and return an Error upon failure.
|
||||
*
|
||||
* @param {Array<Number>} statusArray
|
||||
* @param {Response} res
|
||||
* @return {?Error}
|
||||
* @api private
|
||||
*/// eslint-disable-next-line class-methods-use-this
|
||||
_assertStatusArray(statusArray, res) {
|
||||
if (!statusArray.includes(res.status)) {
|
||||
const b = STATUS_CODES[res.status];
|
||||
const expectedList = statusArray.join(', ');
|
||||
return new Error(
|
||||
'expected one of "' + expectedList + '", got ' + res.status + ' "' + b + '"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an assertion by calling a function and return an Error upon failure.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {Response} res
|
||||
* @return {?Error}
|
||||
* @api private
|
||||
*/// eslint-disable-next-line class-methods-use-this
|
||||
_assertFunction(fn, res) {
|
||||
let err;
|
||||
try {
|
||||
err = fn(res);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
if (err instanceof Error) return err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps an assert function into another.
|
||||
* The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it.
|
||||
*
|
||||
* @param {Function} assertFn
|
||||
* @returns {Function} wrapped assert function
|
||||
*/
|
||||
|
||||
function wrapAssertFn(assertFn) {
|
||||
const savedStack = new Error().stack.split('\n').slice(3);
|
||||
|
||||
return function(res) {
|
||||
let badStack;
|
||||
let err;
|
||||
try {
|
||||
err = assertFn(res);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
if (err instanceof Error && err.stack) {
|
||||
badStack = err.stack.replace(err.message, '').split('\n').slice(1);
|
||||
err.stack = [err.toString()]
|
||||
.concat(savedStack)
|
||||
.concat('----')
|
||||
.concat(badStack)
|
||||
.join('\n');
|
||||
}
|
||||
return err;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an `Error` with `msg` and results properties.
|
||||
*
|
||||
* @param {String} msg
|
||||
* @param {Mixed} expected
|
||||
* @param {Mixed} actual
|
||||
* @return {Error}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function error(msg, expected, actual) {
|
||||
const err = new Error(msg);
|
||||
err.expected = expected;
|
||||
err.actual = actual;
|
||||
err.showDiff = true;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose `Test`.
|
||||
*/
|
||||
|
||||
module.exports = Test;
|
55
backend/apis/nodejs/node_modules/supertest/package.json
generated
vendored
Normal file
55
backend/apis/nodejs/node_modules/supertest/package.json
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "supertest",
|
||||
"description": "SuperAgent driven library for testing HTTP servers",
|
||||
"version": "7.1.0",
|
||||
"author": "TJ Holowaychuk",
|
||||
"contributors": [],
|
||||
"dependencies": {
|
||||
"methods": "^1.1.2",
|
||||
"superagent": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "17",
|
||||
"@commitlint/config-conventional": "17",
|
||||
"body-parser": "^1.20.2",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"express": "^4.18.2",
|
||||
"mocha": "^10.2.0",
|
||||
"nock": "^13.3.0",
|
||||
"nyc": "^15.1.0",
|
||||
"proxyquire": "^2.1.3",
|
||||
"should": "^13.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"keywords": [
|
||||
"bdd",
|
||||
"http",
|
||||
"request",
|
||||
"superagent",
|
||||
"tdd",
|
||||
"test",
|
||||
"testing"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ladjs/supertest.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
|
||||
"lint": "eslint lib/**/*.js test/**/*.js index.js",
|
||||
"lint:fix": "eslint --fix lib/**/*.js test/**/*.js index.js",
|
||||
"pretest": "npm run lint --if-present",
|
||||
"test": "nyc --reporter=html --reporter=text mocha --exit --require should --reporter spec --check-leaks"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user