Skip to content

Commit

Permalink
Add test for custom user agent header if browser
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeritz committed Jun 12, 2020
1 parent 01efb7e commit d418c03
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/find.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('record retrival', function() {
});

afterAll(function() {
delete global.x;
return teardownAsync();
});

Expand All @@ -25,6 +26,32 @@ describe('record retrival', function() {
testExpressApp.set('handler override', function(req, res) {
expect(req.method).toBe('GET');
expect(req.url).toBe('/v0/app123/Table/record1?');
expect(req.get('user-agent')).toMatch(/Airtable.js/);
res.json({
id: req.params.recordId,
fields: {Name: 'Rebecca'},
createdTime: '2020-04-20T16:20:00.000Z',
});
});

return airtable
.base('app123')
.table('Table')
.find(recordId)
.then(function(foundRecord) {
expect(foundRecord.id).toBe(recordId);
expect(foundRecord.get('Name')).toBe('Rebecca');
});
});

it('set the correct headers in a browser', function() {
global.window = {};
var recordId = 'record1';

testExpressApp.set('handler override', function(req, res) {
expect(req.method).toBe('GET');
expect(req.url).toBe('/v0/app123/Table/record1?');
expect(req.get('x-airtable-user-agent')).toMatch(/Airtable.js/);
res.json({
id: req.params.recordId,
fields: {Name: 'Rebecca'},
Expand Down

0 comments on commit d418c03

Please sign in to comment.