Exemplo n.º 1
0
  before(function(done) {
    agent = supertest.agent('http://localhost:3000');

    child = util.startProcess(path.join(__dirname, '../../scenarios/hanging_workers.js'));
    setTimeout(done, 1000);
  });
Exemplo n.º 2
0
        ghost({app: app}).then(function (_ghostServer) {
            ghostServer = _ghostServer;
            request = supertest.agent(app);

        }).then(function () {
Exemplo n.º 3
0
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
======================================================================*/

var should = require('should');
var supertest = require('supertest');
var config = require('../../config.js');
if (config.server.ssl.enabled) {
  var deploymentLocation = 'https://' + config.server.url + ':' + config.server.port;
} else {
  var deploymentLocation = 'http://' + config.server.url + ':' + config.server.port;
}
var databaseLocation = 'mongodb://' + config.database.url + '/' + config.database.name;
var api = supertest.agent(deploymentLocation);
var common = require('../common/commonFunctions');
var mongoose = require('mongoose');

if (mongoose.connection.readyState === 0) {
  mongoose.connect(databaseLocation);
}

describe('GET Access Unauthorized API Testing', function() {

  it('GET Access Unauthorized', function(done) {
    api.get('/access')
      .expect(401)
      .end(function(err, res) {
        if (err) {
          return done(err);
Exemplo n.º 4
0
var should = require('should');
var supertest = require('supertest');

var server = supertest.agent('http://localhost:3000');

describe('File upload test cases',function(){
	it('should upload file',function(done){
		server
		.post('/api/photo')
		.field('filename', 'test file')
		.attach('file', 'test/test.png')
		.expect(200)
		.end(function(err,res){
			res.status.should.equal(200)
			done();
		});
	});
});
Exemplo n.º 5
0
 ghost().then(function (ghostServer) {
     request = supertest.agent(ghostServer.rootApp);
 }).then(function () {
Exemplo n.º 6
0
const assert = require('assert');
const supertest = require('supertest');
const should = require('should');
const cheerio = require('cheerio');
const APP = require('../../app/app');
const testClient = supertest.agent(APP);

describe('Alerts controller', () => {
  // login as the primary account
  before(done => {
    testClient.get('/login')
      .end(function(err, res) {
        if (res.status == '302') {
          done();
        } else {
          const $html = cheerio.load(res.text);
          const csrf = $html('input[name=_csrf]').val();

          testClient.post('/login')
            .type('form')
            .send({ _csrf: csrf })
            .send({ email: '*****@*****.**' })
            .send({ pass: '******' })
            .expect(302)
            .expect('Location', '/login-success')
            .end((err, res) => {
              done(err);
            });
        }
      });
  });
Exemplo n.º 7
0
/**
 *
 * @author apps
 * @date   16-3-10
 * @version
 */
var mocha       = require('mocha');
var should      = require('should');
var supertest   = require('supertest');
var bfw         = require('../src/framework/bfw');
var app         = bfw.getApp("haoyi-node-api");
var request = supertest.agent(app);


/*describe('get /order findById', function(){
    it('get order findById', function(done){
        request.get('/order/findById?id=605')
            /!*.set('content-type', 'application/x-www-form-urlencoded')
             .set('X-HTTP-Method-Override', 'POST')
             .send({
             username:'******',
             passwd  :'123456',
             })*!/
            .end(function(err, res){
                console.log(JSON.stringify(res));
                should.not.exists(err);
                done();
            });
    });
})
Exemplo n.º 8
0
var app = require('../')
  , mongoose = require('mongoose')
  , port = process.env.PORT || 3000
  , supertest = require('supertest')
  , should = require('should');

var request = supertest('http://localhost:' + port)
  , agent = supertest.agent('http://localhost:' + port);

var User = mongoose.model('User');

var userId, sessionId;

describe('Users & Authentication', function () {

  describe('POST /api/users', function () {
    describe('Invalid parameters', function () {
      it('should return JSON and a 422', function (done) {
        request
          .post('/api/users')
          .send({ username: '******', email: 'foobar', password: '******', birthday: new Date(2000, 0, 1) })
          .expect('Content-Type', /json/)
          .expect(422, done);
      });
      it('should not create document', function (done) {
        User.findOne({ username: '******' }, function (err, user) {
          should.equal(user, null);
          done();
        });
      });
Exemplo n.º 9
0
var supertest = require('supertest');
//var api = supertest.agent('http://localhost:3000');
//Local db used for testing
var api = supertest.agent('http://localhost:3000');
var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;
chai.should();
chai.use(require('chai-things'));
var database = require('mongodb').Db;

var path = require('path');
var common = require(path.join(__dirname, '../common/common.js'));

var record = require('blue-button-record');

describe('Pre Test Cleanup', function () {

    before(function (done) {
        var options = {
            dbName: process.env.DBname || 'tests',
            supported_sections: ['allergies', 'procedures']
        };

        var dbinfo = record.connectDatabase('localhost', options, function (err) {
            //assert.ifError(err);
            if (err) {
                console.log(">>>> ", err);
            }

            record.clearDatabase(function (err) {
Exemplo n.º 10
0
 ghost({app: app}).then(function () {
     request = supertest.agent(app);
 }).then(function () {
Exemplo n.º 11
0
 before(() => {
   const app = Express()
   app.use('/api', apiRoutes)
   agent = request.agent(app)
 })
 beforeEach('Create guest agent', function () {
   guestAgent = supertest.agent(app);
 });
Exemplo n.º 13
0
 beforeEach(function() {
     agent = request.agent(phonegap());
 });
Exemplo n.º 14
0
var mocha = require('mocha');
var supertest = require('supertest');
var app = require('../../../index');
var should = require('should');
var sinon = require('sinon');
var utils = require('../../utils');
var passport = require('passport');
var http = require('http');

var mongoose = require('mongoose');
var passportConfig = require('../../../config/passport');
var auth = require('../../../controllers/auth')
var User = require('../../../models/user');

var agent = supertest.agent(app);

describe('Auth controller', function() {

  it('should have a login method', function() {
    auth.login.should.exist;
    (typeof auth.login).should.equal('function');
  });

  it('should have a signup method', function() {
    auth.signup.should.exist;
    (typeof auth.signup).should.equal('function');
  });

  it('should have a logout method', function() {
    auth.logout.should.exist;
Exemplo n.º 15
0
const supertest = require("supertest");
const should = require("should");
const app = require('../server');
const server = supertest.agent(app);

describe('mimeTypesIcons', () => {

  describe('type found "image.png"', () => {
    it('it should return status code 301', (done) => {
      server
      .get('/image.png')
      .expect(301)
      .end((err, res) => {
        res.status.should.equal(301);
        done();
      });
    });
  });

  describe('type and icon size found "image.gif?size=96"', () => {
    it('it should return status code 301', (done) => {
      server
      .get('/image.gif?size=96')
      .expect(301)
      .end((err, res) => {
        res.status.should.equal(301);
        done();
      });
    });
  });
Exemplo n.º 16
0
 before(function() {
   agent = request.agent(server);
 });
var assert = require('assert');
var supertest = require("supertest");
var testConfig = require('../testConfig');
var server = supertest.agent(testConfig.host + ":" + testConfig.port);
var apiURL = testConfig.apiArticleUrl;
var initData = require('../initData');

/*
* See /api/controllers/v1/admin/ArticleController.js  
* and /api/routes/articleRoutes.js for more details
*/
describe('Admin Article Controller Test', function() {
    var newUsers = [];
    var oldUsers = [];
    var newArticles = [];
    var oldArticles = [];

    beforeEach(function(done) {
        initData(function(returnData) {
            newUsers = returnData.newUsers;
            oldUsers = returnData.oldUsers;
            newArticles = returnData.newArticles;
            oldArticles = returnData.oldArticles;
            done();
        });
    });

    //query method in in /api/controllers/v1/ArticleController.js
    it('should not let normal user query all articles', function(done) {
        var apiLogin = testConfig.apiLogin;
        server
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
/* Api integration/acceptance tests (just a few sample tests, not full coverage)                  */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */

'use strict';

const supertest = require('supertest');   // SuperAgent driven library for testing HTTP servers
const expect    = require('chai').expect; // BDD/TDD assertion library
require('mocha');                         // simple, flexible, fun test framework

const app = require('../app.js');


const request = supertest.agent(app.listen());

const headers = { Host: 'api.localhost' }; // set host header (note Accept is defaulted to application/json)


describe(`API app (${app.env})`, function() {
    let jwt = null;

    describe('/auth', function() {
        it('returns 404 on unrecognised email', async function() {
            const response = await request.get('/auth').set(headers).query({ username: '******', password: '******' });
            expect(response.status).to.equal(404, response.text);
            expect(response.body).to.be.an('object');
        });

        it('returns 404 on bad password', async function() {
            const response = await request.get('/auth').set(headers).query({ username: '******', password: '******' });
            expect(response.status).to.equal(404, response.text);
  suite('with token', addDatabaseHooks(() => {
    const agent = request.agent(server);

    beforeEach((done) => {
      request(server)
        .post('/token')
        .set('Accept', 'application/json')
        .set('Content-Type', 'application/json')
        .send({
          email: '*****@*****.**',
          password: '******'
        })
        .end((err, res) => {
          if (err) {
            return done(err);
          }

          agent.saveCookies(res);
          done();
        });
    });

    test('GET /favorites', (done) => {
      /* eslint-disable max-len */
      agent
        .get('/favorites')
        .set('Accept', 'application/json')
        .expect('Content-Type', /json/)
        .expect(200, [{
          id: 1,
          bookId: 1,
          userId: 1,
          createdAt: '2016-06-26T14:26:16.000Z',
          updatedAt: '2016-06-26T14:26:16.000Z',
          title: 'JavaScript, The Good Parts',
          author: 'Douglas Crockford',
          genre: 'JavaScript',
          description: 'Most programming languages contain good and bad parts, but JavaScript has more than its share of the bad, having been developed and released in a hurry before it could be refined. This authoritative book scrapes away these bad features to reveal a subset of JavaScript that\'s more reliable, readable, and maintainable than the language as a whole—a subset you can use to create truly extensible and efficient code.',
          coverUrl: 'https://students-gschool-production.s3.amazonaws.com/uploads/asset/file/284/javascript_the_good_parts.jpg'
        }], done);

      /* eslint-enable max-len */
    });

    test('GET /favorites/check?bookId=1', (done) => {
      agent
        .get('/favorites/check?bookId=1')
        .set('Accept', 'application/json')
        .expect('Content-Type', /json/)
        .expect(200, 'true', done);
    });

    test('GET /favorites/check?bookId=2', (done) => {
      agent
        .get('/favorites/check?bookId=2')
        .set('Accept', 'application/json')
        .expect(200, 'false', done);
    });

    test('POST /favorites', (done) => {
      agent
        .post('/favorites')
        .set('Accept', 'application/json')
        .set('Content-Type', 'application/json')
        .send({ bookId: 2 })
        .expect('Content-Type', /json/)
        .expect((res) => {
          delete res.body.createdAt;
          delete res.body.updatedAt;
        })
        .expect(200, { id: 2, bookId: 2, userId: 1 }, done);
    });

    test('DELETE /favorites', (done) => {
      agent
        .delete('/favorites')
        .set('Accept', 'application/json')
        .set('Content-Type', 'application/json')
        .send({ bookId: 1 })
        .expect('Content-Type', /json/)
        .expect((res) => {
          delete res.body.createdAt;
          delete res.body.updatedAt;
        })
        .expect(200, { bookId: 1, userId: 1 }, done);
    });
  }));
Exemplo n.º 20
0
function server (app) {
  return agent(http.createServer(app.callback()))
}
'use strict';

var should = require('should'),
	request = require('supertest'),
	app = require('../../server'),
	agent = request.agent(app);

/**
 * Globals
 */
var credentials, user;

/**
 * Article routes tests
 */
describe('Calculator Route tests', function() {
	

	it('should be able to calulate', function(done) {
		
		// get a new calulation
		agent.get('/calculator/add/1/1')
			.expect(200)
			.end(function(calulateErr, calulateRes) {
				// Handle calulate error
				should.not.exist(calulateErr);
				(calulateRes.body.result).should.equal(2);
				done();
			});
	});
Exemplo n.º 22
0
var expect = require('chai').expect;
var server = require("../web/basic-server.js");
var fs = require('fs');
var archive = require("../helpers/archive-helpers");
var path = require('path');
var supertest = require('supertest');
archive.initialize({
  list: path.join(__dirname, "/testdata/sites.txt")
});

var request = supertest.agent(server);
debugger
describe("server", function() {
  describe("GET /", function () {
    it("should return the content of index.html", function (done) {
      // just assume that if it contains an <input> tag its index.html
      request
        .get('/')
        .expect(200, /<input/, done);
    });
  });

  describe("archived websites", function () {
    describe("GET", function () {
      it("should return the content of a website from the archive", function (done) {
        var fixtureName = "www.google.com";
        var fixturePath = archive.paths.archivedSites + "/" + fixtureName;

        // Create or clear the file.
        var fd = fs.openSync(fixturePath, "w");
        fs.writeSync(fd, "google");