@@ -11,6 +11,7 @@ import {
11
11
compareObjectId ,
12
12
decorateWithExplain ,
13
13
Explain ,
14
+ hasAtomicOperators ,
14
15
HostAddress ,
15
16
hostMatchesWildcards ,
16
17
isHello ,
@@ -19,13 +20,74 @@ import {
19
20
List ,
20
21
MongoDBCollectionNamespace ,
21
22
MongoDBNamespace ,
23
+ MongoInvalidArgumentError ,
22
24
MongoRuntimeError ,
23
25
ObjectId ,
24
26
shuffle
25
27
} from '../mongodb' ;
26
28
import { sleep } from '../tools/utils' ;
27
29
28
30
describe ( 'driver utils' , function ( ) {
31
+ describe . only ( '.hasAtomicOperators' , function ( ) {
32
+ context ( 'when ignoreUndefined is true' , function ( ) {
33
+ const options = { ignoreUndefined : true } ;
34
+
35
+ context ( 'when no operator is undefined' , function ( ) {
36
+ const document = { $set : { n : 1 } , $unset : '' } ;
37
+
38
+ it ( 'returns true' , function ( ) {
39
+ expect ( hasAtomicOperators ( document , options ) ) . to . be . true ;
40
+ } ) ;
41
+ } ) ;
42
+
43
+ context ( 'when some operators are undefined' , function ( ) {
44
+ const document = { $set : { n : 1 } , $unset : undefined } ;
45
+
46
+ it ( 'returns true' , function ( ) {
47
+ expect ( hasAtomicOperators ( document , options ) ) . to . be . true ;
48
+ } ) ;
49
+ } ) ;
50
+
51
+ context ( 'when all operators are undefined' , function ( ) {
52
+ const document = { $set : undefined , $unset : undefined } ;
53
+
54
+ it ( 'throws an error' , function ( ) {
55
+ expect ( ( ) => {
56
+ hasAtomicOperators ( document , options ) ;
57
+ } ) . to . throw ( MongoInvalidArgumentError ) ;
58
+ } ) ;
59
+ } ) ;
60
+ } ) ;
61
+
62
+ context ( 'when ignoreUndefined is false' , function ( ) {
63
+ const options = { ignoreUndefined : false } ;
64
+
65
+ context ( 'when no operator is undefined' , function ( ) {
66
+ const document = { $set : { n : 1 } , $unset : '' } ;
67
+
68
+ it ( 'returns true' , function ( ) {
69
+ expect ( hasAtomicOperators ( document , options ) ) . to . be . true ;
70
+ } ) ;
71
+ } ) ;
72
+
73
+ context ( 'when some operators are undefined' , function ( ) {
74
+ const document = { $set : { n : 1 } , $unset : undefined } ;
75
+
76
+ it ( 'returns true' , function ( ) {
77
+ expect ( hasAtomicOperators ( document , options ) ) . to . be . true ;
78
+ } ) ;
79
+ } ) ;
80
+
81
+ context ( 'when all operators are undefined' , function ( ) {
82
+ const document = { $set : undefined , $unset : undefined } ;
83
+
84
+ it ( 'returns true' , function ( ) {
85
+ expect ( hasAtomicOperators ( document , options ) ) . to . be . true ;
86
+ } ) ;
87
+ } ) ;
88
+ } ) ;
89
+ } ) ;
90
+
29
91
describe ( '.hostMatchesWildcards' , function ( ) {
30
92
context ( 'when using domains' , function ( ) {
31
93
context ( 'when using exact match' , function ( ) {
0 commit comments