From c8cdcbe10ea3d1761a89363747caf3edf5d46505 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Wed, 13 Jan 2021 12:40:18 -0500 Subject: [PATCH] Improve test code (#7121) --- spec/Auth.spec.js | 8 ++--- spec/ParseAPI.spec.js | 33 +++++-------------- spec/helper.js | 2 +- spec/testing-routes.js | 72 ------------------------------------------ 4 files changed, 13 insertions(+), 102 deletions(-) delete mode 100644 spec/testing-routes.js diff --git a/spec/Auth.spec.js b/spec/Auth.spec.js index ede7eeeda2..38302aa24e 100644 --- a/spec/Auth.spec.js +++ b/spec/Auth.spec.js @@ -168,9 +168,9 @@ describe('Auth', () => { const acl = new Parse.ACL(); const role = new Parse.Role('roleloadtest' + i, acl); role.getUsers().add([user]); - roles.push(role.save()); + roles.push(role); } - const savedRoles = await Promise.all(roles); + const savedRoles = await Parse.Object.saveAll(roles); expect(savedRoles.length).toBe(rolesNumber); const cloudRoles = await userAuth.getRolesForUser(); expect(cloudRoles.length).toBe(rolesNumber); @@ -192,9 +192,9 @@ describe('Auth', () => { const acl = new Parse.ACL(); const role = new Parse.Role('roleloadtest' + i, acl); role.getUsers().add([user]); - roles.push(role.save()); + roles.push(role); } - const savedRoles = await Promise.all(roles); + const savedRoles = await Parse.Object.saveAll(roles); expect(savedRoles.length).toBe(rolesNumber); const cloudRoles = await userAuth.getRolesForUser(); expect(cloudRoles.length).toBe(rolesNumber); diff --git a/spec/ParseAPI.spec.js b/spec/ParseAPI.spec.js index 0a8c147592..39aed06206 100644 --- a/spec/ParseAPI.spec.js +++ b/spec/ParseAPI.spec.js @@ -24,31 +24,14 @@ const headers = { }; describe_only_db('mongo')('miscellaneous', () => { - it('test rest_create_app', function (done) { - let appId; - Parse._request('POST', 'rest_create_app') - .then(res => { - expect(typeof res.application_id).toEqual('string'); - expect(res.master_key).toEqual('master'); - appId = res.application_id; - Parse.initialize(appId, 'unused'); - const obj = new Parse.Object('TestObject'); - obj.set('foo', 'bar'); - return obj.save(); - }) - .then(() => { - const config = Config.get(appId); - return config.database.adapter.find('TestObject', { fields: {} }, {}, {}); - }) - .then(results => { - expect(results.length).toEqual(1); - expect(results[0]['foo']).toEqual('bar'); - done(); - }) - .catch(error => { - fail(JSON.stringify(error)); - done(); - }); + it('db contains document after successful save', async () => { + const obj = new Parse.Object('TestObject'); + obj.set('foo', 'bar'); + await obj.save(); + const config = Config.get(defaultConfiguration.appId); + const results = await config.database.adapter.find('TestObject', { fields: {} }, {}, {}); + expect(results.length).toEqual(1); + expect(results[0]['foo']).toEqual('bar'); }); }); diff --git a/spec/helper.js b/spec/helper.js index 5c598277f5..dbea84edd2 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -134,6 +134,7 @@ const reconfigureServer = changedConfiguration => { if (error) { reject(error); } else { + Parse.CoreManager.set('REQUEST_ATTEMPT_LIMIT', 1); resolve(parseServer); } }, @@ -142,7 +143,6 @@ const reconfigureServer = changedConfiguration => { }); cache.clear(); parseServer = ParseServer.start(newConfiguration); - parseServer.app.use(require('./testing-routes').router); parseServer.expressApp.use('/1', err => { console.error(err); fail('should not call next'); diff --git a/spec/testing-routes.js b/spec/testing-routes.js deleted file mode 100644 index 4cf626bc66..0000000000 --- a/spec/testing-routes.js +++ /dev/null @@ -1,72 +0,0 @@ -// testing-routes.js -const AppCache = require('../lib/cache').default; -const middlewares = require('../lib/middlewares'); -const { ParseServer } = require('../lib/index'); -const { Parse } = require('parse/node'); - -const express = require('express'), - cryptoUtils = require('../lib/cryptoUtils'); - -const router = express.Router(); - -// creates a unique app in the cache, with a collection prefix -function createApp(req, res) { - const appId = cryptoUtils.randomHexString(32); - - ParseServer({ - databaseURI: 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase', - appId: appId, - masterKey: 'master', - serverURL: Parse.serverURL, - collectionPrefix: appId, - }); - const keys = { - application_id: appId, - client_key: 'unused', - windows_key: 'unused', - javascript_key: 'unused', - webhook_key: 'unused', - rest_api_key: 'unused', - master_key: 'master', - }; - res.status(200).send(keys); -} - -// deletes all collections that belong to the app -function clearApp(req, res) { - if (!req.auth.isMaster) { - return res.status(401).send({ error: 'unauthorized' }); - } - return req.config.database.deleteEverything().then(() => { - res.status(200).send({}); - }); -} - -// deletes all collections and drops the app from cache -function dropApp(req, res) { - if (!req.auth.isMaster) { - return res.status(401).send({ error: 'unauthorized' }); - } - return req.config.database.deleteEverything().then(() => { - AppCache.del(req.config.applicationId); - res.status(200).send({}); - }); -} - -// Lets just return a success response and see what happens. -function notImplementedYet(req, res) { - res.status(200).send({}); -} - -router.post('/rest_clear_app', middlewares.handleParseHeaders, clearApp); -router.post('/rest_block', middlewares.handleParseHeaders, notImplementedYet); -router.post('/rest_mock_v8_client', middlewares.handleParseHeaders, notImplementedYet); -router.post('/rest_unmock_v8_client', middlewares.handleParseHeaders, notImplementedYet); -router.post('/rest_verify_analytics', middlewares.handleParseHeaders, notImplementedYet); -router.post('/rest_create_app', createApp); -router.post('/rest_drop_app', middlewares.handleParseHeaders, dropApp); -router.post('/rest_configure_app', middlewares.handleParseHeaders, notImplementedYet); - -module.exports = { - router: router, -};