From 9433c002ee95f56393c4efad02838f1990effafb Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 1 Apr 2025 09:25:43 -0500 Subject: [PATCH 1/3] feat: Improve handling aggregate query errors --- spec/ParseQuery.Aggregate.spec.js | 17 +++++++++++++++++ src/Routers/AggregateRouter.js | 23 ++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/spec/ParseQuery.Aggregate.spec.js b/spec/ParseQuery.Aggregate.spec.js index 902b34d9d3..e7af1a6c03 100644 --- a/spec/ParseQuery.Aggregate.spec.js +++ b/spec/ParseQuery.Aggregate.spec.js @@ -1500,4 +1500,21 @@ describe('Parse.Query Aggregate testing', () => { expect(results.length).toEqual(3); await database.adapter.deleteAllClasses(false); }); + + it_only_db('mongo')('aggregate handle mongodb errors', async () => { + const pipeline = [ + { + $search: { + index: "default", + text: { + path: ["name"], + query: 'foo', + }, + }, + }, + ]; + await expectAsync(new Parse.Query(TestObject).aggregate(pipeline)).toBeRejectedWith( + new Parse.Error(Parse.Error.INVALID_QUERY, 'Using $search and $vectorSearch aggregation stages requires additional configuration. Please connect to Atlas or an AtlasCLI local deployment to enable.For more information on how to connect, see https://dochub.mongodb.org/core/atlas-cli-deploy-local-reqs.') + ); + }); }); diff --git a/src/Routers/AggregateRouter.js b/src/Routers/AggregateRouter.js index d2b8636b74..cf9b5cd190 100644 --- a/src/Routers/AggregateRouter.js +++ b/src/Routers/AggregateRouter.js @@ -5,7 +5,7 @@ import ClassesRouter from './ClassesRouter'; import UsersRouter from './UsersRouter'; export class AggregateRouter extends ClassesRouter { - handleFind(req) { + async handleFind(req) { const body = Object.assign(req.body || {}, ClassesRouter.JSONFromQuery(req.query)); const options = {}; if (body.distinct) { @@ -31,8 +31,8 @@ export class AggregateRouter extends ClassesRouter { if (typeof body.where === 'string') { body.where = JSON.parse(body.where); } - return rest - .find( + try { + const response = await rest.find( req.config, req.auth, this.className(req), @@ -40,15 +40,16 @@ export class AggregateRouter extends ClassesRouter { options, req.info.clientSDK, req.info.context - ) - .then(response => { - for (const result of response.results) { - if (typeof result === 'object') { - UsersRouter.removeHiddenProperties(result); - } + ); + for (const result of response.results) { + if (typeof result === 'object') { + UsersRouter.removeHiddenProperties(result); } - return { response }; - }); + } + return { response }; + } catch (e) { + throw new Parse.Error(Parse.Error.INVALID_QUERY, e.message); + } } /* Builds a pipeline from the body. Originally the body could be passed as a single object, From 8b54a051d6e754ad94263bb4efab7b8ac9eded47 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 1 Apr 2025 09:48:50 -0500 Subject: [PATCH 2/3] simplify tests --- spec/ParseQuery.Aggregate.spec.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/ParseQuery.Aggregate.spec.js b/spec/ParseQuery.Aggregate.spec.js index e7af1a6c03..d255f30166 100644 --- a/spec/ParseQuery.Aggregate.spec.js +++ b/spec/ParseQuery.Aggregate.spec.js @@ -1513,8 +1513,11 @@ describe('Parse.Query Aggregate testing', () => { }, }, ]; - await expectAsync(new Parse.Query(TestObject).aggregate(pipeline)).toBeRejectedWith( - new Parse.Error(Parse.Error.INVALID_QUERY, 'Using $search and $vectorSearch aggregation stages requires additional configuration. Please connect to Atlas or an AtlasCLI local deployment to enable.For more information on how to connect, see https://dochub.mongodb.org/core/atlas-cli-deploy-local-reqs.') - ); + try { + await new Parse.Query(TestObject).aggregate(pipeline); + fail(); + } catch (e) { + expect(e.code).toBe(Parse.Error.INVALID_QUERY); + } }); }); From 1c584e704386fde187d8cea16646fac5da492a17 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 1 Apr 2025 10:25:36 -0500 Subject: [PATCH 3/3] flaky test --- spec/support/CurrentSpecReporter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/CurrentSpecReporter.js b/spec/support/CurrentSpecReporter.js index 626517cdf4..27e4942095 100755 --- a/spec/support/CurrentSpecReporter.js +++ b/spec/support/CurrentSpecReporter.js @@ -22,6 +22,8 @@ const flakyTests = [ "Email Verification Token Expiration: sets the _email_verify_token_expires_at and _email_verify_token fields after user SignUp", // Expected 0 to be 1. "Email Verification Token Expiration: should send a new verification email when a resend is requested and the user is UNVERIFIED", + // Expected 0 to be 1. + "Email Verification Token Expiration: should match codes with emailVerifyTokenReuseIfValid", ]; /** The minimum execution time in seconds for a test to be considered slow. */