diff --git a/spec/CLI.spec.js b/spec/CLI.spec.js index 540f02abf6..63a068ae96 100644 --- a/spec/CLI.spec.js +++ b/spec/CLI.spec.js @@ -219,7 +219,7 @@ describe('execution', () => { } }); - it('shoud start Parse Server', done => { + it('should start Parse Server', done => { childProcess = spawn(binPath, [ '--appId', 'test', @@ -241,7 +241,16 @@ describe('execution', () => { }); }); - it('shoud start Parse Server with GraphQL', done => { + it('should throw without masterKey and appId', done => { + childProcess = spawn(binPath, []); + childProcess.stderr.on('data', data => { + if (data.toString().includes('ERROR: appId and masterKey are required')) { + done(); + } + }); + }); + + it('should start Parse Server with GraphQL', done => { childProcess = spawn(binPath, [ '--appId', 'test', @@ -267,7 +276,7 @@ describe('execution', () => { }); }); - it('shoud start Parse Server with GraphQL and Playground', done => { + it('should start Parse Server with GraphQL and Playground', done => { childProcess = spawn(binPath, [ '--appId', 'test', @@ -294,4 +303,28 @@ describe('execution', () => { done.fail(data.toString()); }); }); + + it('should redact push keys', done => { + childProcess = spawn(binPath, [ + '--appId', + 'test', + '--masterKey', + 'test', + '--databaseURI', + 'mongodb://localhost/test', + '--port', + '1341', + '--push', + '123', + ]); + childProcess.stdout.on('data', data => { + data = data.toString(); + if (data.includes('**REDACTED**')) { + done(); + } + }); + childProcess.stderr.on('data', data => { + done.fail(data.toString()); + }); + }); }); diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index ae24f75874..ab9a189f39 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -19,6 +19,14 @@ const mockAdapter = { }; describe('Cloud Code', () => { + it('can cannot load invalid cloud code', async () => { + await expectAsync( + reconfigureServer({ + cloud: true, + }) + ).toBeRejectedWith("argument 'cloud' must either be a string or a function"); + }); + it('can load absolute cloud code file', done => { reconfigureServer({ cloud: __dirname + '/cloud/cloudCodeRelativeFile.js', @@ -39,6 +47,18 @@ describe('Cloud Code', () => { }); }); + it('can load cloud code as a function', async () => { + await reconfigureServer({ + cloud: () => { + Parse.Cloud.define('hellofunction', () => { + return 'Hello world function!'; + }); + }, + }); + const result = await Parse.Cloud.run('hellofunction'); + expect(result).toBe('Hello world function!'); + }); + it('can create functions', done => { Parse.Cloud.define('hello', () => { return 'Hello world!'; diff --git a/spec/MessageQueue.spec.js b/spec/MessageQueue.spec.js new file mode 100644 index 0000000000..efc0ab5d9e --- /dev/null +++ b/spec/MessageQueue.spec.js @@ -0,0 +1,22 @@ +const ParseMessageQueue = require('../lib/ParseMessageQueue').ParseMessageQueue; +describe('message queue', () => { + it('cannot create message quue with an invalid adapter', function () { + expect(() => + ParseMessageQueue.createPublisher({ + messageQueueAdapter: { + createPublisher: 'a', + createSubscriber: () => {}, + }, + }) + ).toThrow('pubSubAdapter should have createPublisher()'); + + expect(() => + ParseMessageQueue.createSubscriber({ + messageQueueAdapter: { + createPublisher: () => {}, + createSubscriber: 'a', + }, + }) + ).toThrow('messageQueueAdapter should have createSubscriber()'); + }); +}); diff --git a/spec/PagesRouter.spec.js b/spec/PagesRouter.spec.js index e50144f1fe..73c75ba2c2 100644 --- a/spec/PagesRouter.spec.js +++ b/spec/PagesRouter.spec.js @@ -92,6 +92,14 @@ describe('Pages Router', () => { expect(response.status).toBe(403); } }); + + it('can create new page', () => { + const page = new Page({ id: 'testId', defaultFile: './defaultFile' }); + page.id = 'newId'; + page.defaultFile = 'newDefaultFile'; + expect(page._id).toBe('newId'); + expect(page._defaultFile).toBe('newDefaultFile'); + }); }); describe('AJAX requests', () => { diff --git a/spec/ParseAPI.spec.js b/spec/ParseAPI.spec.js index 9b1a97af87..5356a27ffc 100644 --- a/spec/ParseAPI.spec.js +++ b/spec/ParseAPI.spec.js @@ -1827,6 +1827,13 @@ describe('miscellaneous', function () { } ); }); + it('test TestUtils', () => { + delete process.env.TESTING; + expect(() => TestUtils.destroyAllDataPermanently()).toThrow( + 'Only supported in test environment' + ); + process.env.TESTING = true; + }); }); describe_only_db('mongo')('legacy _acl', () => { diff --git a/spec/ParsePubSub.spec.js b/spec/ParsePubSub.spec.js index 53bdd0b674..c8f44e9548 100644 --- a/spec/ParsePubSub.spec.js +++ b/spec/ParsePubSub.spec.js @@ -97,6 +97,25 @@ describe('ParsePubSub', function () { expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled(); }); + it('cannot create publisher/sub with an invalid adapter', function () { + expect(() => + ParsePubSub.createPublisher({ + pubSubAdapter: { + createPublisher: 'a', + createSubscriber: () => {}, + }, + }) + ).toThrow('pubSubAdapter should have createPublisher()'); + expect(() => + ParsePubSub.createSubscriber({ + pubSubAdapter: { + createPublisher: () => {}, + createSubscriber: 'a', + }, + }) + ).toThrow('pubSubAdapter should have createSubscriber()'); + }); + it('can create publisher/sub with custom function adapter', function () { const adapter = { createPublisher: jasmine.createSpy('createPublisher'), diff --git a/src/cli/parse-server.js b/src/cli/parse-server.js index 4ee9dc4c03..0884749754 100755 --- a/src/cli/parse-server.js +++ b/src/cli/parse-server.js @@ -39,7 +39,6 @@ runner({ console.error(''); process.exit(1); } - if (options['liveQuery.classNames']) { options.liveQuery = options.liveQuery || {}; options.liveQuery.classNames = options['liveQuery.classNames']; @@ -55,7 +54,6 @@ runner({ options.liveQuery.redisOptions = options['liveQuery.redisOptions']; delete options['liveQuery.redisOptions']; } - if (options.cluster) { const numCPUs = typeof options.cluster === 'number' ? options.cluster : os.cpus().length; if (cluster.isMaster) { diff --git a/src/cli/utils/runner.js b/src/cli/utils/runner.js index d74a7a5928..506138c30e 100644 --- a/src/cli/utils/runner.js +++ b/src/cli/utils/runner.js @@ -10,13 +10,7 @@ function logStartupOptions(options) { value = '***REDACTED***'; } if (typeof value === 'object') { - try { - value = JSON.stringify(value); - } catch (e) { - if (value && value.constructor && value.constructor.name) { - value = value.constructor.name; - } - } + value = JSON.stringify(value); } /* eslint-disable no-console */ console.log(`${key}: ${value}`);