1
1
'use strict' ;
2
2
3
3
const { expect } = require ( 'chai' ) ;
4
- const { ListCollectionsOperation } = require ( '../../mongodb' ) ;
4
+ const { ListCollectionsOperation, StreamDescription } = require ( '../../mongodb' ) ;
5
5
6
6
describe ( 'ListCollectionsOperation' , function ( ) {
7
7
const db = 'test' ;
@@ -65,6 +65,8 @@ describe('ListCollectionsOperation', function () {
65
65
} ) ;
66
66
67
67
describe ( '#generateCommand' , function ( ) {
68
+ const description = new StreamDescription ( ) ;
69
+
68
70
context ( 'when comment is provided' , function ( ) {
69
71
context ( 'when the wireVersion < 9' , function ( ) {
70
72
it ( 'does not set a comment on the command' , function ( ) {
@@ -73,7 +75,10 @@ describe('ListCollectionsOperation', function () {
73
75
{ } ,
74
76
{ dbName : db , comment : 'test comment' }
75
77
) ;
76
- const command = operation . generateCommand ( 8 ) ;
78
+ description . maxWireVersion = 8 ;
79
+ const command = operation . buildCommandDocument ( {
80
+ description
81
+ } ) ;
77
82
expect ( command ) . not . to . haveOwnProperty ( 'comment' ) ;
78
83
} ) ;
79
84
} ) ;
@@ -85,7 +90,10 @@ describe('ListCollectionsOperation', function () {
85
90
{ } ,
86
91
{ dbName : db , comment : 'test comment' }
87
92
) ;
88
- const command = operation . generateCommand ( 9 ) ;
93
+ description . maxWireVersion = 9 ;
94
+ const command = operation . buildCommandDocument ( {
95
+ description
96
+ } ) ;
89
97
expect ( command ) . to . have . property ( 'comment' ) . that . equals ( 'test comment' ) ;
90
98
} ) ;
91
99
} ) ;
@@ -95,7 +103,11 @@ describe('ListCollectionsOperation', function () {
95
103
const operation = new ListCollectionsOperation ( db , { } , { nameOnly : true , dbName : db } ) ;
96
104
97
105
it ( 'sets nameOnly to true' , function ( ) {
98
- expect ( operation . generateCommand ( 8 ) ) . to . deep . equal ( {
106
+ description . maxWireVersion = 8 ;
107
+ const command = operation . buildCommandDocument ( {
108
+ description
109
+ } ) ;
110
+ expect ( command ) . to . deep . equal ( {
99
111
listCollections : 1 ,
100
112
cursor : { } ,
101
113
filter : { } ,
@@ -109,7 +121,11 @@ describe('ListCollectionsOperation', function () {
109
121
const operation = new ListCollectionsOperation ( db , { } , { nameOnly : false , dbName : db } ) ;
110
122
111
123
it ( 'sets nameOnly to false' , function ( ) {
112
- expect ( operation . generateCommand ( 8 ) ) . to . deep . equal ( {
124
+ description . maxWireVersion = 8 ;
125
+ const command = operation . buildCommandDocument ( {
126
+ description
127
+ } ) ;
128
+ expect ( command ) . to . deep . equal ( {
113
129
listCollections : 1 ,
114
130
cursor : { } ,
115
131
filter : { } ,
@@ -129,7 +145,11 @@ describe('ListCollectionsOperation', function () {
129
145
) ;
130
146
131
147
it ( 'sets authorizedCollections to true' , function ( ) {
132
- expect ( operation . generateCommand ( 8 ) ) . to . deep . equal ( {
148
+ description . maxWireVersion = 8 ;
149
+ const command = operation . buildCommandDocument ( {
150
+ description
151
+ } ) ;
152
+ expect ( command ) . to . deep . equal ( {
133
153
listCollections : 1 ,
134
154
cursor : { } ,
135
155
filter : { } ,
@@ -147,7 +167,11 @@ describe('ListCollectionsOperation', function () {
147
167
) ;
148
168
149
169
it ( 'sets authorizedCollections to false' , function ( ) {
150
- expect ( operation . generateCommand ( 8 ) ) . to . deep . equal ( {
170
+ description . maxWireVersion = 8 ;
171
+ const command = operation . buildCommandDocument ( {
172
+ description
173
+ } ) ;
174
+ expect ( command ) . to . deep . equal ( {
151
175
listCollections : 1 ,
152
176
cursor : { } ,
153
177
filter : { } ,
@@ -162,7 +186,11 @@ describe('ListCollectionsOperation', function () {
162
186
const operation = new ListCollectionsOperation ( db , { } , { dbName : db } ) ;
163
187
164
188
it ( 'sets nameOnly and authorizedCollections properties to false' , function ( ) {
165
- expect ( operation . generateCommand ( 8 ) ) . to . deep . equal ( {
189
+ description . maxWireVersion = 8 ;
190
+ const command = operation . buildCommandDocument ( {
191
+ description
192
+ } ) ;
193
+ expect ( command ) . to . deep . equal ( {
166
194
listCollections : 1 ,
167
195
cursor : { } ,
168
196
filter : { } ,
0 commit comments