@@ -5385,39 +5385,86 @@ describe('Parse.Query testing', () => {
53855385 } ) ;
53865386 } ) ;
53875387
5388- it_id ( 'DEPPS12 ' ) ( it_only_db ( 'mongo' ) ) (
5389- 'throws error when using explain without master key' ,
5388+ it_id ( 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d ' ) ( it_only_db ( 'mongo' ) ) (
5389+ 'explain works with and without master key when allowPublicExplain is true ' ,
53905390 async ( ) => {
5391+ await reconfigureServer ( {
5392+ databaseURI : 'mongodb://localhost:27017/parse' ,
5393+ databaseAdapter : null ,
5394+ databaseOptions : {
5395+ allowPublicExplain : true ,
5396+ } ,
5397+ } ) ;
5398+
53915399 const obj = new TestObject ( { foo : 'bar' } ) ;
53925400 await obj . save ( ) ;
53935401
5394- const spyLogRuntimeDeprecation = spyOn ( Deprecator , 'logRuntimeDeprecation' ) ;
5395-
5396- // Test that explain without master key throws an error
5402+ // Without master key
53975403 const query = new Parse . Query ( TestObject ) ;
53985404 query . explain ( ) ;
5405+ const resultWithoutMasterKey = await query . find ( ) ;
5406+ expect ( resultWithoutMasterKey ) . toBeDefined ( ) ;
53995407
5400- try {
5401- await query . find ( ) ;
5408+ // With master key
5409+ const queryWithMasterKey = new Parse . Query ( TestObject ) ;
5410+ queryWithMasterKey . explain ( ) ;
5411+ const resultWithMasterKey = await queryWithMasterKey . find ( { useMasterKey : true } ) ;
5412+ expect ( resultWithMasterKey ) . toBeDefined ( ) ;
5413+ }
5414+ ) ;
54025415
5403- expect ( spyLogRuntimeDeprecation ) . toHaveBeenCalledTimes ( 1 ) ;
5404- expect ( spyLogRuntimeDeprecation ) . toHaveBeenCalledWith ( {
5405- usage : 'Using the explain query parameter without the master key' ,
5406- } ) ;
5407- // fail('Should have thrown an error');
5408- } catch ( error ) {
5409- // Uncomment this after the Deprecation DEPPS12
5410- // expect(error.code).toEqual(Parse.Error.INVALID_QUERY);
5411- // expect(error.message).toEqual('Using the explain query parameter without the master key');
5412- }
5416+ it_id ( 'b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e' ) ( it_only_db ( 'mongo' ) ) (
5417+ 'explain requires master key when allowPublicExplain is false' ,
5418+ async ( ) => {
5419+ console . log ( "just before test" )
5420+ await reconfigureServer ( {
5421+ databaseURI : 'mongodb://localhost:27017/parse' ,
5422+ databaseAdapter : null ,
5423+ databaseOptions : {
5424+ allowPublicExplain : false ,
5425+ } ,
5426+ } ) ;
5427+
5428+ const obj = new TestObject ( { foo : 'bar' } ) ;
5429+ await obj . save ( ) ;
5430+
5431+ // Without master key
5432+ const query = new Parse . Query ( TestObject ) ;
5433+ query . explain ( ) ;
5434+ await expectAsync ( query . find ( ) ) . toBeRejectedWith (
5435+ new Parse . Error (
5436+ Parse . Error . INVALID_QUERY ,
5437+ 'Using the explain query parameter requires the master key'
5438+ )
5439+ ) ;
54135440
5414- // Test that explain with master key works fine
5441+ // With master key
54155442 const queryWithMasterKey = new Parse . Query ( TestObject ) ;
54165443 queryWithMasterKey . explain ( ) ;
54175444 const result = await queryWithMasterKey . find ( { useMasterKey : true } ) ;
5418-
5419- // Should return explain result (not throw error)
54205445 expect ( result ) . toBeDefined ( ) ;
54215446 }
54225447 ) ;
5448+
5449+ it_id ( 'c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f' ) ( it_only_db ( 'mongo' ) ) (
5450+ 'explain works with and without master key by default (allowPublicExplain not set)' ,
5451+ async ( ) => {
5452+ await reconfigureServer ( { } ) ;
5453+
5454+ const obj = new TestObject ( { foo : 'bar' } ) ;
5455+ await obj . save ( ) ;
5456+
5457+ // Without master key (default behavior)
5458+ const query = new Parse . Query ( TestObject ) ;
5459+ query . explain ( ) ;
5460+ const resultWithoutMasterKey = await query . find ( ) ;
5461+ expect ( resultWithoutMasterKey ) . toBeDefined ( ) ;
5462+
5463+ // With master key
5464+ const queryWithMasterKey = new Parse . Query ( TestObject ) ;
5465+ queryWithMasterKey . explain ( ) ;
5466+ const resultWithMasterKey = await queryWithMasterKey . find ( { useMasterKey : true } ) ;
5467+ expect ( resultWithMasterKey ) . toBeDefined ( ) ;
5468+ }
5469+ ) ;
54235470} ) ;
0 commit comments