-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db): fix mongoose unique indexes, add tests [#56]
- Loading branch information
Showing
8 changed files
with
137 additions
and
19 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
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,39 @@ | ||
import 'db/connect'; | ||
|
||
import { expect, dropData, spy, defaultObjectMetadata, addAdminUser } from 'utils/testing'; | ||
|
||
import { StorageEntity } from './model'; | ||
|
||
describe('StorageEntity model', () => { | ||
let data; | ||
|
||
before(async function() { | ||
this.timeout(5000); | ||
|
||
await dropData(); | ||
StorageEntity.ensureIndexes(); | ||
|
||
await addAdminUser(); | ||
const metadata = await defaultObjectMetadata(); | ||
data = { | ||
key: 'doc-key', | ||
document: {}, | ||
metadata, | ||
}; | ||
}); | ||
|
||
it('should fail to save doc | dup key', async () => { | ||
const errorHandler = spy(({ message }) => { | ||
expect(message).to.not.empty(); | ||
expect(message).to.includes('duplicate key'); | ||
}); | ||
|
||
await StorageEntity(data).save(); | ||
await StorageEntity(data) | ||
.save() | ||
.catch(errorHandler); | ||
|
||
expect(errorHandler).to.have.been.called(); | ||
await StorageEntity.find({}).then(docs => expect(docs).to.have.length(1)); | ||
}); | ||
}); |
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
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