Skip to content

Commit

Permalink
test: fix more tests re: #8481
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 23, 2020
1 parent 105c8ae commit c41ae4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions test/timestamps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ describe('timestamps', function() {
}, { timestamps: true });
const M = db.model('Test', schema);

M.create({ name: 'Test' }, function(error) {
M.create({ name: 'Test' }, function(error, doc) {
assert.ifError(error);
M.findOne({}, function(error, doc) {
M.findOne({ _id: doc._id }, function(error, doc) {
assert.ifError(error);
assert.ok(!doc.createdAt);
assert.ok(doc.updatedAt);
Expand All @@ -56,9 +56,9 @@ describe('timestamps', function() {
}, { timestamps: { createdAt: null, updatedAt: true } });
const M = db.model('Test', schema);

M.create({ name: 'Test' }, function(error) {
M.create({ name: 'Test' }, function(error, doc) {
assert.ifError(error);
M.findOne({}, function(error, doc) {
M.findOne({ _id: doc._id }, function(error, doc) {
assert.ifError(error);
assert.ok(!doc.createdAt);
assert.ok(doc.updatedAt);
Expand All @@ -78,9 +78,9 @@ describe('timestamps', function() {
});
const M = db.model('Test', parentSchema);

M.create({ child: { name: 'test' } }, function(error) {
M.create({ child: { name: 'test' } }, function(error, doc) {
assert.ifError(error);
M.findOne({}, function(error, doc) {
M.findOne({ _id: doc._id }, function(error, doc) {
assert.ifError(error);
assert.ok(!doc.child.createdAt);
assert.ok(doc.child.updatedAt);
Expand All @@ -97,9 +97,9 @@ describe('timestamps', function() {
}, { timestamps: { createdAt: 'ts.c', updatedAt: 'ts.a' } });
const M = db.model('Test', schema);

M.create({ name: 'Test' }, function(error) {
M.create({ name: 'Test' }, function(error, doc) {
assert.ifError(error);
M.findOne({}, function(error, doc) {
M.findOne({ _id: doc._id }, function(error, doc) {
assert.ifError(error);
assert.ok(doc.ts.c);
assert.ok(doc.ts.c.valueOf() >= startTime);
Expand Down Expand Up @@ -157,9 +157,9 @@ describe('timestamps', function() {
}, { timestamps: { createdAt: 'ts.createdAt', updatedAt: 'ts.updatedAt' } });
const M = db.model('Test', schema);

M.create({ name: 'Test' }, function(error) {
M.create({ name: 'Test' }, function(error, doc) {
assert.ifError(error);
M.findOne({}, function(error, doc) {
M.findOne({ _id: doc._id }, function(error, doc) {
assert.ifError(error);
assert.ok(!doc.ts.createdAt);
assert.ok(doc.ts.updatedAt);
Expand Down Expand Up @@ -218,7 +218,8 @@ describe('timestamps', function() {
const M = db.model('Test', schema);

const startTime = Date.now();
return M.updateOne({}, { name: 'foo' }, { upsert: true }).
return M.deleteMany({}).
then(() => M.updateOne({}, { name: 'foo' }, { upsert: true })).
then(() => assert.equal(called, 1)).
then(() => M.findOne()).
then(doc => assert.ok(doc.createdAt.valueOf() >= startTime));
Expand Down
4 changes: 2 additions & 2 deletions test/types.buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ describe('types.buffer', function() {

t.sub.push({ name: 'Friday Friday' });
t.save(function(err) {
assert.ok(err.message.indexOf('UserBuffer validation failed') === 0, err.message);
assert.ok(err.message.indexOf('Test validation failed') === 0, err.message);
assert.equal(err.errors['sub.0.buf'].kind, 'required');
t.sub[0].buf = Buffer.from('well well');
t.save(function(err) {
assert.ok(err.message.indexOf('UserBuffer validation failed') === 0, err.message);
assert.ok(err.message.indexOf('Test validation failed') === 0, err.message);
assert.equal(err.errors['sub.0.buf'].kind, 'user defined');
assert.equal(err.errors['sub.0.buf'].message, 'valid failed');

Expand Down

0 comments on commit c41ae4d

Please sign in to comment.