This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability for requests to already be buffered
Decided to use less documentation in favor of confusing documentation Wrote up README example but not satisfied with it Added assertion as promised Added callback logic with buffered body Added raw body parser Added body parsing Added new tests for buffered body Moving back to req.body Deciding to "expose" forwardRequestMessage Created forwardBufferedRequest to use, yey Moving to options for buffer Exposing Message to avoid future complications Fixed up timing complications Fixed missing property Starting to allow existing body
- Loading branch information
Showing
6 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var expect = require('chai').expect; | ||
var express = require('express'); | ||
var rawBody = require('raw-body'); | ||
var eightTrack = require('../'); | ||
var httpUtils = require('./utils/http'); | ||
var serverUtils = require('./utils/server'); | ||
|
||
// TODO: This should be a separate repo | ||
function connectRawBody(req, res, next) { | ||
rawBody(req, function handleBody (err, buff) { | ||
if (err) { | ||
next(err); | ||
} | ||
req.body = buff; | ||
next(); | ||
}); | ||
} | ||
|
||
describe('A server that asserts content before talking to eight-track', function () { | ||
serverUtils.run(1337, [ | ||
express.urlencoded(), | ||
function (req, res) { | ||
res.send(req.body); | ||
} | ||
]); | ||
serverUtils.run(1338, [ | ||
connectRawBody, | ||
function assertInfo (req, res, next) { | ||
expect(req.body.toString()).to.equal('hello=world'); | ||
next(); | ||
}, | ||
eightTrack({ | ||
fixtureDir: __dirname + '/actual-files/buffered-body', | ||
url: 'http://localhost:1337' | ||
}) | ||
]); | ||
serverUtils._cleanupEightTrack(__dirname + '/actual-files/buffered-body'); | ||
|
||
describe('when requested', function () { | ||
httpUtils.save({ | ||
form: { | ||
hello: 'world' | ||
}, | ||
url: 'http://localhost:1338/' | ||
}); | ||
|
||
it('replies with a our header', function () { | ||
expect(this.err).to.equal(null); | ||
expect(this.res.statusCode).to.equal(200); | ||
expect(JSON.parse(this.body)).to.have.property('hello', 'world'); | ||
}); | ||
|
||
describe('when requested again', function () { | ||
httpUtils.save({ | ||
form: { | ||
hello: 'world' | ||
}, | ||
url: 'http://localhost:1338/' | ||
}); | ||
|
||
it('has the same header', function () { | ||
expect(JSON.parse(this.body)).to.have.property('hello', 'world'); | ||
}); | ||
|
||
it('does not double request', function () { | ||
expect(this.requests[1337]).to.have.property('length', 1); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters