|
1 | 1 | var Parse = require('parse/node').Parse;
|
2 | 2 | var request = require('request');
|
3 | 3 | var dd = require('deep-diff');
|
| 4 | +var Config = require('../src/Config'); |
| 5 | + |
| 6 | +var config = new Config('test'); |
4 | 7 |
|
5 | 8 | var hasAllPODobject = () => {
|
6 | 9 | var obj = new Parse.Object('HasAllPOD');
|
@@ -633,4 +636,102 @@ describe('schemas', () => {
|
633 | 636 | });
|
634 | 637 | });
|
635 | 638 | });
|
| 639 | + |
| 640 | + it('requires the master key to delete schemas', done => { |
| 641 | + request.del({ |
| 642 | + url: 'http://localhost:8378/1/schemas/DoesntMatter', |
| 643 | + headers: noAuthHeaders, |
| 644 | + json: true, |
| 645 | + }, (error, response, body) => { |
| 646 | + expect(response.statusCode).toEqual(403); |
| 647 | + expect(body.error).toEqual('unauthorized'); |
| 648 | + done(); |
| 649 | + }); |
| 650 | + }); |
| 651 | + |
| 652 | + it('refuses to delete non-empty collection', done => { |
| 653 | + var obj = hasAllPODobject(); |
| 654 | + obj.save() |
| 655 | + .then(() => { |
| 656 | + request.del({ |
| 657 | + url: 'http://localhost:8378/1/schemas/HasAllPOD', |
| 658 | + headers: masterKeyHeaders, |
| 659 | + json: true, |
| 660 | + }, (error, response, body) => { |
| 661 | + expect(response.statusCode).toEqual(400); |
| 662 | + expect(body.code).toEqual(255); |
| 663 | + expect(body.error).toEqual('class HasAllPOD not empty, contains 1 objects, cannot drop schema'); |
| 664 | + done(); |
| 665 | + }); |
| 666 | + }); |
| 667 | + }); |
| 668 | + |
| 669 | + it('fails when deleting collections with invalid class names', done => { |
| 670 | + request.del({ |
| 671 | + url: 'http://localhost:8378/1/schemas/_GlobalConfig', |
| 672 | + headers: masterKeyHeaders, |
| 673 | + json: true, |
| 674 | + }, (error, response, body) => { |
| 675 | + expect(response.statusCode).toEqual(400); |
| 676 | + expect(body.code).toEqual(Parse.Error.INVALID_CLASS_NAME); |
| 677 | + expect(body.error).toEqual('Invalid classname: _GlobalConfig, classnames can only have alphanumeric characters and _, and must start with an alpha character '); |
| 678 | + done(); |
| 679 | + }) |
| 680 | + }); |
| 681 | + |
| 682 | + it('does not fail when deleting nonexistant collections', done => { |
| 683 | + request.del({ |
| 684 | + url: 'http://localhost:8378/1/schemas/Missing', |
| 685 | + headers: masterKeyHeaders, |
| 686 | + json: true, |
| 687 | + }, (error, response, body) => { |
| 688 | + expect(response.statusCode).toEqual(200); |
| 689 | + expect(body).toEqual({}); |
| 690 | + done(); |
| 691 | + }); |
| 692 | + }); |
| 693 | + |
| 694 | + it('deletes collections including join tables', done => { |
| 695 | + var obj = new Parse.Object('MyClass'); |
| 696 | + obj.set('data', 'data'); |
| 697 | + obj.save() |
| 698 | + .then(() => { |
| 699 | + var obj2 = new Parse.Object('MyOtherClass'); |
| 700 | + var relation = obj2.relation('aRelation'); |
| 701 | + relation.add(obj); |
| 702 | + return obj2.save(); |
| 703 | + }) |
| 704 | + .then(obj2 => obj2.destroy()) |
| 705 | + .then(() => { |
| 706 | + request.del({ |
| 707 | + url: 'http://localhost:8378/1/schemas/MyOtherClass', |
| 708 | + headers: masterKeyHeaders, |
| 709 | + json: true, |
| 710 | + }, (error, response, body) => { |
| 711 | + expect(response.statusCode).toEqual(200); |
| 712 | + expect(response.body).toEqual({}); |
| 713 | + config.database.db.collection('test__Join:aRelation:MyOtherClass', { strict: true }, (err, coll) => { |
| 714 | + //Expect Join table to be gone |
| 715 | + expect(err).not.toEqual(null); |
| 716 | + config.database.db.collection('test_MyOtherClass', { strict: true }, (err, coll) => { |
| 717 | + // Expect data table to be gone |
| 718 | + expect(err).not.toEqual(null); |
| 719 | + request.get({ |
| 720 | + url: 'http://localhost:8378/1/schemas/MyOtherClass', |
| 721 | + headers: masterKeyHeaders, |
| 722 | + json: true, |
| 723 | + }, (error, response, body) => { |
| 724 | + //Expect _SCHEMA entry to be gone. |
| 725 | + expect(response.statusCode).toEqual(400); |
| 726 | + expect(body.code).toEqual(Parse.Error.INVALID_CLASS_NAME); |
| 727 | + expect(body.error).toEqual('class MyOtherClass does not exist'); |
| 728 | + done(); |
| 729 | + }); |
| 730 | + }); |
| 731 | + }); |
| 732 | + }); |
| 733 | + }, error => { |
| 734 | + fail(error); |
| 735 | + }); |
| 736 | + }); |
636 | 737 | });
|
0 commit comments