|
1 | 1 | 'use strict';
|
| 2 | +var test = require('./shared').assert; |
| 3 | +var setupDatabase = require('./shared').setupDatabase; |
| 4 | +var assign = require('../../lib/utils').assign; |
2 | 5 |
|
3 |
| -/** |
4 |
| - * @ignore |
5 |
| - */ |
6 |
| -exports['Should correctly insert document ignoring undefined field'] = { |
7 |
| - metadata: { requires: { topology: ['single'] } }, |
8 |
| - // The actual test we wish to run |
9 |
| - test: function(configuration, test) { |
10 |
| - var client = configuration.newDbInstance(configuration.writeConcernMax(), { |
11 |
| - poolSize: 1, |
12 |
| - ignoreUndefined: true |
13 |
| - }); |
14 |
| - client.connect(function(err, client) { |
15 |
| - var db = client.db(configuration.database); |
16 |
| - var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue'); |
17 |
| - // console.log("!!!!!!!!!!!!!!!!! IGNORE") |
18 |
| - |
19 |
| - // Ignore the undefined field |
20 |
| - collection.insert({ a: 1, b: undefined }, configuration.writeConcernMax(), function( |
21 |
| - err, |
22 |
| - result |
23 |
| - ) { |
24 |
| - // Locate the doument |
25 |
| - collection.findOne(function(err, item) { |
26 |
| - test.equal(1, item.a); |
27 |
| - test.ok(item.b === undefined); |
28 |
| - client.close(); |
29 |
| - test.done(); |
30 |
| - }); |
31 |
| - }); |
32 |
| - }); |
33 |
| - } |
34 |
| -}; |
35 |
| - |
36 |
| -/** |
37 |
| - * @ignore |
38 |
| - */ |
39 |
| -exports[ |
40 |
| - 'Should correctly connect using MongoClient and perform insert document ignoring undefined field' |
41 |
| -] = { |
42 |
| - metadata: { requires: { topology: ['single'] } }, |
43 |
| - // The actual test we wish to run |
44 |
| - test: function(configuration, test) { |
45 |
| - var MongoClient = configuration.require.MongoClient; |
46 |
| - MongoClient.connect( |
47 |
| - configuration.url(), |
48 |
| - { |
49 |
| - db: { bufferMaxEntries: 0, ignoreUndefined: true }, |
50 |
| - server: { sslValidate: false } |
51 |
| - }, |
52 |
| - function(err, client) { |
53 |
| - var db = client.db(configuration.database); |
54 |
| - var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue1'); |
55 |
| - collection.insert({ a: 1, b: undefined }, function(err, result) { |
| 6 | +describe('Ignore Undefined', function() { |
| 7 | + before(function() { |
| 8 | + return setupDatabase(this.configuration); |
| 9 | + }); |
| 10 | + |
| 11 | + /** |
| 12 | + * @ignore |
| 13 | + */ |
| 14 | + it('Should correctly insert document ignoring undefined field', { |
| 15 | + metadata: { requires: { topology: ['single'] } }, |
| 16 | + |
| 17 | + test: function(done) { |
| 18 | + var configuration = this.configuration; |
| 19 | + var client = configuration.newClient( |
| 20 | + assign({}, configuration.writeConcernMax(), { |
| 21 | + poolSize: 1, |
| 22 | + ignoreUndefined: true |
| 23 | + }) |
| 24 | + ); |
| 25 | + |
| 26 | + client.connect(function(err, client) { |
| 27 | + var db = client.db(configuration.db); |
| 28 | + var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue'); |
| 29 | + |
| 30 | + // Ignore the undefined field |
| 31 | + collection.insert({ a: 1, b: undefined }, configuration.writeConcernMax(), function(err) { |
| 32 | + test.equal(null, err); |
| 33 | + |
| 34 | + // Locate the doument |
56 | 35 | collection.findOne(function(err, item) {
|
57 | 36 | test.equal(1, item.a);
|
58 | 37 | test.ok(item.b === undefined);
|
| 38 | + client.close(); |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + /** |
| 47 | + * @ignore |
| 48 | + */ |
| 49 | + it( |
| 50 | + 'Should correctly connect using MongoClient and perform insert document ignoring undefined field', |
| 51 | + { |
| 52 | + metadata: { requires: { topology: ['single'] } }, |
| 53 | + |
| 54 | + test: function(done) { |
| 55 | + var configuration = this.configuration; |
| 56 | + var MongoClient = configuration.require.MongoClient; |
59 | 57 |
|
60 |
| - collection.insertOne({ a: 2, b: undefined }, function(err, result) { |
61 |
| - collection.findOne({ a: 2 }, function(err, item) { |
62 |
| - test.equal(2, item.a); |
| 58 | + MongoClient.connect( |
| 59 | + configuration.url(), |
| 60 | + { |
| 61 | + db: { bufferMaxEntries: 0, ignoreUndefined: true }, |
| 62 | + server: { sslValidate: false } |
| 63 | + }, |
| 64 | + function(err, client) { |
| 65 | + var db = client.db(configuration.db); |
| 66 | + var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue1'); |
| 67 | + collection.insert({ a: 1, b: undefined }, function(err) { |
| 68 | + test.equal(null, err); |
| 69 | + |
| 70 | + collection.findOne(function(err, item) { |
| 71 | + test.equal(1, item.a); |
63 | 72 | test.ok(item.b === undefined);
|
64 | 73 |
|
65 |
| - collection.insertMany([{ a: 3, b: undefined }], function(err, result) { |
66 |
| - collection.findOne({ a: 3 }, function(err, item) { |
67 |
| - test.equal(3, item.a); |
| 74 | + collection.insertOne({ a: 2, b: undefined }, function(err) { |
| 75 | + test.equal(null, err); |
| 76 | + |
| 77 | + collection.findOne({ a: 2 }, function(err, item) { |
| 78 | + test.equal(2, item.a); |
68 | 79 | test.ok(item.b === undefined);
|
69 |
| - client.close(); |
70 |
| - test.done(); |
| 80 | + |
| 81 | + collection.insertMany([{ a: 3, b: undefined }], function(err) { |
| 82 | + test.equal(null, err); |
| 83 | + |
| 84 | + collection.findOne({ a: 3 }, function(err, item) { |
| 85 | + test.equal(3, item.a); |
| 86 | + test.ok(item.b === undefined); |
| 87 | + client.close(); |
| 88 | + done(); |
| 89 | + }); |
| 90 | + }); |
71 | 91 | });
|
72 | 92 | });
|
73 | 93 | });
|
74 | 94 | });
|
75 |
| - }); |
76 |
| - }); |
| 95 | + } |
| 96 | + ); |
77 | 97 | }
|
78 |
| - ); |
79 |
| - } |
80 |
| -}; |
81 |
| - |
82 |
| -/** |
83 |
| - * @ignore |
84 |
| - */ |
85 |
| -exports['Should correctly update document ignoring undefined field'] = { |
86 |
| - metadata: { requires: { topology: ['single'] } }, |
87 |
| - // The actual test we wish to run |
88 |
| - test: function(configuration, test) { |
89 |
| - var ObjectId = configuration.require.ObjectID; |
90 |
| - |
91 |
| - var client = configuration.newDbInstance(configuration.writeConcernMax(), { |
92 |
| - poolSize: 1, |
93 |
| - ignoreUndefined: true |
94 |
| - }); |
95 |
| - client.connect(function(err, client) { |
96 |
| - var db = client.db(configuration.database); |
97 |
| - var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue2'); |
98 |
| - var id = new ObjectId(); |
99 |
| - |
100 |
| - collection.updateOne( |
101 |
| - { _id: id, a: 1, b: undefined }, |
102 |
| - { $set: { a: 1, b: undefined } }, |
103 |
| - { upsert: true }, |
104 |
| - function(err, result) { |
105 |
| - collection.findOne({ _id: id }, function(err, item) { |
106 |
| - test.equal(1, item.a); |
107 |
| - test.ok(item.b === undefined); |
108 |
| - var id = new ObjectId(); |
109 |
| - |
110 |
| - collection.updateMany( |
111 |
| - { _id: id, a: 1, b: undefined }, |
112 |
| - { $set: { a: 1, b: undefined } }, |
113 |
| - { upsert: true }, |
114 |
| - function(err, result) { |
115 |
| - collection.findOne({ _id: id }, function(err, item) { |
116 |
| - test.equal(1, item.a); |
117 |
| - test.ok(item.b === undefined); |
118 |
| - var id = new ObjectId(); |
119 |
| - |
120 |
| - collection.update( |
121 |
| - { _id: id, a: 1, b: undefined }, |
122 |
| - { $set: { a: 1, b: undefined } }, |
123 |
| - { upsert: true }, |
124 |
| - function(err, result) { |
125 |
| - collection.findOne({ _id: id }, function(err, item) { |
126 |
| - test.equal(1, item.a); |
127 |
| - test.ok(item.b === undefined); |
128 |
| - client.close(); |
129 |
| - test.done(); |
130 |
| - }); |
131 |
| - } |
132 |
| - ); |
133 |
| - }); |
134 |
| - } |
135 |
| - ); |
136 |
| - }); |
137 |
| - } |
| 98 | + } |
| 99 | + ); |
| 100 | + |
| 101 | + /** |
| 102 | + * @ignore |
| 103 | + */ |
| 104 | + it('Should correctly update document ignoring undefined field', { |
| 105 | + metadata: { requires: { topology: ['single'] } }, |
| 106 | + |
| 107 | + test: function(done) { |
| 108 | + var configuration = this.configuration; |
| 109 | + var ObjectId = configuration.require.ObjectID; |
| 110 | + |
| 111 | + var client = configuration.newClient( |
| 112 | + assign({}, configuration.writeConcernMax(), { |
| 113 | + poolSize: 1, |
| 114 | + ignoreUndefined: true |
| 115 | + }) |
138 | 116 | );
|
139 |
| - }); |
140 |
| - } |
141 |
| -}; |
| 117 | + |
| 118 | + client.connect(function(err, client) { |
| 119 | + var db = client.db(configuration.db); |
| 120 | + var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue2'); |
| 121 | + var id = new ObjectId(); |
| 122 | + |
| 123 | + collection.updateOne( |
| 124 | + { _id: id, a: 1, b: undefined }, |
| 125 | + { $set: { a: 1, b: undefined } }, |
| 126 | + { upsert: true }, |
| 127 | + function(err) { |
| 128 | + test.equal(null, err); |
| 129 | + collection.findOne({ _id: id }, function(err, item) { |
| 130 | + test.equal(1, item.a); |
| 131 | + test.ok(item.b === undefined); |
| 132 | + var id = new ObjectId(); |
| 133 | + |
| 134 | + collection.updateMany( |
| 135 | + { _id: id, a: 1, b: undefined }, |
| 136 | + { $set: { a: 1, b: undefined } }, |
| 137 | + { upsert: true }, |
| 138 | + function(err) { |
| 139 | + test.equal(null, err); |
| 140 | + collection.findOne({ _id: id }, function(err, item) { |
| 141 | + test.equal(1, item.a); |
| 142 | + test.ok(item.b === undefined); |
| 143 | + var id = new ObjectId(); |
| 144 | + |
| 145 | + collection.update( |
| 146 | + { _id: id, a: 1, b: undefined }, |
| 147 | + { $set: { a: 1, b: undefined } }, |
| 148 | + { upsert: true }, |
| 149 | + function(err) { |
| 150 | + test.equal(null, err); |
| 151 | + collection.findOne({ _id: id }, function(err, item) { |
| 152 | + test.equal(1, item.a); |
| 153 | + test.ok(item.b === undefined); |
| 154 | + client.close(); |
| 155 | + done(); |
| 156 | + }); |
| 157 | + } |
| 158 | + ); |
| 159 | + }); |
| 160 | + } |
| 161 | + ); |
| 162 | + }); |
| 163 | + } |
| 164 | + ); |
| 165 | + }); |
| 166 | + } |
| 167 | + }); |
| 168 | +}); |
0 commit comments