Skip to content

Commit 8788a0e

Browse files
committed
reconfigure username/email tests
1 parent d93d9a9 commit 8788a0e

File tree

4 files changed

+42
-77
lines changed

4 files changed

+42
-77
lines changed

spec/ParseAPI.spec.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let defaultColumns = require('../src/Controllers/SchemaController').defaultColum
1010

1111
const requiredUserFields = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._User) };
1212

13-
1413
fdescribe('miscellaneous', function() {
1514
it('create a GameScore object', function(done) {
1615
var obj = new Parse.Object('GameScore');
@@ -50,37 +49,40 @@ fdescribe('miscellaneous', function() {
5049
});
5150

5251
it('fail to create a duplicate username', done => {
53-
let numCreated = 0;
54-
let numFailed = 0;
55-
let p1 = createTestUser();
56-
p1.then(user => {
57-
numCreated++;
58-
expect(numCreated).toEqual(1);
59-
})
60-
.catch(error => {
61-
numFailed++;
62-
expect(numFailed).toEqual(1);
63-
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
64-
});
65-
let p2 = createTestUser();
66-
p2.then(user => {
67-
numCreated++;
68-
expect(numCreated).toEqual(1);
69-
})
70-
.catch(error => {
71-
numFailed++;
72-
expect(numFailed).toEqual(1);
73-
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
74-
});
75-
Parse.Promise.all([p1, p2])
52+
DatabaseAdapter._indexBuildsCompleted('test')
7653
.then(() => {
77-
fail('one of the users should not have been created');
78-
done();
79-
})
80-
.catch(done);
54+
let numCreated = 0;
55+
let numFailed = 0;
56+
let p1 = createTestUser();
57+
p1.then(user => {
58+
numCreated++;
59+
expect(numCreated).toEqual(1);
60+
})
61+
.catch(error => {
62+
numFailed++;
63+
expect(numFailed).toEqual(1);
64+
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
65+
});
66+
let p2 = createTestUser();
67+
p2.then(user => {
68+
numCreated++;
69+
expect(numCreated).toEqual(1);
70+
})
71+
.catch(error => {
72+
numFailed++;
73+
expect(numFailed).toEqual(1);
74+
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
75+
});
76+
Parse.Promise.all([p1, p2])
77+
.then(() => {
78+
fail('one of the users should not have been created');
79+
done();
80+
})
81+
.catch(done);
82+
});
8183
});
8284

83-
fit('ensure that email is uniquely indexed', done => {
85+
it('ensure that email is uniquely indexed', done => {
8486
DatabaseAdapter._indexBuildsCompleted('test')
8587
.then(() => {
8688
let numCreated = 0;
@@ -96,7 +98,6 @@ fdescribe('miscellaneous', function() {
9698
expect(numCreated).toEqual(1);
9799
}, error => {
98100
numFailed++;
99-
console.log(error);
100101
expect(numFailed).toEqual(1);
101102
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
102103
});
@@ -111,7 +112,6 @@ fdescribe('miscellaneous', function() {
111112
expect(numCreated).toEqual(1);
112113
}, error => {
113114
numFailed++;
114-
console.log(error);
115115
expect(numFailed).toEqual(1);
116116
expect(error.code).toEqual(Parse.Error.EMAIL_TAKEN);
117117
});

spec/helper.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ var currentConfiguration;
5656
// Allows testing specific configurations of Parse Server
5757
const setServerConfiguration = configuration => {
5858
// the configuration hasn't changed
59-
if (configuration === currentConfiguration) {
60-
return;
61-
}
6259
DatabaseAdapter.clearDatabaseSettings();
6360
currentConfiguration = configuration;
6461
server.close();
@@ -80,11 +77,14 @@ Parse.serverURL = 'http://localhost:' + port + '/1';
8077
Parse.Promise.disableAPlusCompliant();
8178

8279
beforeEach(function(done) {
83-
restoreServerConfiguration();
84-
Parse.initialize('test', 'test', 'test');
85-
Parse.serverURL = 'http://localhost:' + port + '/1';
86-
Parse.User.enableUnsafeCurrentUser();
87-
return TestUtils.destroyAllDataPermanently().then(done, fail);
80+
TestUtils.destroyAllDataPermanently()
81+
.then(() => {
82+
restoreServerConfiguration();
83+
Parse.initialize('test', 'test', 'test');
84+
Parse.serverURL = 'http://localhost:' + port + '/1';
85+
Parse.User.enableUnsafeCurrentUser();
86+
done();
87+
}, fail)
8888
});
8989

9090
var mongoAdapter = new MongoStorageAdapter({
@@ -111,7 +111,7 @@ afterEach(function(done) {
111111
})
112112
.then(() => Parse.User.logOut())
113113
.then(() => {
114-
//return TestUtils.destroyAllDataPermanently();
114+
return TestUtils.destroyAllDataPermanently();
115115
}).then(() => {
116116
done();
117117
}, (error) => {

src/DatabaseAdapter.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function clearDatabaseSettings() {
4141
appDatabaseURIs = {};
4242
dbConnections = {};
4343
appDatabaseOptions = {};
44+
indexBuildCreationPromises = {};
4445
}
4546

4647
//Used by tests
@@ -87,42 +88,7 @@ function getDatabaseConnection(appId: string, collectionPrefix: string) {
8788
return Promise.reject();
8889
})
8990

90-
indexBuildCreationPromises[appId] = p1.then(() => p2)
91-
.then(() => console.log('index build success'))
92-
.then(() => {
93-
let numCreated = 0;
94-
let numFailed = 0;
95-
96-
let user1 = new Parse.User();
97-
user1.setPassword('asdf');
98-
user1.setUsername('u1');
99-
user1.setEmail('[email protected]');
100-
let p1 = user1.signUp();
101-
p1.then(user => {
102-
numCreated++;
103-
console.log(numCreated)
104-
}, error => {
105-
numFailed++;
106-
console.log(error);
107-
console.log(numFailed)
108-
console.log(error.code)
109-
});
110-
111-
let user2 = new Parse.User();
112-
user2.setPassword('asdf');
113-
user2.setUsername('u2');
114-
user2.setEmail('[email protected]');
115-
let p2 = user2.signUp();
116-
p2.then(user => {
117-
numCreated++;
118-
console.log(numCreated)
119-
}, error => {
120-
numFailed++;
121-
console.log(error);
122-
console.log(numFailed)
123-
console.log(error.code)
124-
});
125-
})
91+
indexBuildCreationPromises[appId] = Promise.all([p1, p2])
12692

12793
return dbConnections[appId];
12894
}

src/middlewares.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ var handleParseErrors = function(err, req, res, next) {
235235
}
236236

237237
res.status(httpStatus);
238-
console.log(err);
239238
res.json({code: err.code, error: err.message});
240239
} else if (err.status && err.message) {
241240
res.status(err.status);

0 commit comments

Comments
 (0)