-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from rollbar/fix-server-transforms
Allow more flexibility of request objects
- Loading branch information
Showing
2 changed files
with
79 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,6 +419,66 @@ vows.describe('transforms') | |
assert.equal(item.data.context, '/api/:bork'); | ||
}, | ||
}, | ||
'with a request like from hapi': { | ||
topic: function(options) { | ||
var item = { | ||
request: { | ||
headers: { | ||
host: 'example.com', | ||
'x-auth-token': '12345' | ||
}, | ||
protocol: 'https', | ||
url: { | ||
protocol: null, | ||
slashes: null, | ||
auth: null, | ||
host: null, | ||
port: null, | ||
hostname: null, | ||
hash: null, | ||
search: '', | ||
query: {}, | ||
pathname: '/some/endpoint', | ||
path: '/some/endpoint', | ||
href: '/some/endpoint' | ||
}, | ||
ip: '192.192.192.1', | ||
method: 'POST', | ||
payload: { | ||
token: 'abc123', | ||
something: 'else' | ||
}, | ||
route: { path: '/api/:bork' }, | ||
user: { | ||
id: 42, | ||
email: '[email protected]' | ||
} | ||
}, | ||
stuff: 'hey', | ||
data: {other: 'thing'} | ||
}; | ||
t.addRequestData(item, options, this.callback); | ||
}, | ||
'should not error': function(err, item) { | ||
assert.ifError(err); | ||
}, | ||
'should have a request object inside data': function(err, item) { | ||
assert.ok(item.data.request); | ||
}, | ||
'should set a person based on request user': function(err, item) { | ||
assert.equal(item.data.person.id, 42); | ||
assert.equal(item.data.person.email, '[email protected]'); | ||
}, | ||
'should set some fields based on request data': function(err, item) { | ||
var r = item.data.request; | ||
assert.equal(r.url, 'https://example.com/some/endpoint'); | ||
assert.equal(r.user_ip, '192.192.192.1'); | ||
assert.ok(!r.GET); | ||
assert.ok(r.POST); | ||
|
||
assert.equal(item.data.context, '/api/:bork'); | ||
}, | ||
}, | ||
'with a request with an array body': { | ||
topic: function(options) { | ||
var item = { | ||
|