-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from derbyjs/addPromised-id
Resolve `addPromised` with new doc `id`
- Loading branch information
Showing
2 changed files
with
45 additions
and
12 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,23 @@ | ||
const {expect} = require('chai'); | ||
const {RootModel} = require('../../lib/Model'); | ||
|
||
describe('mutators', () => { | ||
describe('add', () => { | ||
const guidRegExp = new RegExp(/[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}/); | ||
it('returns created id in callback', () => { | ||
const model = new RootModel(); | ||
model.add('_test_doc', {name: 'foo'}, (error, id) => { | ||
expect(error).to.not.exist; | ||
expect(id).not.to.be.undefined; | ||
expect(id).to.match(guidRegExp, 'Expected a GUID-like Id'); | ||
}); | ||
}); | ||
|
||
it('resolves promised add with id', async () => { | ||
const model = new RootModel(); | ||
const id = await model.addPromised('_test_doc', {name: 'bar'}); | ||
expect(id).not.to.be.undefined; | ||
expect(id).to.match(guidRegExp, 'Expected a GUID-like Id'); | ||
}); | ||
}); | ||
}); |