-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for batch record creation
For example: const table = airtable.base('app123').table('My Table'); const records = await table.create([ {foo: 'boo'}, {bar: 'yar'}, ]); console.log(records.length); // => 2 console.log(records[0].get('foo')); // => 'boo' console.log(records[1].get('bar')); // => 'yar'
- Loading branch information
Evan Hahn
committed
Apr 25, 2019
1 parent
7eceb7a
commit 509c643
Showing
3 changed files
with
147 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
var testHelpers = require('./test_helpers'); | ||
|
||
describe('record creation', function () { | ||
var airtable; | ||
var teardownAsync; | ||
|
||
beforeAll(function () { | ||
return testHelpers.getMockEnvironmentAsync().then(function (env) { | ||
airtable = env.airtable; | ||
teardownAsync = env.teardownAsync; | ||
}); | ||
}); | ||
|
||
afterAll(function () { | ||
return teardownAsync(); | ||
}); | ||
|
||
it('can create one record', function () { | ||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.create({ | ||
foo: 'boo', | ||
bar: 'yar', | ||
}) | ||
.then(function (createdRecord) { | ||
expect(createdRecord.id).toBe('rec0'); | ||
expect(createdRecord.get('foo')).toBe('boo'); | ||
expect(createdRecord.get('bar')).toBe('yar'); | ||
}); | ||
}); | ||
|
||
it('can add the "typecast" parameter when creating one record', function () { | ||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.create({ | ||
foo: 'boo', | ||
bar: 'yar', | ||
}, {typecast: true}) | ||
.then(function (createdRecord) { | ||
expect(createdRecord.id).toBe('rec0'); | ||
expect(createdRecord.get('typecasted')).toBe(true); | ||
}); | ||
}); | ||
|
||
it('can create one record with an array', function () { | ||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.create([{foo: 'boo'}]) | ||
.then(function (createdRecords) { | ||
expect(createdRecords).toHaveLength(1); | ||
expect(createdRecords[0].id).toBe('rec0'); | ||
expect(createdRecords[0].get('foo')).toBe('boo'); | ||
}); | ||
}); | ||
|
||
it('can create two records', function () { | ||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.create([ | ||
{foo: 'boo'}, | ||
{bar: 'yar'}, | ||
]) | ||
.then(function (createdRecords) { | ||
expect(createdRecords).toHaveLength(2); | ||
expect(createdRecords[0].id).toBe('rec0'); | ||
expect(createdRecords[0].get('foo')).toBe('boo'); | ||
expect(createdRecords[1].id).toBe('rec1'); | ||
expect(createdRecords[1].get('bar')).toBe('yar'); | ||
}); | ||
}); | ||
|
||
it('can create two records with the "typecast" parameter', function () { | ||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.create([ | ||
{foo: 'boo'}, | ||
{bar: 'yar'}, | ||
], {typecast: true}) | ||
.then(function (createdRecords) { | ||
expect(createdRecords).toHaveLength(2); | ||
expect(createdRecords[0].id).toBe('rec0'); | ||
expect(createdRecords[0].get('typecasted')).toBe(true); | ||
expect(createdRecords[1].id).toBe('rec1'); | ||
expect(createdRecords[1].get('typecasted')).toBe(true); | ||
}); | ||
}); | ||
}); |
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