Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete tests for http_headers #182

Merged
merged 1 commit into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the reason istanbul ignore if doesn't work here is that there are two branches involved. There's the body of the if statement (which is ignored by istanbul ignore if) and the second half of the condition expression, lowercasedKey === 'user-agent' (which is not ignored by istanbul ignore if).

We could switch the order of the expressions in the conditional. That would technically be more precise, but I wouldn't push for it. The current order is presumably more intuitive for the folks maintaining this code, and it's more important to support them than it is to improve a technicality in the coverage report.

// 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