Skip to content

test: Change tests to use native MongoDB aggregation pipeline syntax #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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