@@ -155,9 +155,11 @@ describe('Schema', () => {
155155 . then ( schema => {
156156 schema . validateObject ( 'NewClass' , { foo : 7 } )
157157 . then ( ( ) => {
158- schema . addClassIfNotExists ( 'NewClass' , {
158+ schema . reload ( )
159+ . then ( schema => schema . addClassIfNotExists ( 'NewClass' , {
159160 foo : { type : 'String' }
160- } ) . catch ( error => {
161+ } ) )
162+ . catch ( error => {
161163 expect ( error . code ) . toEqual ( Parse . Error . INVALID_CLASS_NAME )
162164 expect ( error . error ) . toEqual ( 'class NewClass already exists' ) ;
163165 done ( ) ;
@@ -223,7 +225,17 @@ describe('Schema', () => {
223225 } ) ;
224226 } ) ;
225227
226- it ( 'refuses to explicitly create the default fields' , done => {
228+ it ( 'refuses to explicitly create the default fields for custom classes' , done => {
229+ config . database . loadSchema ( )
230+ . then ( schema => schema . addClassIfNotExists ( 'NewClass' , { objectId : { type : 'String' } } ) )
231+ . catch ( error => {
232+ expect ( error . code ) . toEqual ( 136 ) ;
233+ expect ( error . error ) . toEqual ( 'field objectId cannot be added' ) ;
234+ done ( ) ;
235+ } ) ;
236+ } ) ;
237+
238+ it ( 'refuses to explicitly create the default fields for non-custom classes' , done => {
227239 config . database . loadSchema ( )
228240 . then ( schema => schema . addClassIfNotExists ( '_Installation' , { localeIdentifier : { type : 'String' } } ) )
229241 . catch ( error => {
@@ -317,6 +329,18 @@ describe('Schema', () => {
317329 } ) ;
318330 } ) ;
319331
332+ it ( 'refuses to add fields with unknown types' , done => {
333+ config . database . loadSchema ( )
334+ . then ( schema => schema . addClassIfNotExists ( 'NewClass' , {
335+ foo : { type : 'Unknown' } ,
336+ } ) )
337+ . catch ( error => {
338+ expect ( error . code ) . toEqual ( Parse . Error . INCORRECT_TYPE ) ;
339+ expect ( error . error ) . toEqual ( 'invalid field type: Unknown' ) ;
340+ done ( ) ;
341+ } ) ;
342+ } ) ;
343+
320344 it ( 'will create classes' , done => {
321345 config . database . loadSchema ( )
322346 . then ( schema => schema . addClassIfNotExists ( 'NewClass' , {
@@ -352,6 +376,32 @@ describe('Schema', () => {
352376 } ) ;
353377 } ) ;
354378
379+ it ( 'creates the default fields for non-custom classes' , done => {
380+ config . database . loadSchema ( )
381+ . then ( schema => schema . addClassIfNotExists ( '_Installation' , {
382+ foo : { type : 'Number' } ,
383+ } ) )
384+ . then ( mongoObj => {
385+ expect ( mongoObj ) . toEqual ( {
386+ _id : '_Installation' ,
387+ createdAt : 'string' ,
388+ updatedAt : 'string' ,
389+ objectId : 'string' ,
390+ foo : 'number' ,
391+ installationId : 'string' ,
392+ deviceToken : 'string' ,
393+ channels : 'array' ,
394+ deviceType : 'string' ,
395+ pushType : 'string' ,
396+ GCMSenderId : 'string' ,
397+ timeZone : 'string' ,
398+ localeIdentifier : 'string' ,
399+ badge : 'number' ,
400+ } ) ;
401+ done ( ) ;
402+ } ) ;
403+ } ) ;
404+
355405 it ( 'refuses to create two geopoints' , done => {
356406 config . database . loadSchema ( )
357407 . then ( schema => schema . addClassIfNotExists ( 'NewClass' , {
0 commit comments