-
Notifications
You must be signed in to change notification settings - Fork 407
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 lib/record.js
#185
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// istanbul ignore file | ||
'use strict'; | ||
|
||
var assign = require('lodash/assign'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,29 @@ describe('record deletion', function() { | |
}); | ||
}); | ||
|
||
it('can throw an error if a single record delete fails', function(done) { | ||
testExpressApp.set('handler override', function(req, res) { | ||
res.status(402).json({ | ||
error: {message: 'foo bar'}, | ||
}); | ||
}); | ||
|
||
return airtable | ||
.base('app123') | ||
.table('Table') | ||
.destroy('rec123') | ||
.then( | ||
function() { | ||
throw new Error('Promise unexpectly fufilled.'); | ||
}, | ||
function(err) { | ||
expect(err.statusCode).toBe(402); | ||
expect(err.message).toBe('foo bar'); | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Digging the pun |
||
} | ||
); | ||
}); | ||
|
||
it('can delete multiple records', function() { | ||
return airtable | ||
.base('app123') | ||
|
@@ -52,7 +75,7 @@ describe('record deletion', function() { | |
}); | ||
}); | ||
|
||
it('can throw an error if delete fails', function(done) { | ||
it('can throw an error if a multi-record delete fails', function(done) { | ||
rmeritz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
testExpressApp.set('handler override', function(req, res) { | ||
res.status(402).json({ | ||
error: {message: 'foo bar'}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,26 @@ describe('Record', function() { | |
}); | ||
}); | ||
|
||
describe('set', function() { | ||
var record; | ||
beforeEach(function() { | ||
record = new Record(table, null, { | ||
id: 'rec123', | ||
fields: {foo: 'bar'}, | ||
}); | ||
}); | ||
|
||
it('sets a new value', function() { | ||
record.set('bing', 'sing'); | ||
expect(record.get('bing')).toBe('sing'); | ||
}); | ||
|
||
it('re-sets an existing value', function() { | ||
record.set('foo', 'pig'); | ||
expect(record.get('foo')).toBe('pig'); | ||
}); | ||
}); | ||
|
||
describe('patchUpdate', function() { | ||
var record; | ||
|
||
|
@@ -170,6 +190,30 @@ describe('Record', function() { | |
}); | ||
}); | ||
|
||
it('saves the record and calls a callback', function(done) { | ||
record.set('foo', undefined); // eslint-disable-line no-undefined | ||
record.set('baz', 'qux'); | ||
record.save(function(err, updatedRecord) { | ||
expect(err).toBeNull(); | ||
|
||
expect(updatedRecord).toBe(record); | ||
expect(record.get('foo')).toBeUndefined(); | ||
expect(record.get('baz')).toEqual('qux'); | ||
|
||
expect(table._base.runAction).toHaveBeenCalledWith( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The invocation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated these tests to use the same mocking we use in all other places. |
||
'put', | ||
'/My%20Table/rec123', | ||
{}, | ||
{ | ||
fields: {baz: 'qux'}, | ||
}, | ||
expect.any(Function) | ||
); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('returns a promise when no callback is passed', function() { | ||
return record.patchUpdate({baz: 'qux'}).then(function(updatedRecord) { | ||
expect(updatedRecord).toBe(record); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "unexpectly" -> "unexpectedly" (here and below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.