Skip to content

Commit 0ff35e1

Browse files
drew-grosspeterdotjs
authored andcommitted
Add more postgres support (#2080)
* reload the right data More passing postgres tests Handle schema updates, and $in for non array columns remove authdata from user and implement ensureUniqueness Make some tests work, detect existing classes Throw proper error for unique index violation * fix findOneAndUpdate
1 parent 1a75101 commit 0ff35e1

File tree

8 files changed

+194
-127
lines changed

8 files changed

+194
-127
lines changed

spec/ParseAPI.spec.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ var request = require('request');
88
const rp = require('request-promise');
99
const Parse = require("parse/node");
1010
let Config = require('../src/Config');
11-
let defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;
11+
const SchemaController = require('../src/Controllers/SchemaController');
1212
var TestUtils = require('../src/index').TestUtils;
13+
const deepcopy = require('deepcopy');
1314

14-
const requiredUserFields = { fields: Object.assign({}, defaultColumns._Default, defaultColumns._User) };
15+
const userSchema = SchemaController.convertSchemaToAdapterSchema({ className: '_User', fields: Object.assign({}, SchemaController.defaultColumns._Default, SchemaController.defaultColumns._User) });
1516

1617
describe('miscellaneous', function() {
1718
it('create a GameScore object', function(done) {
@@ -131,24 +132,27 @@ describe('miscellaneous', function() {
131132
let config = new Config('test');
132133
// Remove existing data to clear out unique index
133134
TestUtils.destroyAllDataPermanently()
134-
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', username: 'u' }))
135-
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', username: 'u' }))
135+
.then(() => config.database.adapter.createClass('_User', userSchema))
136+
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'x', username: 'u' }).catch(fail))
137+
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'y', username: 'u' }).catch(fail))
136138
// Create a new server to try to recreate the unique indexes
137139
.then(reconfigureServer)
138140
.catch(() => {
139141
let user = new Parse.User();
140142
user.setPassword('asdf');
141143
user.setUsername('zxcv');
142-
// Sign up with new email still works
143144
return user.signUp().catch(fail);
144145
})
145146
.then(() => {
146147
let user = new Parse.User();
147148
user.setPassword('asdf');
148149
user.setUsername('u');
149-
// sign up with duplicate username doens't
150150
return user.signUp()
151151
})
152+
.then(result => {
153+
fail('should not have been able to sign up');
154+
done();
155+
})
152156
.catch(error => {
153157
expect(error.code).toEqual(Parse.Error.USERNAME_TAKEN);
154158
done();
@@ -159,8 +163,9 @@ describe('miscellaneous', function() {
159163
let config = new Config('test');
160164
// Remove existing data to clear out unique index
161165
TestUtils.destroyAllDataPermanently()
162-
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'x', email: '[email protected]' }))
163-
.then(() => config.database.adapter.createObject('_User', requiredUserFields, { objectId: 'y', email: '[email protected]' }))
166+
.then(() => config.database.adapter.createClass('_User', userSchema))
167+
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'x', email: '[email protected]' }))
168+
.then(() => config.database.adapter.createObject('_User', userSchema, { objectId: 'y', email: '[email protected]' }))
164169
.then(reconfigureServer)
165170
.catch(() => {
166171
let user = new Parse.User();
@@ -184,7 +189,8 @@ describe('miscellaneous', function() {
184189

185190
it('ensure that if you try to sign up a user with a unique username and email, but duplicates in some other field that has a uniqueness constraint, you get a regular duplicate value error', done => {
186191
let config = new Config('test');
187-
config.database.adapter.ensureUniqueness('_User', requiredUserFields, ['randomField'])
192+
config.database.adapter.addFieldIfNotExists('_User', 'randomField', { type: 'String' })
193+
.then(() => config.database.adapter.ensureUniqueness('_User', userSchema, ['randomField']))
188194
.then(() => {
189195
let user = new Parse.User();
190196
user.setPassword('asdf');
@@ -277,7 +283,7 @@ describe('miscellaneous', function() {
277283
expect(results.length).toEqual(1);
278284
done();
279285
}, (error) => {
280-
fail(error);
286+
fail(JSON.stringify(error));
281287
done();
282288
});
283289
});
@@ -292,8 +298,8 @@ describe('miscellaneous', function() {
292298
}).then((results) => {
293299
expect(results.length).toEqual(100);
294300
done();
295-
}, (error) => {
296-
fail(error);
301+
}, error => {
302+
fail(JSON.stringify(error));
297303
done();
298304
});
299305
});
@@ -335,8 +341,8 @@ describe('miscellaneous', function() {
335341
fail(error);
336342
done();
337343
});
338-
}, function(error) {
339-
fail(error);
344+
}, error => {
345+
fail(JSON.stringify(error));
340346
done();
341347
});
342348
});

spec/Schema.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,11 +788,10 @@ describe('SchemaController', () => {
788788
_id: '_User',
789789
username: { type: 'String' },
790790
password: { type: 'String' },
791-
authData: { type: 'Object' },
792791
email: { type: 'String' },
793792
emailVerified: { type: 'Boolean' },
794793
},{
795-
authData: { type: 'String' },
794+
emailVerified: { type: 'String' },
796795
customField: { type: 'String' },
797796
})).toEqual({
798797
customField: { type: 'String' }

spec/schemas.spec.js

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ var pointersAndRelationsSchema = {
8686
classLevelPermissions: defaultClassLevelPermissions
8787
}
8888

89+
const userSchema = {
90+
"className": "_User",
91+
"fields": {
92+
"objectId": {"type": "String"},
93+
"createdAt": {"type": "Date"},
94+
"updatedAt": {"type": "Date"},
95+
"ACL": {"type": "ACL"},
96+
"username": {"type": "String"},
97+
"password": {"type": "String"},
98+
"email": {"type": "String"},
99+
"emailVerified": {"type": "Boolean"}
100+
},
101+
"classLevelPermissions": defaultClassLevelPermissions,
102+
}
103+
89104
var noAuthHeaders = {
90105
'X-Parse-Application-Id': 'test',
91106
};
@@ -139,13 +154,13 @@ describe('schemas', () => {
139154
});
140155
});
141156

