Skip to content

Commit 6870a13

Browse files
authored
test: Change tests to use native MongoDB aggregation pipeline syntax (#1654)
1 parent 7e1ed12 commit 6870a13

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
steps:
3535
- name: Fix usage of insecure GitHub protocol
3636
run: sudo git config --system url."https://github".insteadOf "git://github"
37+
- name: Fix git protocol for Node 14
38+
if: ${{ startsWith(matrix.NODE_VERSION, '14.') }}
39+
run: sudo git config --system url."https://github".insteadOf "ssh://git@github"
3740
- uses: actions/checkout@v2
3841
- name: Use Node.js
3942
uses: actions/setup-node@v1

integration/test/ParseQueryAggregateTest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Parse Aggregate Query', () => {
1414

1515
it('aggregate pipeline object query', done => {
1616
const pipeline = {
17-
group: { objectId: '$name' },
17+
$group: { _id: '$name' },
1818
};
1919
const query = new Parse.Query(TestObject);
2020
query.aggregate(pipeline).then(results => {
@@ -24,7 +24,7 @@ describe('Parse Aggregate Query', () => {
2424
});
2525

2626
it('aggregate pipeline array query', done => {
27-
const pipeline = [{ group: { objectId: '$name' } }];
27+
const pipeline = [{ $group: { _id: '$name' } }];
2828
const query = new Parse.Query(TestObject);
2929
query.aggregate(pipeline).then(results => {
3030
assert.equal(results.length, 3);
@@ -53,17 +53,17 @@ describe('Parse Aggregate Query', () => {
5353

5454
const pipeline = [
5555
{
56-
match: { name: 'Hello' },
56+
$match: { name: 'Hello' },
5757
},
5858
{
5959
// Transform className$objectId to objectId and store in new field tempPointer
60-
project: {
60+
$project: {
6161
tempPointer: { $substr: ['$_p_pointer', 11, -1] }, // Remove TestObject$
6262
},
6363
},
6464
{
6565
// Left Join, replace objectId stored in tempPointer with an actual object
66-
lookup: {
66+
$lookup: {
6767
from: 'TestObject',
6868
localField: 'tempPointer',
6969
foreignField: '_id',
@@ -72,12 +72,12 @@ describe('Parse Aggregate Query', () => {
7272
},
7373
{
7474
// lookup returns an array, Deconstructs an array field to objects
75-
unwind: {
75+
$unwind: {
7676
path: '$tempPointer',
7777
},
7878
},
7979
{
80-
match: { 'tempPointer.value': 2 },
80+
$match: { 'tempPointer.value': 2 },
8181
},
8282
];
8383
await Parse.Object.saveAll([pointer1, pointer2, pointer3, obj1, obj2, obj3]);
@@ -91,7 +91,7 @@ describe('Parse Aggregate Query', () => {
9191

9292
it('aggregate pipeline on top of a simple query', async done => {
9393
const pipeline = {
94-
group: { objectId: '$name' },
94+
$group: { _id: '$name' },
9595
};
9696
let results = await new Parse.Query(TestObject).equalTo('name', 'foo').aggregate(pipeline);
9797

package-lock.json

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ParseQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ class ParseQuery {
832832
if (!Array.isArray(pipeline)) {
833833
pipeline = [pipeline];
834834
}
835-
pipeline.unshift({ match: this._where });
835+
pipeline.unshift({ $match: this._where });
836836
}
837837

838838
const params = {

0 commit comments

Comments
 (0)