|
1 | | -// These tests check that the Schema operates correctly. |
2 | 1 | var Config = require('../src/Config'); |
3 | 2 | var Schema = require('../src/Schema'); |
4 | 3 | var dd = require('deep-diff'); |
@@ -406,4 +405,60 @@ describe('Schema', () => { |
406 | 405 | done(); |
407 | 406 | }); |
408 | 407 | }); |
| 408 | + |
| 409 | + it('can check if a class exists', done => { |
| 410 | + config.database.loadSchema() |
| 411 | + .then(schema => { |
| 412 | + return schema.addClassIfNotExists('NewClass', {}) |
| 413 | + .then(() => { |
| 414 | + console.log(Object.getPrototypeOf(schema)); |
| 415 | + schema.hasClass('NewClass') |
| 416 | + .then(hasClass => { |
| 417 | + expect(hasClass).toEqual(true); |
| 418 | + done(); |
| 419 | + }) |
| 420 | + .catch(fail); |
| 421 | + |
| 422 | + schema.hasClass('NonexistantClass') |
| 423 | + .then(hasClass => { |
| 424 | + expect(hasClass).toEqual(false); |
| 425 | + done(); |
| 426 | + }) |
| 427 | + .catch(fail); |
| 428 | + }) |
| 429 | + .catch(error => { |
| 430 | + fail('Couldn\'t create class'); |
| 431 | + fail(error); |
| 432 | + }); |
| 433 | + }) |
| 434 | + .catch(error => fail('Couldn\'t load schema')); |
| 435 | + }); |
| 436 | + |
| 437 | + it('refuses to delete fields from invalid class names', done => { |
| 438 | + config.database.loadSchema() |
| 439 | + .then(schema => schema.deleteField('fieldName', 'invalid class name')) |
| 440 | + .catch(error => { |
| 441 | + expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME); |
| 442 | + done(); |
| 443 | + }); |
| 444 | + }); |
| 445 | + |
| 446 | + it('refuses to delete invalid fields', done => { |
| 447 | + config.database.loadSchema() |
| 448 | + .then(schema => schema.deleteField('invalid field name', 'ValidClassName')) |
| 449 | + .catch(error => { |
| 450 | + expect(error.code).toEqual(Parse.Error.INVALID_KEY_NAME); |
| 451 | + done(); |
| 452 | + }); |
| 453 | + }); |
| 454 | + |
| 455 | + it('refuses to delete the default fields', done => { |
| 456 | + config.database.loadSchema() |
| 457 | + .then(schema => schema.deleteField('installationId', '_Installation')) |
| 458 | + .catch(error => { |
| 459 | + expect(error.code).toEqual(136); |
| 460 | + expect(error.error).toEqual('field installationId cannot be changed'); |
| 461 | + done(); |
| 462 | + }); |
| 463 | + }); |
409 | 464 | }); |
0 commit comments