//.insert method should respond with the created document
varto_insert={
value:1,
random:rand
};
returnself.insert(test_collection_name,to_insert)
.then(function(response){
assert.deepEqual(to_insert,response,".insert method should respond with the created document");
returnPromise.resolve();
});
}).then(function(){
//check if find resolves with an array
returnself.find(test_collection_name,{},{})
.then(function(documents){
assert(documentsinstanceofArray,"datastore."+self.name+".find should resolve with an array");
returnPromise.resolve();
});
}).then(function(){
//check if amount of created documents checks out
varcreates=[
self.insert(test_collection_name,{
value:2,
random:rand
}),
self.insert(test_collection_name,{
value:3,
random:rand
}),
self.insert(test_collection_name,{
value:4,
random:-rand
}),
]
varcreated_so_far=4;
returnPromise.all(creates)
.then(function(){
returnself.find(test_collection_name,{},{});
}).then(function(documents){
assert(documents.length==created_so_far,"Inserted "+created_so_far+" documents so far, but "+documents.length+" were returned on .find()");
returnPromise.resolve(created_so_far);
});
}).then(function(created_so_far){
//check if there is a proper amount of documents with random value set to rand
vardocuments_with_rand=created_so_far-1;
returnself.find(test_collection_name,{
random:rand
},{})
.then(function(documents){
assert(documents.length==documents_with_rand,"Inserted "+documents_with_rand+" documents with `random` set to `"+rand+"` so far, but "+documents.length+" were returned on .find({random: "+rand+"})");