GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — parse-server/spec/Schema.spec.js at master · cs8/parse-server Expand file tree/ Copy pathSchema.spec.jsMore file actions 797 lines (752 loc) · 25.1 KB / Copy pathSchema.spec.jsFile metadata and controls797 lines (752 loc) · 25.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 'use strict'; var Config = require('../src/Config'); var Schema = require('../src/Schema'); var dd = require('deep-diff'); var config = new Config('test'); var hasAllPODobject = () => { var obj = new Parse.Object('HasAllPOD'); obj.set('aNumber', 5); obj.set('aString', 'string'); obj.set('aBool', true); obj.set('aDate', new Date()); obj.set('aObject', {k1: 'value', k2: true, k3: 5}); obj.set('aArray', ['contents', true, 5]); obj.set('aGeoPoint', new Parse.GeoPoint({latitude: 0, longitude: 0})); obj.set('aFile', new Parse.File('f.txt', { base64: 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=' })); return obj; }; describe('Schema', () => { it('can validate one object', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('TestObject', {a: 1, b: 'yo', c: false}); }).then((schema) => { done(); }, (error) => { fail(error); done(); }); }); it('can validate one object with dot notation', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('TestObjectWithSubDoc', {x: false, y: 'YY', z: 1, 'aObject.k1': 'newValue'}); }).then((schema) => { done(); }, (error) => { fail(error); done(); }); }); it('can validate two objects in a row', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('Foo', {x: true, y: 'yyy', z: 0}); }).then((schema) => { return schema.validateObject('Foo', {x: false, y: 'YY', z: 1}); }).then((schema) => { done(); }); }); it('rejects inconsistent types', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('Stuff', {bacon: 7}); }).then((schema) => { return schema.validateObject('Stuff', {bacon: 'z'}); }).then(() => { fail('expected invalidity'); done(); }, done); }); it('updates when new fields are added', (done) => { config.database.loadSchema().then((schema) => { return schema.validateObject('Stuff', {bacon: 7}); }).then((schema) => { return schema.validateObject('Stuff', {sausage: 8}); }).then((schema) => { return schema.validateObject('Stuff', {sausage: 'ate'}); }).then(() => { fail('expected invalidity'); done(); }, done); }); it('class-level permissions test find', (done) => { config.database.loadSchema().then((schema) => { // Just to create a valid class return schema.validateObject('Stuff', {foo: 'bar'}); }).then((schema) => { return schema.setPermissions('Stuff', { 'find': {} }); }).then((schema) => { var query = new Parse.Query('Stuff'); return query.find(); }).then((results) => { fail('Class permissions should have rejected this query.'); done(); }, (e) => { done(); }); }); it('class-level permissions test user', (done) => { var user; createTestUser().then((u) => { user = u; return config.database.loadSchema(); }).then((schema) => { // Just to create a valid class return schema.validateObject('Stuff', {foo: 'bar'}); }).then((schema) => { var find = {}; find[user.id] = true; return schema.setPermissions('Stuff', { 'find': find }); }).then((schema) => { var query = new Parse.Query('Stuff'); return query.find(); }).then((results) => { done(); }, (e) => { fail('Class permissions should have allowed this query.'); done(); }); }); it('class-level permissions test get', (done) => { var user; var obj; createTestUser().then((u) => { user = u; return config.database.loadSchema(); }).then((schema) => { // Just to create a valid class return schema.validateObject('Stuff', {foo: 'bar'}); }).then((schema) => { var find = {}; var get = {}; get[user.id] = true; return schema.setPermissions('Stuff', { 'find': find, 'get': get }); }).then((schema) => { obj = new Parse.Object('Stuff'); obj.set('foo', 'bar'); return obj.save(); }).then((o) => { obj = o; var query = new Parse.Query('Stuff'); return query.find(); }).then((results) => { fail('Class permissions should have rejected this query.'); done(); }, (e) => { var query = new Parse.Query('Stuff'); return query.get(obj.id).then((o) => { done(); }, (e) => { fail('Class permissions should have allowed this get query'); }); }); }); it('can add classes without needing an object', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'String'} })) .then(actualSchema => { const expectedSchema = { className: 'NewClass', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, foo: { type: 'String' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, } expect(dd(actualSchema, expectedSchema)).toEqual(undefined); done(); }) .catch(error => { fail('Error creating class: ' + JSON.stringify(error)); }); }); it('will fail to create a class if that class was already created by an object', done => { config.database.loadSchema() .then(schema => { schema.validateObject('NewClass', { foo: 7 }) .then(() => schema.reloadData()) .then(() => schema.addClassIfNotExists('NewClass', { foo: { type: 'String' } })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); expect(error.message).toEqual('Class NewClass already exists.'); done(); }); }); }); it('will resolve class creation races appropriately', done => { // If two callers race to create the same schema, the response to the // race loser should be the same as if they hadn't been racing. config.database.loadSchema() .then(schema => { var p1 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}}); var p2 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}}); Promise.race([p1, p2]) .then(actualSchema => { const expectedSchema = { className: 'NewClass', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, foo: { type: 'String' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, } expect(dd(actualSchema, expectedSchema)).toEqual(undefined); }); Promise.all([p1,p2]) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); expect(error.message).toEqual('Class NewClass already exists.'); done(); }); }); }); it('refuses to create classes with invalid names', done => { config.database.loadSchema() .then(schema => { schema.addClassIfNotExists('_InvalidName', {foo: {type: 'String'}}) .catch(error => { expect(error.error).toEqual( 'Invalid classname: _InvalidName, classnames can only have alphanumeric characters and _, and must start with an alpha character ' ); done(); }); }); }); it('refuses to add fields with invalid names', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', {'0InvalidName': {type: 'String'}})) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_KEY_NAME); expect(error.error).toEqual('invalid field name: 0InvalidName'); done(); }); }); it('refuses to explicitly create the default fields for custom classes', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', {objectId: {type: 'String'}})) .catch(error => { expect(error.code).toEqual(136); expect(error.error).toEqual('field objectId cannot be added'); done(); }); }); it('refuses to explicitly create the default fields for non-custom classes', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('_Installation', {localeIdentifier: {type: 'String'}})) .catch(error => { expect(error.code).toEqual(136); expect(error.error).toEqual('field localeIdentifier cannot be added'); done(); }); }); it('refuses to add fields with invalid types', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 7} })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_JSON); expect(error.error).toEqual('invalid JSON'); done(); }); }); it('refuses to add fields with invalid pointer types', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Pointer'} })) .catch(error => { expect(error.code).toEqual(135); expect(error.error).toEqual('type Pointer needs a class name'); done(); }); }); it('refuses to add fields with invalid pointer target', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Pointer', targetClass: 7}, })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_JSON); expect(error.error).toEqual('invalid JSON'); done(); }); }); it('refuses to add fields with invalid Relation type', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Relation', uselessKey: 7}, })) .catch(error => { expect(error.code).toEqual(135); expect(error.error).toEqual('type Relation needs a class name'); done(); }); }); it('refuses to add fields with invalid relation target', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Relation', targetClass: 7}, })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_JSON); expect(error.error).toEqual('invalid JSON'); done(); }); }); it('refuses to add fields with uncreatable pointer target class', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Pointer', targetClass: 'not a valid class name'}, })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); expect(error.error).toEqual('Invalid classname: not a valid class name, classnames can only have alphanumeric characters and _, and must start with an alpha character '); done(); }); }); it('refuses to add fields with uncreatable relation target class', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Relation', targetClass: 'not a valid class name'}, })) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); expect(error.error).toEqual('Invalid classname: not a valid class name, classnames can only have alphanumeric characters and _, and must start with an alpha character '); done(); }); }); it('refuses to add fields with unknown types', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { foo: {type: 'Unknown'}, })) .catch(error => { expect(error.code).toEqual(Parse.Error.INCORRECT_TYPE); expect(error.error).toEqual('invalid field type: Unknown'); done(); }); }); it('will create classes', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { aNumber: {type: 'Number'}, aString: {type: 'String'}, aBool: {type: 'Boolean'}, aDate: {type: 'Date'}, aObject: {type: 'Object'}, aArray: {type: 'Array'}, aGeoPoint: {type: 'GeoPoint'}, aFile: {type: 'File'}, aPointer: {type: 'Pointer', targetClass: 'ThisClassDoesNotExistYet'}, aRelation: {type: 'Relation', targetClass: 'NewClass'}, })) .then(actualSchema => { const expectedSchema = { className: 'NewClass', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, aString: { type: 'String' }, aNumber: { type: 'Number' }, aString: { type: 'String' }, aBool: { type: 'Boolean' }, aDate: { type: 'Date' }, aObject: { type: 'Object' }, aArray: { type: 'Array' }, aGeoPoint: { type: 'GeoPoint' }, aFile: { type: 'File' }, aPointer: { type: 'Pointer', targetClass: 'ThisClassDoesNotExistYet' }, aRelation: { type: 'Relation', targetClass: 'NewClass' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, } expect(dd(actualSchema, expectedSchema)).toEqual(undefined); done(); }); }); it('creates the default fields for non-custom classes', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('_Installation', { foo: {type: 'Number'}, })) .then(actualSchema => { const expectedSchema = { className: '_Installation', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, foo: { type: 'Number' }, installationId: { type: 'String' }, deviceToken: { type: 'String' }, channels: { type: 'Array' }, deviceType: { type: 'String' }, pushType: { type: 'String' }, GCMSenderId: { type: 'String' }, timeZone: { type: 'String' }, localeIdentifier: { type: 'String' }, badge: { type: 'Number' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, } expect(dd(actualSchema, expectedSchema)).toEqual(undefined); done(); }); }); it('creates non-custom classes which include relation field', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('_Role', {})) .then(actualSchema => { const expectedSchema = { className: '_Role', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, name: { type: 'String' }, users: { type: 'Relation', targetClass: '_User' }, roles: { type: 'Relation', targetClass: '_Role' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, }; expect(dd(actualSchema, expectedSchema)).toEqual(undefined); done(); }); }); it('creates non-custom classes which include pointer field', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('_Session', {})) .then(actualSchema => { const expectedSchema = { className: '_Session', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, restricted: { type: 'Boolean' }, user: { type: 'Pointer', targetClass: '_User' }, installationId: { type: 'String' }, sessionToken: { type: 'String' }, expiresAt: { type: 'Date' }, createdWith: { type: 'Object' }, ACL: { type: 'ACL' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, }; expect(dd(actualSchema, expectedSchema)).toEqual(undefined); done(); }); }); it('refuses to create two geopoints', done => { config.database.loadSchema() .then(schema => schema.addClassIfNotExists('NewClass', { geo1: {type: 'GeoPoint'}, geo2: {type: 'GeoPoint'} })) .catch(error => { expect(error.code).toEqual(Parse.Error.INCORRECT_TYPE); expect(error.error).toEqual('currently, only one GeoPoint field may exist in an object. Adding geo2 when geo1 already exists.'); done(); }); }); it('can check if a class exists', done => { config.database.loadSchema() .then(schema => { return schema.addClassIfNotExists('NewClass', {}) .then(() => { schema.hasClass('NewClass') .then(hasClass => { expect(hasClass).toEqual(true); done(); }) .catch(fail); schema.hasClass('NonexistantClass') .then(hasClass => { expect(hasClass).toEqual(false); done(); }) .catch(fail); }) .catch(error => { fail('Couldn\'t create class'); fail(error); }); }) .catch(error => fail('Couldn\'t load schema')); }); it('refuses to delete fields from invalid class names', done => { config.database.loadSchema() .then(schema => schema.deleteField('fieldName', 'invalid class name')) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); done(); }); }); it('refuses to delete invalid fields', done => { config.database.loadSchema() .then(schema => schema.deleteField('invalid field name', 'ValidClassName')) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_KEY_NAME); done(); }); }); it('refuses to delete the default fields', done => { config.database.loadSchema() .then(schema => schema.deleteField('installationId', '_Installation')) .catch(error => { expect(error.code).toEqual(136); expect(error.message).toEqual('field installationId cannot be changed'); done(); }); }); it('refuses to delete fields from nonexistant classes', done => { config.database.loadSchema() .then(schema => schema.deleteField('field', 'NoClass')) .catch(error => { expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); expect(error.message).toEqual('Class NoClass does not exist.'); done(); }); }); it('refuses to delete fields that dont exist', done => { hasAllPODobject().save() .then(() => config.database.loadSchema()) .then(schema => schema.deleteField('missingField', 'HasAllPOD')) .fail(error => { expect(error.code).toEqual(255); expect(error.message).toEqual('Field missingField does not exist, cannot delete.'); done(); }); }); it('drops related collection when deleting relation field', done => { var obj1 = hasAllPODobject(); obj1.save() .then(savedObj1 => { var obj2 = new Parse.Object('HasPointersAndRelations'); obj2.set('aPointer', savedObj1); var relation = obj2.relation('aRelation'); relation.add(obj1); return obj2.save(); }) .then(() => config.database.collectionExists('_Join:aRelation:HasPointersAndRelations')) .then(exists => { if (!exists) { fail('Relation collection ' + 'should exist after save.'); } }) .then(() => config.database.loadSchema()) .then(schema => schema.deleteField('aRelation', 'HasPointersAndRelations', config.database)) .then(() => config.database.collectionExists('_Join:aRelation:HasPointersAndRelations')) .then(exists => { if (exists) { fail('Relation collection should not exist after deleting relation field.'); } done(); }, error => { fail(error); done(); }); }); it('can delete relation field when related _Join collection not exist', done => { config.database.loadSchema() .then(schema => { schema.addClassIfNotExists('NewClass', { relationField: {type: 'Relation', targetClass: '_User'} }) .then(actualSchema => { const expectedSchema = { className: 'NewClass', fields: { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' }, relationField: { type: 'Relation', targetClass: '_User' }, }, classLevelPermissions: { find: { '*': true }, get: { '*': true }, create: { '*': true }, update: { '*': true }, delete: { '*': true }, addField: { '*': true }, }, }; expect(dd(actualSchema, expectedSchema)).toEqual(undefined); }) .then(() => config.database.collectionExists('_Join:relationField:NewClass')) .then(exist => { expect(exist).toEqual(false); }) .then(() => schema.deleteField('relationField', 'NewClass', config.database)) .then(() => schema.reloadData()) .then(() => { const expectedSchema = { objectId: { type: 'String' }, updatedAt: { type: 'Date' }, createdAt: { type: 'Date' }, ACL: { type: 'ACL' } }; expect(dd(schema.data.NewClass, expectedSchema)).toEqual(undefined); done(); }); }); }); it('can delete string fields and resave as number field', done => { Parse.Object.disableSingleInstance(); var obj1 = hasAllPODobject(); var obj2 = hasAllPODobject(); var p = Parse.Object.saveAll([obj1, obj2]) .then(() => config.database.loadSchema()) .then(schema => schema.deleteField('aString', 'HasAllPOD', config.database)) .then(() => new Parse.Query('HasAllPOD').get(obj1.id)) .then(obj1Reloaded => { expect(obj1Reloaded.get('aString')).toEqual(undefined); obj1Reloaded.set('aString', ['not a string', 'this time']); obj1Reloaded.save() .then(obj1reloadedAgain => { expect(obj1reloadedAgain.get('aString')).toEqual(['not a string', 'this time']); return new Parse.Query('HasAllPOD').get(obj2.id); }) .then(obj2reloaded => { expect(obj2reloaded.get('aString')).toEqual(undefined); done(); Parse.Object.enableSingleInstance(); }); }) .catch(error => { fail(error); done(); }); }); it('can delete pointer fields and resave as string', done => { Parse.Object.disableSingleInstance(); var obj1 = new Parse.Object('NewClass'); obj1.save() .then(() => { obj1.set('aPointer', obj1); return obj1.save(); }) .then(obj1 => { expect(obj1.get('aPointer').id).toEqual(obj1.id); }) .then(() => config.database.loadSchema()) .then(schema => schema.deleteField('aPointer', 'NewClass', config.database)) .then(() => new Parse.Query('NewClass').get(obj1.id)) .then(obj1 => { expect(obj1.get('aPointer')).toEqual(undefined); obj1.set('aPointer', 'Now a string'); return obj1.save(); }) .then(obj1 => { expect(obj1.get('aPointer')).toEqual('Now a string'); done(); Parse.Object.enableSingleInstance(); }); }); it('can merge schemas', done => { expect(Schema.buildMergedSchemaObject({ _id: 'SomeClass', someType: { type: 'Number' } }, { newType: {type: 'Number'} })).toEqual({ someType: {type: 'Number'}, newType: {type: 'Number'}, }); done(); }); it('can merge deletions', done => { expect(Schema.buildMergedSchemaObject({ _id: 'SomeClass', someType: { type: 'Number' }, outDatedType: { type: 'String' }, },{ newType: {type: 'GeoPoint'}, outDatedType: {__op: 'Delete'}, })).toEqual({ someType: {type: 'Number'}, newType: {type: 'GeoPoint'}, }); done(); }); it('ignore default field when merge with system class', done => { expect(Schema.buildMergedSchemaObject({ _id: '_User', username: { type: 'String' }, password: { type: 'String' }, authData: { type: 'Object' }, email: { type: 'String' }, emailVerified: { type: 'Boolean' }, },{ authData: { type: 'String' }, customField: { type: 'String' }, })).toEqual({ customField: { type: 'String' } }); done(); }); }); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |