Skip to content

Latest commit

 

History

History
216 lines (183 loc) · 5.79 KB

test_results.md

File metadata and controls

216 lines (183 loc) · 5.79 KB

TOC

# collection.js ## id() should convert string id to ObjectID success.
id = db.testcollection.id(id);
id.should.be.instanceof(db.testcollection.ObjectID);
id = db.testcollection.id(id);
id.should.be.instanceof(db.testcollection.ObjectID);
id = '4ec4b2b9f44a927223000foo';
id = db.testcollection.id(id);
id.should.be.instanceof(db.testcollection.ObjectID);

should return source id when id length !== 24.

ids.forEach(function (id) {
  db.testcollection.id(id).should.equal(id);
});
## find(), findItems(), findEach() should find().toArray() return 100 comments.
  should.not.exist(err);
  rows.should.be.instanceof(Array).with.length(100);
  done();
});

should findItems(fn) all comments.

  should.not.exist(err);
  should.exist(comments);
  comments.should.be.instanceof(Array).with.length(100);
  done();
});

should findItems({} fn) all comments.

  should.not.exist(err);
  should.exist(comments);
  comments.should.be.instanceof(Array).with.length(100);
  done();
});

should findItems({limit: 10}) query wrong return top 0 comments.

  should.not.exist(err);
  comments.should.be.instanceof(Array).with.length(0);
  done();
});

should findItems({}, {limit: 10}) return top 10 comments.

  should.not.exist(err);
  comments.should.be.instanceof(Array).with.length(10);
  done();
});

should findEach(fn) call fn 100 times.

db.comment.findEach(function (err, comment) {
  should.not.exist(err);
  if (!comment) {
    count.should.equal(100);
    return done();
  }
  count++;
});

should findEach({}, {limit: 20}, fn) call fn 20 times.

db.comment.findEach({}, {limit: 20}, function (err, comment) {
  should.not.exist(err);
  if (!comment) {
    count.should.equal(20);
    return done();
  }
  count++;
});
### mock find() error should findItems() error.
  should.exist(err);
  err.should.be.instanceof(Error).with.have.property('message', 'mock find() error');
  should.not.exist(docs);
  done();
});

should findEach() error.

  should.exist(err);
  err.should.be.instanceof(Error).with.have.property('message', 'mock find() error');
  should.not.exist(docs);
  done();
});
## findById(), updateById(), removeById() ### findById() should find one object by ObjectID.
  should.not.exist(err);
  should.exist(article);
  article.should.have.property('_id').with.instanceof(db.ObjectID);
  article.should.have.property('created_at').with.instanceof(Date);
  article.should.have.property('title').with.include(now.toString());
  article.created_at.toString().should.equal(now.toString());
  done();
});

should find one object by String id.

  should.not.exist(err);
  should.exist(article);
  article.should.have.property('_id').with.instanceof(db.ObjectID);
  article.should.have.property('created_at').with.instanceof(Date);
  article.should.have.property('title').with.include(now.toString());
  article.created_at.toString().should.equal(now.toString());
  done();
});

should not find when id not exists.

  should.not.exist(err);
  should.not.exist(article);
  done();
});
### updateById() should update obj by id.
var doc = {
  $set: {
    title: 'new title ' + updatedTime,
    updated_at: updatedTime
  }
};
db.article.updateById(articleId.toString(), doc, function (err, article) {
  should.not.exist(err);
  should.not.exist(article);
  db.article.findById(articleId, function (err, article) {
    should.not.exist(err);
    should.exist(article);
    article.should.have.property('title', 'new title ' + updatedTime);
    article.should.have.property('updated_at').with.instanceof(Date);
    article.updated_at.toString().should.equal(updatedTime.toString());
    done();
  });
});
### removeById() should remove obj by id.
db.article.findById(id, function (err, article) {
  should.not.exist(err);
  should.exist(article);
  db.article.removeById(id, function (err, article) {
    should.not.exist(err);
    should.not.exist(article);
    db.article.findById(id, function (err, article) {
      should.not.exist(err);
      should.not.exist(article);
      done();
    });
  });
});