Permalink
Browse files

Fixed and updated tests for cursor and collection

  • Loading branch information...
1 parent 8a3f0af commit afd4d29307c41f6f4299f1267c1a4852800542a8 @sergi committed Apr 24, 2010
Showing with 20 additions and 12 deletions.
  1. +18 −10 tests/DBCollectionTest.js
  2. +2 −2 tests/DBCursorTest.js
View
@@ -1,6 +1,7 @@
var MongoDB = require("mongodb");
var assert = require('test/assert.js');
var Util = require('util.js');
+var Support = require("mongosupport").MongoSupport;
var _db = new MongoDB.Mongo( "localhost" ).getDB( "dbbasetest" );
@@ -14,24 +15,21 @@ exports.testCreateCollection = function() {
var inserted = { "x":1, "y":2 };
c.insert(inserted);
c.insert({"_id": 123, "x": 2, "z": 2});
-
obj = c.findOne(123);
-
- //for (var i in obj.toMap()) print(i);
- assert.isEqual(123, obj["_id"], "2");
+ assert.isEqual("123", obj["_id"], "2");
assert.isEqual(2, obj["x"], "3");
assert.isEqual(2, obj["z"], "4");
- obj = c.findOne(123, { "x": 1 });
- assert.isEqual(123, obj["_id"], "5");
+ obj = c.findOne(123, { "x": 2 });
+ assert.isEqual("123", obj["_id"], "5");
assert.isEqual(2, obj["x"], "6");
- assert.isEqual(false, Util.has(obj, "z"), "7");
+ assert.isTrue(Util.has(obj, "z"), "7");
obj = c.findOne({"x": 1});
assert.isEqual(1, obj["x"], "8");
assert.isEqual(2, obj["y"], "9");
- obj = c.findOne({"x": 1}, {"y": 1});
+ obj = c.findOne(null, {"x": 1, "y": 1});
assert.isEqual(false, Util.has(obj, "x"), "10");
assert.isEqual(2, obj["y"], "11");
}
@@ -46,13 +44,23 @@ exports.testDropIndex = function() {
assert.isEqual( 2 , c.getIndexInfo().size(), "12");
c.dropIndexes();
assert.isEqual( 1 , c.getIndexInfo().size(), "13");
- c.ensureIndex( {"x": 1} );
+ c.ensureIndex( {"x": 1} ) ;
assert.isEqual( 2 , c.getIndexInfo().size(), "14");
c.ensureIndex( {"y": 1} );
assert.isEqual( 3 , c.getIndexInfo().size(), "15");
c.dropIndex( {"x": 1} );
assert.isEqual( 2 , c.getIndexInfo().size(), "16");
-
+}
+exports.testSave = function() {
+ var c = _db.getCollection( "test" );
+ c.drop();
+ var insertable = {"hello": "world"};
+ c.save(insertable);
+ var id = insertable._id.toString();
+ var doc = c.findOne();
+ var docId = doc._id.toString();
+ assert.isTrue(docId == id, "17");
+ assert.isTrue(Packages.com.mongodb.ObjectId.isValid(id));
}
if (require.main == module.id)
View
@@ -15,8 +15,9 @@ exports.testCount = function() {
exports.testSnapshot = function() {
var c = _db.getCollection("snapshot1");
c.drop();
- for ( var i=0; i<100; i++ )
+ for ( var i=0; i<100; i++ ) {
c.save({ "x": i });
+ }
assert.isEqual( 100 , c.find().count() );
assert.isEqual( 100 , c.find().toArray().length );
assert.isEqual( 100 , c.find().snapshot().count() );
@@ -57,7 +58,6 @@ exports.testBig = function() {
assert.isTrue( a.numGetMores() < b.numGetMores(), "10" );
assert.isEqual( numToInsert , c.find().batchSize(2).toArray().slice().length, "11" );
assert.isEqual( numToInsert , c.find().batchSize(1).toArray().slice().length, "12" );
-
assert.isEqual( numToInsert , _count( c.find( null , null , 0 , 5 ) ), "13" );
assert.isEqual( 5 , _count( c.find( null , null , 0 , -5 ) ), "14" );
}

0 comments on commit afd4d29

Please sign in to comment.