Skip to content

Commit 45be5cd

Browse files
committed
Move logic to it's own function and use it for appId and masterKey as well.
1 parent adc0f64 commit 45be5cd

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

spec/index.spec.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,9 @@ var request = require('request');
22

33
describe('server', () => {
44
it('requires a master key and app id', done => {
5-
expect(setServerConfiguration.bind(undefined, { masterKey: 'mykey', serverURL: '' })).toThrow('You must provide an appId and masterKey!');
6-
expect(setServerConfiguration.bind(undefined, { appId: 'myId', serverURL: '' })).toThrow('You must provide an appId and masterKey!');
7-
done();
8-
});
9-
10-
it('requires a serverURL', done => {
11-
expect(setServerConfiguration.bind(undefined, {
12-
databaseURI: 'mongodb://fake:[email protected]:43605/drew3',
13-
appId: 'test',
14-
javascriptKey: 'test',
15-
dotNetKey: 'windows',
16-
clientKey: 'client',
17-
restAPIKey: 'rest',
18-
masterKey: 'test',
19-
collectionPrefix: 'test_',
20-
fileKey: 'test',
21-
})).toThrow('You must provide a serverURL!');
5+
expect(setServerConfiguration.bind(undefined, { })).toThrow('You must provide an appId!');
6+
expect(setServerConfiguration.bind(undefined, { appId: 'myId' })).toThrow('You must provide a masterKey!');
7+
expect(setServerConfiguration.bind(undefined, { appId: 'myId', masterKey: 'mk' })).toThrow('You must provide a serverURL!');
228
done();
239
});
2410

src/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { loadAdapter } from './Adapters/AdapterLoader';
3737
import { FileLoggerAdapter } from './Adapters/Logger/FileLoggerAdapter';
3838
import { LoggerController } from './Controllers/LoggerController';
3939

40+
import requiredParameter from './requiredParameter';
4041
// Mutate the Parse object to add the Cloud Code handlers
4142
addParseCloud();
4243

@@ -65,8 +66,8 @@ addParseCloud();
6566
// "push": optional key from configure push
6667

6768
function ParseServer({
68-
appId,
69-
masterKey,
69+
appId = requiredParameter('You must provide an appId!'),
70+
masterKey = requiredParameter('You must provide a masterKey!'),
7071
databaseAdapter,
7172
filesAdapter,
7273
push,
@@ -82,12 +83,8 @@ function ParseServer({
8283
facebookAppIds = [],
8384
enableAnonymousUsers = true,
8485
oauth = {},
85-
serverURL = (()=>{throw 'You must provide a serverURL!'})(),
86+
serverURL = requiredParameter('You must provide a serverURL!'),
8687
}) {
87-
if (!appId || !masterKey) {
88-
throw 'You must provide an appId and masterKey!';
89-
}
90-
9188
if (databaseAdapter) {
9289
DatabaseAdapter.setAdapter(databaseAdapter);
9390
}

src/requiredParameter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* @flow */
2+
export default (errorMessage: string) => {throw errorMessage}

0 commit comments

Comments
 (0)