142-
it('responds with empty list when there are no schemas', done => {
157+
it('creates _User schema when server starts', done => {
143158
request.get({
144159
url: 'http://localhost:8378/1/schemas',
145160
json: true,
146161
headers: masterKeyHeaders,
147162
}, (error, response, body) => {
148-
expect(body.results).toEqual([]);
163+
expect(dd(body.results, [userSchema])).toEqual();
149164
done();
150165
});
151166
});
@@ -165,9 +180,9 @@ describe('schemas', () => {
165180
headers: masterKeyHeaders,
166181
}, (error, response, body) => {
167182
var expected = {
168-
results: [plainOldDataSchema,pointersAndRelationsSchema]
183+
results: [userSchema,plainOldDataSchema,pointersAndRelationsSchema]
169184
};
170-
expect(body).toEqual(expected);
185+
expect(dd(body, expected)).toEqual(undefined);
171186
done();
172187
})
173188
});
@@ -328,31 +343,43 @@ describe('schemas', () => {
328343

329344
it('responds with all fields when getting incomplete schema', done => {
330345
config.database.loadSchema()
331-
.then(schemaController => schemaController.addClassIfNotExists('_User', {}, defaultClassLevelPermissions))
346+
.then(schemaController => schemaController.addClassIfNotExists('_Installation', {}, defaultClassLevelPermissions))
332347
.then(() => {
333348
request.get({
334-
url: 'http://localhost:8378/1/schemas/_User',
349+
url: 'http://localhost:8378/1/schemas/_Installation',
335350
headers: masterKeyHeaders,
336351
json: true
337352
}, (error, response, body) => {
338-
expect(body).toEqual({
339-
className: '_User',
353+
expect(dd(body,{
354+
className: '_Installation',
340355
fields: {
341356
objectId: {type: 'String'},
342357
updatedAt: {type: 'Date'},
343358
createdAt: {type: 'Date'},
344-
username: {type: 'String'},
345-
password: {type: 'String'},
346-
authData: {type: 'Object'},
347-
email: {type: 'String'},
348-
emailVerified: {type: 'Boolean'},
359+
installationId: {type: 'String'},
360+
deviceToken: {type: 'String'},
361+
channels: {type: 'Array'},
362+
deviceType: {type: 'String'},
363+
pushType: {type: 'String'},
364+
GCMSenderId: {type: 'String'},
365+
timeZone: {type: 'String'},
366+
badge: {type: 'Number'},
367+
appIdentifier: {type: 'String'},
368+
localeIdentifier: {type: 'String'},
369+
appVersion: {type: 'String'},
370+
appName: {type: 'String'},
371+
parseVersion: {type: 'String'},
349372
ACL: {type: 'ACL'}
350373
},
351374
classLevelPermissions: defaultClassLevelPermissions
352-
});
375+
})).toBeUndefined();
353376
done();
354377
});
355378
})
379+
.catch(error => {
380+
fail(JSON.stringify(error))
381+
done();
382+
});
356383
});
357384

358385
it('lets you specify class name in both places', done => {
@@ -634,43 +661,41 @@ describe('schemas', () => {
634661
}
635662
}
636663
}, (error, response, body) => {
637-
expect(body).toEqual({
664+
expect(dd(body,{
638665
className: '_User',
639666
fields: {
640667
objectId: {type: 'String'},
641668
updatedAt: {type: 'Date'},
642669
createdAt: {type: 'Date'},
643670
username: {type: 'String'},
644671
password: {type: 'String'},
645-
authData: {type: 'Object'},
646672
email: {type: 'String'},
647673
emailVerified: {type: 'Boolean'},
648674
newField: {type: 'String'},
649675
ACL: {type: 'ACL'}
650676
},
651677
classLevelPermissions: defaultClassLevelPermissions
652-
});
678+
})).toBeUndefined();
653679
request.get({
654680
url: 'http://localhost:8378/1/schemas/_User',
655681
headers: masterKeyHeaders,
656682
json: true
657683
}, (error, response, body) => {
658-
expect(body).toEqual({
684+
expect(dd(body,{
659685
className: '_User',
660686
fields: {
661687
objectId: {type: 'String'},
662688
updatedAt: {type: 'Date'},
663689
createdAt: {type: 'Date'},
664690
username: {type: 'String'},
665691
password: {type: 'String'},
666-
authData: {type: 'Object'},
667692
email: {type: 'String'},
668693
emailVerified: {type: 'Boolean'},
669694
newField: {type: 'String'},
670695
ACL: {type: 'ACL'}
671696
},
672697
classLevelPermissions: defaultClassLevelPermissions
673-
});
698+
})).toBeUndefined();
674699
done();
675700
});
676701
});
@@ -1541,14 +1566,13 @@ describe('schemas', () => {
15411566
setPermissionsOnClass('_User', {
15421567
'create': {'*': true},
15431568
'addField': {}
1544-
}).then(() => {
1569+
}, true).then(() => {
15451570
return Parse.User.signUp('foo', 'bar');
15461571
}).then((user) => {
15471572
expect(user.getUsername()).toBe('foo');
15481573
done()
1549-
}, (err) => {
1550-
console.error(err);
1551-
fail('should create user');
1574+
}, error => {
1575+
fail(JSON.stringify(error));
15521576
done();
15531577
})
15541578
})

0 commit comments

Comments
 (0)