Skip to content

Commit

Permalink
Complete tests for http_headers
Browse files Browse the repository at this point in the history
- Ignore lack of test for isBrowser because isn't very important and is
hard to test because `window` is called when the file is required.
- Add test for custom user-agent header
  • Loading branch information
rmeritz committed Jun 9, 2020
1 parent 9b84555 commit d3127d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/http_headers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// istanbul ignore file
var forEach = require('lodash/forEach');

var isBrowser = typeof window !== 'undefined';
Expand All @@ -25,6 +24,7 @@ HttpHeaders.prototype.toJSON = function() {
var result = {};
forEach(this._headersByLowercasedKey, function(headerDefinition, lowercasedKey) {
var headerKey;
/* istanbul ignore next */
if (isBrowser && lowercasedKey === 'user-agent') {
// Some browsers do not allow overriding the user agent.
// https://github.com/Airtable/airtable.js/issues/52
Expand Down
15 changes: 15 additions & 0 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ describe('Base', function() {
expect(value === 'bar' || value === 'baz').toBeTruthy();
});
});

it('allows headers with custom user agent', function() {
return fakeBase
.makeRequest({
headers: {
Authorization: 'foo',
'X-Airtable-User-Agent': 'bazz',
},
})
.then(function() {
const req = testExpressApp.get('most recent request');
expect(req.get('authorization')).toEqual('foo');
expect(req.get('user-agent')).toEqual('bazz');
});
});
});

describe('request body', function() {
Expand Down

0 comments on commit d3127d0

Please sign in to comment.