|
1 | 1 | import { expect } from 'chai';
|
2 | 2 |
|
3 |
| -import { type AggregationCursor, MongoClient } from '../../mongodb'; |
| 3 | +import { |
| 4 | + type AggregationCursor, |
| 5 | + CursorTimeoutMode, |
| 6 | + MongoAPIError, |
| 7 | + MongoClient |
| 8 | +} from '../../mongodb'; |
4 | 9 |
|
5 | 10 | describe('class AggregationCursor', () => {
|
6 | 11 | let client: MongoClient;
|
@@ -126,6 +131,38 @@ describe('class AggregationCursor', () => {
|
126 | 131 | });
|
127 | 132 |
|
128 | 133 | context('when addStage, bespoke stage methods, or array is used to construct pipeline', () => {
|
| 134 | + context('when CSOT is enabled', () => { |
| 135 | + let aggregationCursor: AggregationCursor; |
| 136 | + before(function () { |
| 137 | + aggregationCursor = client |
| 138 | + .db('test') |
| 139 | + .collection('test') |
| 140 | + .aggregate([], { timeoutMS: 100, timeoutMode: CursorTimeoutMode.ITERATION }); |
| 141 | + }); |
| 142 | + |
| 143 | + context('when a $out stage is add with .addStage()', () => { |
| 144 | + it('throws a MongoAPIError', function () { |
| 145 | + expect(() => { |
| 146 | + aggregationCursor.addStage({ $out: 'test' }); |
| 147 | + }).to.throw(MongoAPIError); |
| 148 | + }); |
| 149 | + }); |
| 150 | + context('when a $merge stage is add with .addStage()', () => { |
| 151 | + it('throws a MongoAPIError', function () { |
| 152 | + expect(() => { |
| 153 | + aggregationCursor.addStage({ $merge: {} }); |
| 154 | + }).to.throw(MongoAPIError); |
| 155 | + }); |
| 156 | + }); |
| 157 | + context('when a $out stage is add with .out()', () => { |
| 158 | + it('throws a MongoAPIError', function () { |
| 159 | + expect(() => { |
| 160 | + aggregationCursor.out('test'); |
| 161 | + }).to.throw(MongoAPIError); |
| 162 | + }); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
129 | 166 | it('sets deeply identical aggregations pipelines', () => {
|
130 | 167 | const collection = client.db().collection('test');
|
131 | 168 |
|
@@ -157,4 +194,29 @@ describe('class AggregationCursor', () => {
|
157 | 194 | expect(builderGenericStageCursor.pipeline).to.deep.equal(expectedPipeline);
|
158 | 195 | });
|
159 | 196 | });
|
| 197 | + |
| 198 | + describe('constructor()', () => { |
| 199 | + context('when CSOT is enabled', () => { |
| 200 | + let client: MongoClient; |
| 201 | + before(function () { |
| 202 | + client = new MongoClient('mongodb://iLoveJavascript', { timeoutMS: 100 }); |
| 203 | + }); |
| 204 | + context('when timeoutMode=ITERATION and a $out stage is provided', function () { |
| 205 | + expect(() => { |
| 206 | + client |
| 207 | + .db('test') |
| 208 | + .collection('test') |
| 209 | + .aggregate([{ $out: 'test' }], { timeoutMode: CursorTimeoutMode.ITERATION }); |
| 210 | + }).to.throw(MongoAPIError); |
| 211 | + }); |
| 212 | + context('when timeoutMode=ITERATION and a $merge stage is provided', function () { |
| 213 | + expect(() => { |
| 214 | + client |
| 215 | + .db('test') |
| 216 | + .collection('test') |
| 217 | + .aggregate([{ $merge: 'test' }], { timeoutMode: CursorTimeoutMode.ITERATION }); |
| 218 | + }).to.throw(MongoAPIError); |
| 219 | + }); |
| 220 | + }); |
| 221 | + }); |
160 | 222 | });
|
0 commit comments