Skip to content

Commit

Permalink
test: Change tests to use native MongoDB aggregation pipeline syntax (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Jan 16, 2023
1 parent 7e1ed12 commit 6870a13
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
steps:
- name: Fix usage of insecure GitHub protocol
run: sudo git config --system url."https://github".insteadOf "git://github"
- name: Fix git protocol for Node 14
if: ${{ startsWith(matrix.NODE_VERSION, '14.') }}
run: sudo git config --system url."https://github".insteadOf "ssh://git@github"
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
Expand Down
16 changes: 8 additions & 8 deletions integration/test/ParseQueryAggregateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Parse Aggregate Query', () => {

it('aggregate pipeline object query', done => {
const pipeline = {
group: { objectId: '$name' },
$group: { _id: '$name' },
};
const query = new Parse.Query(TestObject);
query.aggregate(pipeline).then(results => {
Expand All @@ -24,7 +24,7 @@ describe('Parse Aggregate Query', () => {
});

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

const pipeline = [
{
match: { name: 'Hello' },
$match: { name: 'Hello' },
},
{
// Transform className$objectId to objectId and store in new field tempPointer
project: {
$project: {
tempPointer: { $substr: ['$_p_pointer', 11, -1] }, // Remove TestObject$
},
},
{
// Left Join, replace objectId stored in tempPointer with an actual object
lookup: {
$lookup: {
from: 'TestObject',
localField: 'tempPointer',
foreignField: '_id',
Expand All @@ -72,12 +72,12 @@ describe('Parse Aggregate Query', () => {
},
{
// lookup returns an array, Deconstructs an array field to objects
unwind: {
$unwind: {
path: '$tempPointer',
},
},
{
match: { 'tempPointer.value': 2 },
$match: { 'tempPointer.value': 2 },
},
];
await Parse.Object.saveAll([pointer1, pointer2, pointer3, obj1, obj2, obj3]);
Expand All @@ -91,7 +91,7 @@ describe('Parse Aggregate Query', () => {

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

Expand Down
36 changes: 22 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ class ParseQuery {
if (!Array.isArray(pipeline)) {
pipeline = [pipeline];
}
pipeline.unshift({ match: this._where });
pipeline.unshift({ $match: this._where });
}

const params = {
Expand Down

0 comments on commit 6870a13

Please sign in to comment.