1- 'use strict ';
1+ import { expect } from 'chai ';
22
3- const { expect } = require ( 'chai' ) ;
4- const { AggregateOperation } = require ( '../../../src/operations/aggregate' ) ;
3+ import { AggregateOperation } from '../../../src/operations/aggregate' ;
4+ import { MongoDBNamespace , WriteConcern } from '../../mongodb' ;
55
66describe ( 'AggregateOperation' , function ( ) {
7- const db = 'test' ;
7+ const ns = new MongoDBNamespace ( 'test' , 'coll' ) ;
88
99 describe ( '#constructor' , function ( ) {
1010 context ( 'when out is in the options' , function ( ) {
11- const operation = new AggregateOperation ( db , [ ] , { out : 'test' , dbName : db } ) ;
11+ const operation = new AggregateOperation ( ns , [ ] , { out : 'test' , dbName : ns . db } ) ;
1212
1313 it ( 'sets hasWriteStage to true' , function ( ) {
1414 expect ( operation . hasWriteStage ) . to . be . true ;
1515 } ) ;
1616 } ) ;
1717
1818 context ( 'when $out is the last stage' , function ( ) {
19- const operation = new AggregateOperation ( db , [ { $out : 'test' } ] , { dbName : db } ) ;
19+ const operation = new AggregateOperation ( ns , [ { $out : 'test' } ] , { dbName : ns . db } ) ;
2020
2121 it ( 'sets hasWriteStage to true' , function ( ) {
2222 expect ( operation . hasWriteStage ) . to . be . true ;
2323 } ) ;
2424 } ) ;
2525
2626 context ( 'when $out is not the last stage' , function ( ) {
27- const operation = new AggregateOperation ( db , [ { $out : 'test' } , { $project : { name : 1 } } ] , {
28- dbName : db
27+ const operation = new AggregateOperation ( ns , [ { $out : 'test' } , { $project : { name : 1 } } ] , {
28+ dbName : ns . db
2929 } ) ;
3030
3131 it ( 'sets hasWriteStage to false' , function ( ) {
@@ -34,7 +34,9 @@ describe('AggregateOperation', function () {
3434 } ) ;
3535
3636 context ( 'when $merge is the last stage' , function ( ) {
37- const operation = new AggregateOperation ( db , [ { $merge : { into : 'test' } } ] , { dbName : db } ) ;
37+ const operation = new AggregateOperation ( ns , [ { $merge : { into : 'test' } } ] , {
38+ dbName : ns . db
39+ } ) ;
3840
3941 it ( 'sets hasWriteStage to true' , function ( ) {
4042 expect ( operation . hasWriteStage ) . to . be . true ;
@@ -43,9 +45,9 @@ describe('AggregateOperation', function () {
4345
4446 context ( 'when $merge is not the last stage' , function ( ) {
4547 const operation = new AggregateOperation (
46- db ,
48+ ns ,
4749 [ { $merge : { into : 'test' } } , { $project : { name : 1 } } ] ,
48- { dbName : db }
50+ { dbName : ns . db }
4951 ) ;
5052
5153 it ( 'sets hasWriteStage to false' , function ( ) {
@@ -54,19 +56,33 @@ describe('AggregateOperation', function () {
5456 } ) ;
5557
5658 context ( 'when no writable stages in empty pipeline' , function ( ) {
57- const operation = new AggregateOperation ( db , [ ] , { dbName : db } ) ;
59+ const operation = new AggregateOperation ( ns , [ ] , { dbName : ns . db } ) ;
5860
5961 it ( 'sets hasWriteStage to false' , function ( ) {
6062 expect ( operation . hasWriteStage ) . to . be . false ;
6163 } ) ;
6264 } ) ;
6365
6466 context ( 'when no writable stages' , function ( ) {
65- const operation = new AggregateOperation ( db , [ { $project : { name : 1 } } ] , { dbName : db } ) ;
67+ const operation = new AggregateOperation ( ns , [ { $project : { name : 1 } } ] , { dbName : ns } ) ;
6668
6769 it ( 'sets hasWriteStage to false' , function ( ) {
6870 expect ( operation . hasWriteStage ) . to . be . false ;
6971 } ) ;
7072 } ) ;
73+
74+ context ( 'when explain is set' , function ( ) {
75+ context ( 'when writeConcern is set' , function ( ) {
76+ const operation = new AggregateOperation ( ns , [ ] , {
77+ dbName : ns . db ,
78+ explain : true ,
79+ writeConcern : WriteConcern . fromOptions ( { wtimeoutMS : 1000 } )
80+ } ) ;
81+
82+ it ( 'does not raise an error' , function ( ) {
83+ expect ( operation . explain ) . to . exist ;
84+ } ) ;
85+ } ) ;
86+ } ) ;
7187 } ) ;
7288} ) ;
0 commit comments