|
1 | 1 | 'use strict';
|
2 |
| -var test = require('./shared').assert; |
3 |
| -var setupDatabase = require('./shared').setupDatabase; |
| 2 | +var test = require('./shared').assert, |
| 3 | + setupDatabase = require('./shared').setupDatabase, |
| 4 | + expect = require('chai').expect; |
4 | 5 |
|
5 | 6 | // instanceof cannot be use reliably to detect the new models in js due to scoping and new
|
6 | 7 | // contexts killing class info find/distinct/count thus cannot be overloaded without breaking
|
@@ -1011,4 +1012,81 @@ describe('CRUD API', function() {
|
1011 | 1012 | });
|
1012 | 1013 | }
|
1013 | 1014 | });
|
| 1015 | + |
| 1016 | + it('should correctly throw error if update doc for updateOne lacks atomic operator', { |
| 1017 | + // Add a tag that our runner can trigger on |
| 1018 | + // in this case we are setting that node needs to be higher than 0.10.X to run |
| 1019 | + metadata: { |
| 1020 | + requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } |
| 1021 | + }, |
| 1022 | + |
| 1023 | + // The actual test we wish to run |
| 1024 | + test: function(done) { |
| 1025 | + var configuration = this.configuration; |
| 1026 | + var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); |
| 1027 | + client.connect(function(err, client) { |
| 1028 | + expect(err).to.not.exist; |
| 1029 | + var db = client.db(configuration.db); |
| 1030 | + var col = db.collection('t21_1'); |
| 1031 | + col.insertOne({ a: 1, b: 2, c: 3 }, function(err, r) { |
| 1032 | + expect(err).to.not.exist; |
| 1033 | + expect(r.insertedCount).to.equal(1); |
| 1034 | + |
| 1035 | + // empty update document |
| 1036 | + col.updateOne({ a: 1 }, {}, function(err, r) { |
| 1037 | + expect(err).to.exist; |
| 1038 | + expect(r).to.not.exist; |
| 1039 | + |
| 1040 | + // update document non empty but still lacks atomic operator |
| 1041 | + col.updateOne({ a: 1 }, { b: 5 }, function(err, r) { |
| 1042 | + expect(err).to.exist; |
| 1043 | + expect(r).to.not.exist; |
| 1044 | + |
| 1045 | + client.close(); |
| 1046 | + done(); |
| 1047 | + }); |
| 1048 | + }); |
| 1049 | + }); |
| 1050 | + }); |
| 1051 | + } |
| 1052 | + }); |
| 1053 | + |
| 1054 | + it('should correctly throw error if update doc for updateMany lacks atomic operator', { |
| 1055 | + // Add a tag that our runner can trigger on |
| 1056 | + // in this case we are setting that node needs to be higher than 0.10.X to run |
| 1057 | + metadata: { |
| 1058 | + requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } |
| 1059 | + }, |
| 1060 | + |
| 1061 | + // The actual test we wish to run |
| 1062 | + test: function(done) { |
| 1063 | + var configuration = this.configuration; |
| 1064 | + var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); |
| 1065 | + client.connect(function(err, client) { |
| 1066 | + expect(err).to.not.exist; |
| 1067 | + var db = client.db(configuration.db); |
| 1068 | + var col = db.collection('t22_1'); |
| 1069 | + col.insertMany([{ a: 1, b: 2 }, { a: 1, b: 3 }, { a: 1, b: 4 }], function(err, r) { |
| 1070 | + console.dir(err); |
| 1071 | + expect(err).to.not.exist; |
| 1072 | + expect(r.insertedCount).to.equal(3); |
| 1073 | + |
| 1074 | + // empty update document |
| 1075 | + col.updateMany({ a: 1 }, {}, function(err, r) { |
| 1076 | + expect(err).to.exist; |
| 1077 | + expect(r).to.not.exist; |
| 1078 | + |
| 1079 | + // update document non empty but still lacks atomic operator |
| 1080 | + col.updateMany({ a: 1 }, { b: 5 }, function(err, r) { |
| 1081 | + expect(err).to.exist; |
| 1082 | + expect(r).to.not.exist; |
| 1083 | + |
| 1084 | + client.close(); |
| 1085 | + done(); |
| 1086 | + }); |
| 1087 | + }); |
| 1088 | + }); |
| 1089 | + }); |
| 1090 | + } |
| 1091 | + }); |
1014 | 1092 | });
|
0 commit comments