How to use supertest - 10 common examples

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 HenryGau / node-paypal-ipn / tests / subscriptionMessage.js View on Github external
it('POST will send a new IPN message to IPN listener', function(done){
		console.log('New subscription from user:', requestForm.payer_email);

		request.post('/')
			// format application/x-www-form-urlencoded
			.type('form')
			.send(requestForm)
			.expect(function(res){
				console.log('POST response body:' + JSON.stringify(res.body));
			})
			.expect(200, done);
	});
github salesforce / refocus / tests / api / v1 / collectors / pause.js View on Github external
/**
 * Copyright (c) 2018, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or
 * https://opensource.org/licenses/BSD-3-Clause
 */

/**
 * tests/api/v1/collectors/pause.js
 */
'use strict'; // eslint-disable-line strict
const supertest = require('supertest');
const Promise = require('bluebird');
supertest.Test.prototype.endAsync = Promise.promisify(supertest.Test
  .prototype.end);
const api = supertest(require('../../../../express').app);
const constants = require('../../../../api/v1/constants');
const tu = require('../../../testUtils');
const u = require('./utils');
const pausePath = '/v1/collectors/{key}/pause';
const expect = require('chai').expect;
const Collector = tu.db.Collector;
const Generator = tu.db.Generator;
const CollectorGroup = tu.db.CollectorGroup;
const GeneratorTemplate = tu.db.GeneratorTemplate;
const sgUtils = require('../generators/utils');
const gtUtil = sgUtils.gtUtil;
const sinon = require('sinon');

