Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Add tests for multi-callback chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisJEllis committed Oct 25, 2016
1 parent ab8ec24 commit 21f5293
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/raven.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,77 @@ describe('raven.Client', function () {
});
});

it('should pass original shouldSendCallback to newer shouldSendCallback', function (done) {
var cb1 = function (data) {
return false;
};

var cb2 = function (data, original) {
original.should.equal(cb1);
return original(data);
};

var cb3 = function (data, original) {
return original(data);
};

client = new raven.Client(dsn, {
shouldSendCallback: cb1,
});

client.setShouldSendCallback(cb2);
client.setShouldSendCallback(cb3);

// neither of these should fire, so report err to done if they do
client.on('logged', done);
client.on('error', done);

client.process({
message: 'test'
}, function (err, eventId) {
setTimeout(done, 10);
});
});

it('should pass original dataCallback to newer dataCallback', function (done) {
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
.post('/api/269/store/', '*')
.reply(200, function (uri, body) {
var msg = JSON.parse(zlib.inflateSync(new Buffer(body, 'base64')).toString());
msg.extra.foo.should.equal('bar');
return 'OK';
});

var cb1 = function (data) {
data.extra = { foo: 'bar' };
return data;
};

var cb2 = function (data, original) {
original.should.equal(cb1);
return original(data);
};

var cb3 = function (data, original) {
return original(data);
};

client = new raven.Client(dsn, {
dataCallback: cb1,
});

client.setDataCallback(cb2);
client.setDataCallback(cb3);

client.process({
message: 'test'
}, function (err, eventId) {
scope.done();
done();
});
});

it('should call the callback after sending', function (done) {
var firedCallback = false;
var sentResponse = false;
Expand Down

0 comments on commit 21f5293

Please sign in to comment.