Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 27, 2025
1 parent 37fd3a0 commit 6e5e048
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,14 @@ describe('aggregate: ', function() {
it('works', function() {
const aggregate = new Aggregate();

assert.equal(aggregate.near({ a: 1 }), aggregate);
assert.deepEqual(aggregate._pipeline, [{ $geoNear: { a: 1 } }]);
assert.equal(aggregate.near({ near: { type: 'Point', coordinates: [1, 2] } }), aggregate);
assert.deepEqual(aggregate._pipeline, [{ $geoNear: { near: { type: 'Point', coordinates: [1, 2] } } }]);

aggregate.near({ b: 2 });
assert.deepEqual(aggregate._pipeline, [{ $geoNear: { a: 1 } }, { $geoNear: { b: 2 } }]);
aggregate.near({ near: { type: 'Point', coordinates: [3, 4] } });
assert.deepEqual(aggregate._pipeline, [
{ $geoNear: { near: { type: 'Point', coordinates: [1, 2] } } },
{ $geoNear: { near: { type: 'Point', coordinates: [3, 4] } } }
]);
});

it('works with discriminators (gh-3304)', function() {
Expand All @@ -308,19 +311,19 @@ describe('aggregate: ', function() {

aggregate._model = stub;

assert.equal(aggregate.near({ a: 1 }), aggregate);
assert.equal(aggregate.near({ near: { type: 'Point', coordinates: [1, 2] } }), aggregate);
// Run exec so we apply discriminator pipeline
Aggregate._prepareDiscriminatorPipeline(aggregate._pipeline, stub.schema);
assert.deepEqual(aggregate._pipeline,
[{ $geoNear: { a: 1, query: { __t: 'subschema' } } }]);
[{ $geoNear: { near: { type: 'Point', coordinates: [1, 2] }, query: { __t: 'subschema' } } }]);

aggregate = new Aggregate();
aggregate._model = stub;

aggregate.near({ b: 2, query: { x: 1 } });
aggregate.near({ near: { type: 'Point', coordinates: [3, 4] }, query: { x: 1 } });
Aggregate._prepareDiscriminatorPipeline(aggregate._pipeline, stub.schema);
assert.deepEqual(aggregate._pipeline,
[{ $geoNear: { b: 2, query: { x: 1, __t: 'subschema' } } }]);
[{ $geoNear: { near: { type: 'Point', coordinates: [3, 4] }, query: { x: 1, __t: 'subschema' } } }]);
});
});

Expand Down

0 comments on commit 6e5e048

Please sign in to comment.