How to use the supertest.Test.prototype function in supertest

To help you get started, we’ve selected a few supertest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onehilltech / blueprint / packages / blueprint-gatekeeper / lib / testing / request.js View on Github external
* @param i       Index of user from dab file
 * @param conn    Name of database connection, or default if no name provided
 */
Test.prototype.withUserToken = function (i, conn) {
  const {user_tokens} = seed (conn);
  const gatekeeper = blueprint.lookup ('service:gatekeeper');
  const tokenGenerator = gatekeeper.getTokenGenerator ('gatekeeper:access_token');

  const accessToken = user_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a user_tokens.[${i}]`);

  return this.set ('Authorization', `Bearer ${accessToken.access_token}`);
};

Test.prototype.fromUser = Test.prototype.withUserToken;

/**
 * Creates a Blueprint testing request that has already be initialized to a client.
 *
 * @param i     Index of client from dab file
 * @param conn    Name of database connection
 */
Test.prototype.withClientToken = function (i, conn) {
  const {client_tokens} = seed (conn);
  const gatekeeper = blueprint.lookup ('service:gatekeeper');
  const tokenGenerator = gatekeeper.getTokenGenerator ('gatekeeper:access_token');

  const accessToken = client_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a client_tokens.[${i}]`);
github onehilltech / blueprint / packages / blueprint-gatekeeper / lib / testing / request.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

const assert    = require ('assert');
const { seed }  = require ('@onehilltech/blueprint-mongodb');
const { Test }  = require ('supertest');
const blueprint = require ('@onehilltech/blueprint');

/**
 * Creates a Blueprint testing request that has already be initialized to a user.
 *
 * @param i       Index of user from dab file
 * @param conn    Name of database connection, or default if no name provided
 */
Test.prototype.withUserToken = function (i, conn) {
  const {user_tokens} = seed (conn);
  const gatekeeper = blueprint.lookup ('service:gatekeeper');
  const tokenGenerator = gatekeeper.getTokenGenerator ('gatekeeper:access_token');

  const accessToken = user_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a user_tokens.[${i}]`);

  return this.set ('Authorization', `Bearer ${accessToken.access_token}`);
};

Test.prototype.fromUser = Test.prototype.withUserToken;

/**
 * Creates a Blueprint testing request that has already be initialized to a client.
 *
github onehilltech / blueprint / packages / blueprint-gatekeeper / lib / testing / request.js View on Github external
const accessToken = user_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a user_tokens.[${i}]`);

  return this.set ('Authorization', `Bearer ${accessToken.access_token}`);
};

Test.prototype.fromUser = Test.prototype.withUserToken;

/**
 * Creates a Blueprint testing request that has already be initialized to a client.
 *
 * @param i     Index of client from dab file
 * @param conn    Name of database connection
 */
Test.prototype.withClientToken = function (i, conn) {
  const {client_tokens} = seed (conn);
  const gatekeeper = blueprint.lookup ('service:gatekeeper');
  const tokenGenerator = gatekeeper.getTokenGenerator ('gatekeeper:access_token');

  const accessToken = client_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a client_tokens.[${i}]`);

  return this.set ('Authorization', `Bearer ${accessToken.access_token}`);
};

Test.prototype.fromClient = Test.prototype.withClientToken;

const {
  request
} = require ('@onehilltech/blueprint-testing');
github onehilltech / blueprint / packages / blueprint-gatekeeper / lib / testing / request.js View on Github external
* @param i     Index of client from dab file
 * @param conn    Name of database connection
 */
Test.prototype.withClientToken = function (i, conn) {
  const {client_tokens} = seed (conn);
  const gatekeeper = blueprint.lookup ('service:gatekeeper');
  const tokenGenerator = gatekeeper.getTokenGenerator ('gatekeeper:access_token');

  const accessToken = client_tokens[i].serializeSync (tokenGenerator);

  assert (!!accessToken, `The seed for ${conn} does not have a client_tokens.[${i}]`);

  return this.set ('Authorization', `Bearer ${accessToken.access_token}`);
};

Test.prototype.fromClient = Test.prototype.withClientToken;

const {
  request
} = require ('@onehilltech/blueprint-testing');

module.exports = request;

supertest

SuperAgent driven library for testing HTTP servers

MIT
Latest version published 8 months ago

Package Health Score

86 / 100
Full package analysis