Commit df58203b authored by analog-nico's avatar analog-nico
Browse files

Additional test for issue #39

parent 3158939c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
    "request": "^2.34"
  },
  "devDependencies": {
    "body-parser": "^1.12.0",
    "chai": "^1.10.0",
    "chai-as-promised": "^4.1.1",
    "event-stream": "^3.1.7",
+28 −13
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ var Bluebird = require('bluebird');
var childProcess = require('child_process');
var path = require('path');
var es = require('event-stream');
var bodyParser = require('body-parser');


describe('Request-Promise', function () {
@@ -17,6 +18,7 @@ describe('Request-Promise', function () {
    before(function (done) {
        // This creates a local server to test for various status codes. A request to /404 returns a 404, etc
        server = http.createServer(function (request, response) {
            (bodyParser.json())(request, response, function () {
                var path = url.parse(request.url).pathname;
                var status = parseInt(path.split('/')[1]);
                if(isNaN(status)) { status = 555; }
@@ -26,10 +28,12 @@ describe('Request-Promise', function () {
                    response.end();
                } else {
                    response.writeHead(status, { 'Content-Type': 'text/plain' });
                lastResponseBody = request.method + ' ' + request.url;
                    var body = (request.method === 'POST' && JSON.stringify(request.body) !== '{}' ? ' - ' + JSON.stringify(request.body) : '');
                    lastResponseBody = request.method + ' ' + request.url + body;
                    response.end(lastResponseBody);
                }
            });
        });
        server.listen(4000, function () {
            done();
        });
@@ -895,6 +899,17 @@ describe('Request-Promise', function () {

        });

        it('for passing the data as the second parameter', function (done) {

            rp('http://localhost:4000/200', { method: 'POST', json: { foo: 'bar' } })
                .then(function (body) {
                    expect(body).to.eql('POST /200 - {"foo":"bar"}');
                    done();
                })
                .catch(done);

        });

    });

    describe('should still allow to require Request independently', function (done) {