|
1 | 1 | 'use strict';
|
2 |
| -const test = require('./shared').assert, |
3 |
| - setupDatabase = require('./shared').setupDatabase, |
4 |
| - expect = require('chai').expect; |
5 |
| - |
6 |
| -const MongoError = require('../../src/error').MongoError; |
7 |
| -const ignoreNsNotFound = require('./shared').ignoreNsNotFound; |
| 2 | +const { withClient, setupDatabase, ignoreNsNotFound } = require('./shared'); |
| 3 | +const test = require('./shared').assert; |
| 4 | +const { expect } = require('chai'); |
| 5 | +const { MongoError } = require('../../src/error'); |
| 6 | +const { Long } = require('../../src'); |
8 | 7 |
|
9 | 8 | describe('Bulk', function () {
|
10 | 9 | before(function () {
|
@@ -158,6 +157,108 @@ describe('Bulk', function () {
|
158 | 157 | }
|
159 | 158 | });
|
160 | 159 |
|
| 160 | + it('should inherit promote long false from db during unordered bulk operation', function () { |
| 161 | + const client = this.configuration.newClient(this.configuration.writeConcernMax(), { |
| 162 | + promoteLongs: true |
| 163 | + }); |
| 164 | + |
| 165 | + return withClient.call(this, client, (client, done) => { |
| 166 | + const db = client.db('shouldInheritPromoteLongFalseFromDb1', { promoteLongs: false }); |
| 167 | + const coll = db.collection('test'); |
| 168 | + |
| 169 | + const batch = coll.initializeUnorderedBulkOp(); |
| 170 | + batch.insert({ a: Long.fromNumber(10) }); |
| 171 | + batch.execute((err, result) => { |
| 172 | + expect(err).to.not.exist; |
| 173 | + expect(result).to.exist; |
| 174 | + |
| 175 | + coll.findOne((err, item) => { |
| 176 | + expect(err).to.not.exist; |
| 177 | + expect(item.a).to.not.be.a('number'); |
| 178 | + expect(item.a).to.have.property('_bsontype'); |
| 179 | + expect(item.a._bsontype).to.be.equal('Long'); |
| 180 | + |
| 181 | + done(); |
| 182 | + }); |
| 183 | + }); |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + it( |
| 188 | + 'should inherit promote long false from collection during unordered bulk operation', |
| 189 | + withClient(function (client, done) { |
| 190 | + const db = client.db('shouldInheritPromoteLongFalseFromColl1', { promoteLongs: true }); |
| 191 | + const coll = db.collection('test', { promoteLongs: false }); |
| 192 | + |
| 193 | + const batch = coll.initializeUnorderedBulkOp(); |
| 194 | + batch.insert({ a: Long.fromNumber(10) }); |
| 195 | + batch.execute((err, result) => { |
| 196 | + expect(err).to.not.exist; |
| 197 | + expect(result).to.exist; |
| 198 | + |
| 199 | + coll.findOne((err, item) => { |
| 200 | + expect(err).to.not.exist; |
| 201 | + expect(item.a).to.not.be.a('number'); |
| 202 | + expect(item.a).to.have.property('_bsontype'); |
| 203 | + expect(item.a._bsontype).to.be.equal('Long'); |
| 204 | + |
| 205 | + done(); |
| 206 | + }); |
| 207 | + }); |
| 208 | + }) |
| 209 | + ); |
| 210 | + |
| 211 | + it('should inherit promote long false from db during ordered bulk operation', function () { |
| 212 | + const client = this.configuration.newClient(this.configuration.writeConcernMax(), { |
| 213 | + promoteLongs: true |
| 214 | + }); |
| 215 | + |
| 216 | + return withClient.call(this, client, (client, done) => { |
| 217 | + const db = client.db('shouldInheritPromoteLongFalseFromDb2', { promoteLongs: false }); |
| 218 | + const coll = db.collection('test'); |
| 219 | + |
| 220 | + const batch = coll.initializeOrderedBulkOp(); |
| 221 | + batch.insert({ a: Long.fromNumber(10) }); |
| 222 | + batch.execute((err, result) => { |
| 223 | + expect(err).to.not.exist; |
| 224 | + expect(result).to.exist; |
| 225 | + |
| 226 | + coll.findOne((err, item) => { |
| 227 | + expect(err).to.not.exist; |
| 228 | + expect(item.a).to.not.be.a('number'); |
| 229 | + expect(item.a).to.have.property('_bsontype'); |
| 230 | + expect(item.a._bsontype).to.be.equal('Long'); |
| 231 | + |
| 232 | + done(); |
| 233 | + }); |
| 234 | + }); |
| 235 | + }); |
| 236 | + }); |
| 237 | + |
| 238 | + it( |
| 239 | + 'should inherit promote long false from collection during ordered bulk operation', |
| 240 | + withClient(function (client, done) { |
| 241 | + const db = client.db('shouldInheritPromoteLongFalseFromColl2', { promoteLongs: true }); |
| 242 | + const coll = db.collection('test', { promoteLongs: false }); |
| 243 | + |
| 244 | + const batch = coll.initializeOrderedBulkOp(); |
| 245 | + batch.insert({ a: Long.fromNumber(10) }); |
| 246 | + batch.execute((err, result) => { |
| 247 | + expect(err).to.not.exist; |
| 248 | + expect(result).to.exist; |
| 249 | + |
| 250 | + coll.findOne((err, item) => { |
| 251 | + expect(err).to.not.exist; |
| 252 | + expect(item.a).to.not.be.a('number'); |
| 253 | + expect(item.a).to.have.property('_bsontype'); |
| 254 | + expect(item.a._bsontype).to.be.equal('Long'); |
| 255 | + |
| 256 | + done(); |
| 257 | + }); |
| 258 | + }); |
| 259 | + }) |
| 260 | + ); |
| 261 | + |
161 | 262 | it('should correctly handle ordered multiple batch api write command errors', {
|
162 | 263 | metadata: {
|
163 | 264 | requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
|
|
0 commit comments