|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { expect } = require('chai'); |
| 4 | +const { AggregateOperation } = require('../../../src/operations/aggregate'); |
| 5 | + |
| 6 | +describe('AggregateOperation', function () { |
| 7 | + const db = 'test'; |
| 8 | + |
| 9 | + describe('#constructor', function () { |
| 10 | + context('when out is in the options', function () { |
| 11 | + const operation = new AggregateOperation(db, [], { out: 'test', dbName: db }); |
| 12 | + |
| 13 | + it('sets trySecondaryWrite to true', function () { |
| 14 | + expect(operation.trySecondaryWrite).to.be.true; |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + context('when $out is the last stage', function () { |
| 19 | + const operation = new AggregateOperation(db, [{ $out: 'test' }], { dbName: db }); |
| 20 | + |
| 21 | + it('sets trySecondaryWrite to true', function () { |
| 22 | + expect(operation.trySecondaryWrite).to.be.true; |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + context('when $out is not the last stage', function () { |
| 27 | + const operation = new AggregateOperation(db, [{ $out: 'test' }, { $project: { name: 1 } }], { |
| 28 | + dbName: db |
| 29 | + }); |
| 30 | + |
| 31 | + it('sets trySecondaryWrite to false', function () { |
| 32 | + expect(operation.trySecondaryWrite).to.be.false; |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + context('when $merge is the last stage', function () { |
| 37 | + const operation = new AggregateOperation(db, [{ $merge: { into: 'test' } }], { dbName: db }); |
| 38 | + |
| 39 | + it('sets trySecondaryWrite to true', function () { |
| 40 | + expect(operation.trySecondaryWrite).to.be.true; |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + context('when $merge is not the last stage', function () { |
| 45 | + const operation = new AggregateOperation( |
| 46 | + db, |
| 47 | + [{ $merge: { into: 'test' } }, { $project: { name: 1 } }], |
| 48 | + { dbName: db } |
| 49 | + ); |
| 50 | + |
| 51 | + it('sets trySecondaryWrite to false', function () { |
| 52 | + expect(operation.trySecondaryWrite).to.be.false; |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + context('when no writable stages in empty pipeline', function () { |
| 57 | + const operation = new AggregateOperation(db, [], { dbName: db }); |
| 58 | + |
| 59 | + it('sets trySecondaryWrite to false', function () { |
| 60 | + expect(operation.trySecondaryWrite).to.be.false; |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + context('when no writable stages', function () { |
| 65 | + const operation = new AggregateOperation(db, [{ $project: { name: 1 } }], { dbName: db }); |
| 66 | + |
| 67 | + it('sets trySecondaryWrite to false', function () { |
| 68 | + expect(operation.trySecondaryWrite).to.be.false; |
| 69 | + }); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments