1
- 'use strict ';
1
+ import { expect } from 'chai ';
2
2
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' ;
5
5
6
6
describe ( 'AggregateOperation' , function ( ) {
7
- const db = 'test' ;
7
+ const ns = new MongoDBNamespace ( 'test' , 'coll' ) ;
8
8
9
9
describe ( '#constructor' , function ( ) {
10
10
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 } ) ;
12
12
13
13
it ( 'sets hasWriteStage to true' , function ( ) {
14
14
expect ( operation . hasWriteStage ) . to . be . true ;
15
15
} ) ;
16
16
} ) ;
17
17
18
18
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 } ) ;
20
20
21
21
it ( 'sets hasWriteStage to true' , function ( ) {
22
22
expect ( operation . hasWriteStage ) . to . be . true ;
23
23
} ) ;
24
24
} ) ;
25
25
26
26
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
29
29
} ) ;
30
30
31
31
it ( 'sets hasWriteStage to false' , function ( ) {
@@ -34,7 +34,9 @@ describe('AggregateOperation', function () {
34
34
} ) ;
35
35
36
36
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
+ } ) ;
38
40
39
41
it ( 'sets hasWriteStage to true' , function ( ) {
40
42
expect ( operation . hasWriteStage ) . to . be . true ;
@@ -43,9 +45,9 @@ describe('AggregateOperation', function () {
43
45
44
46
context ( 'when $merge is not the last stage' , function ( ) {
45
47
const operation = new AggregateOperation (
46
- db ,
48
+ ns ,
47
49
[ { $merge : { into : 'test' } } , { $project : { name : 1 } } ] ,
48
- { dbName : db }
50
+ { dbName : ns . db }
49
51
) ;
50
52
51
53
it ( 'sets hasWriteStage to false' , function ( ) {
@@ -54,19 +56,33 @@ describe('AggregateOperation', function () {
54
56
} ) ;
55
57
56
58
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 } ) ;
58
60
59
61
it ( 'sets hasWriteStage to false' , function ( ) {
60
62
expect ( operation . hasWriteStage ) . to . be . false ;
61
63
} ) ;
62
64
} ) ;
63
65
64
66
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 } ) ;
66
68
67
69
it ( 'sets hasWriteStage to false' , function ( ) {
68
70
expect ( operation . hasWriteStage ) . to . be . false ;
69
71
} ) ;
70
72
} ) ;
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
+ } ) ;
71
87
} ) ;
72
88
} ) ;
0 commit comments