describe('tests/api/v1/collectors/pause.js >', () => {
github salesforce / refocus / tests / api / v1 / aspects / patch.js View on Github external
/**
 * Copyright (c) 2016, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root or
 * https://opensource.org/licenses/BSD-3-Clause
 */

/**
 * tests/api/v1/aspects/patch.js
 */
'use strict'; // eslint-disable-line strict
const supertest = require('supertest');
const Promise = require('bluebird');
supertest.Test.prototype.endAsync =
  Promise.promisify(supertest.Test.prototype.end);
const api = supertest(require('../../../../express').app);
const constants = require('../../../../api/v1/constants');
const tu = require('../../../testUtils');
const u = require('./utils');
const gu = require('../generators/utils');
const gtu = require('../generatorTemplates/utils');
const Aspect = tu.db.Aspect;
const Sample = tu.Sample;
const Generator = tu.db.Generator;
const GeneratorTemplate = tu.db.GeneratorTemplate;
const path = '/v1/aspects';
const samplePath = '/v1/samples';
const expect = require('chai').expect;
const featureToggles = require('feature-toggles');

describe('tests/api/v1/aspects/patch.js >', () => {
github salesforce / refocus / tests / collector / utils / requestUtils.js View on Github external
*/
'use strict'; // eslint-disable-line strict
const expect = require('chai').expect;
const sinon = require('sinon');
const interceptor = require('express-interceptor');
const Promise = require('bluebird');
const supertest = require('supertest');
const ms = require('ms');
const app = require('../../../express').app;
const tu = require('../../testUtils');
const forkUtils = require('./forkUtils');
const constants = require('../../../api/v1/constants');
const genPath = '/v1/generators';
const cgPath = '/v1/collectorGroups';
const api = supertest(app);
supertest.Test.prototype.end = Promise.promisify(supertest.Test.prototype.end);
supertest.Test.prototype.then = function (resolve, reject) {
  return this.end().then(resolve).catch(reject);
};

let token;

module.exports = {
  setupInterception,
  stopGenerator,
  resumeGenerator,
  clearBlocking,
  doStart,
  getGenerator,
  postGenerator,
  patchGenerator,
  putGenerator,
github salesforce / refocus / tests / api / v1 / aspects / put.js View on Github external
/**
 * tests/api/v1/aspects/put.js
 */
'use strict'; // eslint-disable-line strict
const supertest = require('supertest');
const api = supertest(require('../../../../express').app);
const constants = require('../../../../api/v1/constants');
const tu = require('../../../testUtils');
const u = require('./utils');
const gu = require('../generators/utils');
const gtu = require('../generatorTemplates/utils');
const featureToggles = require('feature-toggles');
const Promise = require('bluebird');
supertest.Test.prototype.endAsync =
  Promise.promisify(supertest.Test.prototype.end);
const Aspect = tu.db.Aspect;
const Sample = tu.Sample;
const Generator = tu.db.Generator;
const GeneratorTemplate = tu.db.GeneratorTemplate;
const path = '/v1/aspects';
const samplePath = '/v1/samples';
const expect = require('chai').expect;
const ZERO = 0;
const ONE = 1;
const TWO = 2;

describe('tests/api/v1/aspects/put.js >', () => {
  let token;
  let aspectId = 0;

  before((done) => {
github salesforce / refocus / tests / collector / utils / requestUtils.js View on Github external
'use strict'; // eslint-disable-line strict
const expect = require('chai').expect;
const sinon = require('sinon');
const interceptor = require('express-interceptor');
const Promise = require('bluebird');
const supertest = require('supertest');
const ms = require('ms');
const app = require('../../../express').app;
const tu = require('../../testUtils');
const forkUtils = require('./forkUtils');
const constants = require('../../../api/v1/constants');
const genPath = '/v1/generators';
const cgPath = '/v1/collectorGroups';
const api = supertest(app);
supertest.Test.prototype.end = Promise.promisify(supertest.Test.prototype.end);
supertest.Test.prototype.then = function (resolve, reject) {
  return this.end().then(resolve).catch(reject);
};

let token;

module.exports = {
  setupInterception,
  stopGenerator,
  resumeGenerator,
  clearBlocking,
  doStart,
  getGenerator,
  postGenerator,
  patchGenerator,
  putGenerator,
  patchCollectorGroup,
github salesforce / refocus / tests / api / v1 / common / createdAtUpdatedAtFilters.js View on Github external
* https://opensource.org/licenses/BSD-3-Clause
 */

/**
 * tests/api/v1/common/createdAtUpdatedAtFilters.js
 */
'use strict';
const supertest = require('supertest');
const api = supertest(require('../../../../express').app);
const tu = require('../../../testUtils');
const constants = require('../../../../api/v1/constants');
const expect = require('chai').expect;
const Promise = require('bluebird');
const sinon = require('sinon');
const ms = require('ms');
supertest.Test.prototype.end = Promise.promisify(supertest.Test.prototype.end);
supertest.Test.prototype.then = function (resolve, reject) {
  return this.end().then(resolve).catch(reject);
};

let clock;

/* Admin token is created at Date.now().
Fake test start time =  now - 2000d
User created at fake start time + 1d
Fake now = now - 1000d (or test start time + 1000d)
This setup helps clean teardown and test results, like only delete records
created in this test, do not delete something created before the test like
admin user, only return records created in setup, etc. */

const testStartTime = Date.now() - ms('2000d');
const createUserTime = testStartTime - ms('1d');
github peterjoseph / Reeve / tests_integration / 01_authentication.js View on Github external
test("Owner Account Login - Valid Body - 200 Response", async t => {
	const response = await request.post("api/v1.0/authentication/login").send({
		workspaceURL: testData.workspaceURL,
		emailAddress: testData.emailAddress,
		password: testData.password,
		keepSignedIn: false
	});
	t.is(response.status, 200);
	t.not(response.body.token, null);
	t.is(response.body.keepSignedIn, false);

	// Store token for future user
	testData.securityToken = `jwt ${response.body.token}`;
});
github slco-2016 / clientcomm / test / app / clientsController.js View on Github external
/* global describe it before */
const should = require('should');
const simple = require('simple-mock');
const supertest = require('supertest');
const cheerio = require('cheerio');
const APP = require('../../app/app');
const Clients = require('../../app/models/clients');
const Messages = require('../../app/models/messages');
const Users = require('../../app/models/users');
const db = require('../../app/db.js');

const primary = supertest.agent(APP);
const supervisor = supertest.agent(APP);

// a client to be created and referenced throughout tests
const uniqueID1 = '123JKL98237iuh23bkj';
const reqBody = {
  first: 'Steven',
  middle: undefined,
  last: 'Nixon',
  dob: '03/12/1990',
  targetUser: 2, // TODO: this must be the user that is logged in
  uniqueID1,
  uniqueID2: '456ABC',
};

const logInAsOwner = (done) => {
  supervisor.get('/login')
    .end(function(err, res) {
github slco-2016 / clientcomm / test / app / captureController.js View on Github external
const assert = require('assert');
const supertest = require('supertest');
const should = require('should');
const cheerio = require('cheerio');

const APP = require('../../app/app');
const Communications = require('../../app/models/communications');

const owner = supertest.agent(APP);
const anonUser = supertest.agent(APP);

const twilioAgent = supertest.agent(APP);
const smsData = require('../data/testSMSData');

const createUID = () => String(Math.random().toString(36).substring(7));

// will create a random, unique string
const inboundBodyMsg = createUID();

describe('Capture Board view', () => {
  before((done) => {
    owner.get('/login').end(function(err, res) {
      if (res.status == '302') {
        done();
      } else {

supertest

SuperAgent driven library for testing HTTP servers

MIT
Latest version published 7 months ago

Package Health Score

87 / 100
Full package analysis