2016-02-29 19:45:12 -08:00
'use strict' ;
2016-02-05 14:56:11 -08:00
var Parse = require ( 'parse/node' ) . Parse ;
2016-02-03 11:55:44 -08:00
var request = require ( 'request' ) ;
var dd = require ( 'deep-diff' ) ;
2016-02-17 19:00:17 -08:00
var Config = require ( '../src/Config' ) ;
var config = new Config ( 'test' ) ;
2016-02-05 14:56:11 -08:00
2016-02-03 16:10:00 -08:00
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=' } ) ) ;
var objACL = new Parse . ACL ( ) ;
objACL . setPublicWriteAccess ( false ) ;
obj . setACL ( objACL ) ;
return obj ;
2016-02-08 20:20:08 -08:00
} ;
2016-02-03 16:10:00 -08:00
2016-02-05 20:38:58 -08:00
var plainOldDataSchema = {
2016-02-03 16:10:00 -08:00
className : 'HasAllPOD' ,
fields : {
//Default fields
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
//Custom fields
aNumber : { type : 'Number' } ,
aString : { type : 'String' } ,
aBool : { type : 'Boolean' } ,
aDate : { type : 'Date' } ,
aObject : { type : 'Object' } ,
aArray : { type : 'Array' } ,
aGeoPoint : { type : 'GeoPoint' } ,
aFile : { type : 'File' }
2016-02-08 20:20:08 -08:00
}
2016-02-03 16:10:00 -08:00
} ;
2016-02-05 20:38:58 -08:00
var pointersAndRelationsSchema = {
2016-02-03 16:10:00 -08:00
className : 'HasPointersAndRelations' ,
fields : {
//Default fields
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
//Custom fields
aPointer : {
type : 'Pointer' ,
targetClass : 'HasAllPOD' ,
} ,
aRelation : {
type : 'Relation' ,
targetClass : 'HasAllPOD' ,
} ,
} ,
}
2016-02-03 11:55:44 -08:00
2016-02-05 14:56:11 -08:00
var noAuthHeaders = {
'X-Parse-Application-Id' : 'test' ,
} ;
var restKeyHeaders = {
'X-Parse-Application-Id' : 'test' ,
'X-Parse-REST-API-Key' : 'rest' ,
} ;
var masterKeyHeaders = {
'X-Parse-Application-Id' : 'test' ,
'X-Parse-Master-Key' : 'test' ,
} ;
2016-02-03 11:55:44 -08:00
describe ( 'schemas' , ( ) => {
it ( 'requires the master key to get all schemas' , ( done ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
2016-02-05 14:56:11 -08:00
headers : noAuthHeaders ,
2016-02-03 11:55:44 -08:00
} , ( error , response , body ) => {
2016-02-05 14:56:11 -08:00
//api.parse.com uses status code 401, but due to the lack of keys
//being necessary in parse-server, 403 makes more sense
expect ( response . statusCode ) . toEqual ( 403 ) ;
2016-02-03 11:55:44 -08:00
expect ( body . error ) . toEqual ( 'unauthorized' ) ;
done ( ) ;
} ) ;
} ) ;
2016-02-03 16:10:00 -08:00
it ( 'requires the master key to get one schema' , ( done ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas/SomeSchema' ,
json : true ,
2016-02-05 20:38:58 -08:00
headers : restKeyHeaders ,
2016-02-03 16:10:00 -08:00
} , ( error , response , body ) => {
2016-03-01 15:17:10 -08:00
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized: master key is required' ) ;
2016-02-03 16:10:00 -08:00
done ( ) ;
} ) ;
} ) ;
2016-02-05 14:56:11 -08:00
it ( 'asks for the master key if you use the rest key' , ( done ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
headers : restKeyHeaders ,
} , ( error , response , body ) => {
2016-03-01 15:17:10 -08:00
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized: master key is required' ) ;
2016-02-05 14:56:11 -08:00
done ( ) ;
} ) ;
} ) ;
2016-02-03 11:55:44 -08:00
it ( 'responds with empty list when there are no schemas' , done => {
request . get ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
2016-02-05 14:56:11 -08:00
headers : masterKeyHeaders ,
2016-02-03 11:55:44 -08:00
} , ( error , response , body ) => {
expect ( body . results ) . toEqual ( [ ] ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'responds with a list of schemas after creating objects' , done => {
2016-02-03 16:10:00 -08:00
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 ( ( ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
2016-02-05 14:56:11 -08:00
headers : masterKeyHeaders ,
2016-02-03 16:10:00 -08:00
} , ( error , response , body ) => {
var expected = {
2016-02-05 20:38:58 -08:00
results : [ plainOldDataSchema , pointersAndRelationsSchema ]
2016-02-03 16:10:00 -08:00
} ;
expect ( body ) . toEqual ( expected ) ;
done ( ) ;
} )
} ) ;
} ) ;
2016-02-03 11:55:44 -08:00
2016-02-03 16:10:00 -08:00
it ( 'responds with a single schema' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( ) . then ( ( ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
json : true ,
2016-02-05 20:38:58 -08:00
headers : masterKeyHeaders ,
2016-02-03 16:10:00 -08:00
} , ( error , response , body ) => {
2016-02-05 20:38:58 -08:00
expect ( body ) . toEqual ( plainOldDataSchema ) ;
2016-02-03 16:10:00 -08:00
done ( ) ;
2016-02-03 11:55:44 -08:00
} ) ;
2016-02-03 16:10:00 -08:00
} ) ;
} ) ;
it ( 'treats class names case sensitively' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( ) . then ( ( ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas/HASALLPOD' ,
json : true ,
2016-02-05 20:38:58 -08:00
headers : masterKeyHeaders ,
2016-02-03 16:10:00 -08:00
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body ) . toEqual ( {
code : 103 ,
2016-03-02 21:33:33 -08:00
error : 'Class HASALLPOD does not exist.' ,
2016-02-03 16:10:00 -08:00
} ) ;
done ( ) ;
} ) ;
} ) ;
2016-02-03 11:55:44 -08:00
} ) ;
2016-02-05 14:56:11 -08:00
it ( 'requires the master key to create a schema' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
headers : noAuthHeaders ,
body : {
className : 'MyClass' ,
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized' ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'asks for the master key if you use the rest key' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
json : true ,
headers : restKeyHeaders ,
body : {
className : 'MyClass' ,
} ,
} , ( error , response , body ) => {
2016-03-01 15:17:10 -08:00
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized: master key is required' ) ;
2016-02-05 14:56:11 -08:00
done ( ) ;
} ) ;
} ) ;
it ( 'sends an error if you use mismatching class names' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas/A' ,
headers : masterKeyHeaders ,
json : true ,
body : {
className : 'B' ,
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body ) . toEqual ( {
code : Parse . Error . INVALID _CLASS _NAME ,
error : 'class name mismatch between B and A' ,
} ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'sends an error if you use no class name' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
headers : masterKeyHeaders ,
json : true ,
body : { } ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body ) . toEqual ( {
code : 135 ,
error : 'POST /schemas needs class name' ,
} ) ;
done ( ) ;
} )
} ) ;
it ( 'sends an error if you try to create the same class twice' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
headers : masterKeyHeaders ,
json : true ,
body : {
className : 'A' ,
} ,
} , ( error , response , body ) => {
expect ( error ) . toEqual ( null ) ;
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
headers : masterKeyHeaders ,
json : true ,
body : {
className : 'A' ,
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body ) . toEqual ( {
code : Parse . Error . INVALID _CLASS _NAME ,
error : 'class A already exists' ,
} ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
it ( 'responds with all fields when you create a class' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas' ,
headers : masterKeyHeaders ,
json : true ,
2016-02-05 20:38:58 -08:00
body : {
className : "NewClass" ,
fields : {
foo : { type : 'Number' } ,
ptr : { type : 'Pointer' , targetClass : 'SomeClass' }
}
}
} , ( error , response , body ) => {
expect ( body ) . toEqual ( {
className : 'NewClass' ,
fields : {
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
foo : { type : 'Number' } ,
ptr : { type : 'Pointer' , targetClass : 'SomeClass' } ,
}
} ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'lets you specify class name in both places' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
2016-02-05 14:56:11 -08:00
body : {
className : "NewClass" ,
}
} , ( error , response , body ) => {
expect ( body ) . toEqual ( {
className : 'NewClass' ,
fields : {
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
}
} ) ;
done ( ) ;
} ) ;
} ) ;
2016-02-09 11:26:46 -08:00
it ( 'requires the master key to modify schemas' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : { } ,
} , ( error , response , body ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : noAuthHeaders ,
json : true ,
body : { } ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized' ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
2016-02-16 12:30:30 -08:00
it ( 'rejects class name mis-matches in put' , done => {
2016-02-09 11:26:46 -08:00
request . put ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : { className : 'WrongClassName' }
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INVALID _CLASS _NAME ) ;
expect ( body . error ) . toEqual ( 'class name mismatch between WrongClassName and NewClass' ) ;
2016-02-16 12:30:30 -08:00
done ( ) ;
2016-02-09 11:26:46 -08:00
} ) ;
} ) ;
it ( 'refuses to add fields to non-existent classes' , done => {
request . put ( {
url : 'http://localhost:8378/1/schemas/NoClass' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
newField : { type : 'String' }
}
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INVALID _CLASS _NAME ) ;
2016-02-29 17:41:09 -08:00
expect ( body . error ) . toEqual ( 'Class NoClass does not exist.' ) ;
2016-02-09 11:26:46 -08:00
done ( ) ;
} ) ;
} ) ;
2016-02-16 12:30:30 -08:00
it ( 'refuses to put to existing fields, even if it would not be a change' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
aString : { type : 'String' }
}
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( 255 ) ;
2016-02-29 17:41:09 -08:00
expect ( body . error ) . toEqual ( 'Field aString exists, cannot update.' ) ;
2016-02-16 12:30:30 -08:00
done ( ) ;
} ) ;
} )
} ) ;
2016-02-29 17:04:38 -08:00
it ( 'refuses to delete non-existent fields' , done => {
2016-02-16 12:30:30 -08:00
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
2016-02-29 17:04:38 -08:00
nonExistentKey : { _ _op : "Delete" } ,
2016-02-16 12:30:30 -08:00
}
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( 255 ) ;
2016-02-29 17:41:09 -08:00
expect ( body . error ) . toEqual ( 'Field nonExistentKey does not exist, cannot delete.' ) ;
2016-02-16 12:30:30 -08:00
done ( ) ;
} ) ;
} ) ;
} ) ;
it ( 'refuses to add a geopoint to a class that already has one' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
newGeo : { type : 'GeoPoint' }
}
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INCORRECT _TYPE ) ;
expect ( body . error ) . toEqual ( 'currently, only one GeoPoint field may exist in an object. Adding newGeo when aGeoPoint already exists.' ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
it ( 'refuses to add two geopoints' , done => {
var obj = new Parse . Object ( 'NewClass' ) ;
obj . set ( 'aString' , 'aString' ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
newGeo1 : { type : 'GeoPoint' } ,
newGeo2 : { type : 'GeoPoint' } ,
}
}
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INCORRECT _TYPE ) ;
expect ( body . error ) . toEqual ( 'currently, only one GeoPoint field may exist in an object. Adding newGeo2 when newGeo1 already exists.' ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
it ( 'allows you to delete and add a geopoint in the same request' , done => {
var obj = new Parse . Object ( 'NewClass' ) ;
obj . set ( 'geo1' , new Parse . GeoPoint ( { latitude : 0 , longitude : 0 } ) ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
geo2 : { type : 'GeoPoint' } ,
geo1 : { _ _op : 'Delete' }
}
}
} , ( error , response , body ) => {
expect ( dd ( body , {
"className" : "NewClass" ,
"fields" : {
"ACL" : { "type" : "ACL" } ,
"createdAt" : { "type" : "Date" } ,
"objectId" : { "type" : "String" } ,
"updatedAt" : { "type" : "Date" } ,
"geo2" : { "type" : "GeoPoint" } ,
}
} ) ) . toEqual ( undefined ) ;
done ( ) ;
} ) ;
} )
} ) ;
2016-02-09 11:26:46 -08:00
it ( 'put with no modifications returns all fields' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
2016-02-16 12:30:30 -08:00
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
2016-02-09 11:26:46 -08:00
headers : masterKeyHeaders ,
json : true ,
body : { } ,
} , ( error , response , body ) => {
expect ( body ) . toEqual ( plainOldDataSchema ) ;
done ( ) ;
} ) ;
2016-02-16 12:30:30 -08:00
} )
2016-02-09 11:26:46 -08:00
} ) ;
it ( 'lets you add fields' , done => {
request . post ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : { } ,
} , ( error , response , body ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
newField : { type : 'String' }
}
}
} , ( error , response , body ) => {
2016-02-16 12:30:30 -08:00
expect ( dd ( body , {
className : 'NewClass' ,
fields : {
"ACL" : { "type" : "ACL" } ,
"createdAt" : { "type" : "Date" } ,
"objectId" : { "type" : "String" } ,
"updatedAt" : { "type" : "Date" } ,
"newField" : { "type" : "String" } ,
} ,
} ) ) . toEqual ( undefined ) ;
2016-02-09 11:26:46 -08:00
request . get ( {
url : 'http://localhost:8378/1/schemas/NewClass' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
2016-02-16 12:30:30 -08:00
expect ( body ) . toEqual ( {
className : 'NewClass' ,
fields : {
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
newField : { type : 'String' } ,
}
} ) ;
2016-02-09 11:26:46 -08:00
done ( ) ;
} ) ;
} ) ;
} )
} ) ;
2016-02-16 12:30:30 -08:00
it ( 'lets you delete multiple fields and add fields' , done => {
var obj1 = hasAllPODobject ( ) ;
obj1 . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
aString : { _ _op : 'Delete' } ,
aNumber : { _ _op : 'Delete' } ,
aNewString : { type : 'String' } ,
aNewNumber : { type : 'Number' } ,
aNewRelation : { type : 'Relation' , targetClass : 'HasAllPOD' } ,
aNewPointer : { type : 'Pointer' , targetClass : 'HasAllPOD' } ,
}
}
} , ( error , response , body ) => {
expect ( body ) . toEqual ( {
className : 'HasAllPOD' ,
fields : {
//Default fields
ACL : { type : 'ACL' } ,
createdAt : { type : 'Date' } ,
updatedAt : { type : 'Date' } ,
objectId : { type : 'String' } ,
//Custom fields
aBool : { type : 'Boolean' } ,
aDate : { type : 'Date' } ,
aObject : { type : 'Object' } ,
aArray : { type : 'Array' } ,
aGeoPoint : { type : 'GeoPoint' } ,
aFile : { type : 'File' } ,
aNewNumber : { type : 'Number' } ,
aNewString : { type : 'String' } ,
aNewPointer : { type : 'Pointer' , targetClass : 'HasAllPOD' } ,
aNewRelation : { type : 'Relation' , targetClass : 'HasAllPOD' } ,
}
} ) ;
var obj2 = new Parse . Object ( 'HasAllPOD' ) ;
obj2 . set ( 'aNewPointer' , obj1 ) ;
var relation = obj2 . relation ( 'aNewRelation' ) ;
relation . add ( obj1 ) ;
obj2 . save ( ) . then ( done ) ; //Just need to make sure saving works on the new object.
} ) ;
} ) ;
} ) ;
it ( 'will not delete any fields if the additions are invalid' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . put ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
body : {
fields : {
fakeNewField : { type : 'fake type' } ,
aString : { _ _op : 'Delete' }
}
}
} , ( error , response , body ) => {
expect ( body . code ) . toEqual ( Parse . Error . INCORRECT _TYPE ) ;
expect ( body . error ) . toEqual ( 'invalid field type: fake type' ) ;
request . get ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . body ) . toEqual ( plainOldDataSchema ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
2016-02-17 19:00:17 -08:00
it ( 'requires the master key to delete schemas' , done => {
request . del ( {
url : 'http://localhost:8378/1/schemas/DoesntMatter' ,
headers : noAuthHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 403 ) ;
expect ( body . error ) . toEqual ( 'unauthorized' ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'refuses to delete non-empty collection' , done => {
var obj = hasAllPODobject ( ) ;
obj . save ( )
. then ( ( ) => {
request . del ( {
url : 'http://localhost:8378/1/schemas/HasAllPOD' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( 255 ) ;
2016-02-29 17:04:38 -08:00
expect ( body . error ) . toMatch ( /HasAllPOD/ ) ;
expect ( body . error ) . toMatch ( /contains 1/ ) ;
2016-02-17 19:00:17 -08:00
done ( ) ;
} ) ;
} ) ;
} ) ;
it ( 'fails when deleting collections with invalid class names' , done => {
request . del ( {
url : 'http://localhost:8378/1/schemas/_GlobalConfig' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INVALID _CLASS _NAME ) ;
expect ( body . error ) . toEqual ( 'Invalid classname: _GlobalConfig, classnames can only have alphanumeric characters and _, and must start with an alpha character ' ) ;
done ( ) ;
} )
} ) ;
it ( 'does not fail when deleting nonexistant collections' , done => {
request . del ( {
url : 'http://localhost:8378/1/schemas/Missing' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 200 ) ;
expect ( body ) . toEqual ( { } ) ;
done ( ) ;
} ) ;
} ) ;
it ( 'deletes collections including join tables' , done => {
var obj = new Parse . Object ( 'MyClass' ) ;
obj . set ( 'data' , 'data' ) ;
obj . save ( )
. then ( ( ) => {
var obj2 = new Parse . Object ( 'MyOtherClass' ) ;
var relation = obj2 . relation ( 'aRelation' ) ;
relation . add ( obj ) ;
return obj2 . save ( ) ;
} )
. then ( obj2 => obj2 . destroy ( ) )
. then ( ( ) => {
request . del ( {
url : 'http://localhost:8378/1/schemas/MyOtherClass' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
expect ( response . statusCode ) . toEqual ( 200 ) ;
expect ( response . body ) . toEqual ( { } ) ;
2016-02-29 19:45:12 -08:00
config . database . collectionExists ( '_Join:aRelation:MyOtherClass' ) . then ( exists => {
if ( exists ) {
fail ( 'Relation collection should be deleted.' ) ;
done ( ) ;
}
return config . database . collectionExists ( 'MyOtherClass' ) ;
} ) . then ( exists => {
if ( exists ) {
fail ( 'Class collection should be deleted.' ) ;
done ( ) ;
}
} ) . then ( ( ) => {
request . get ( {
url : 'http://localhost:8378/1/schemas/MyOtherClass' ,
headers : masterKeyHeaders ,
json : true ,
} , ( error , response , body ) => {
//Expect _SCHEMA entry to be gone.
expect ( response . statusCode ) . toEqual ( 400 ) ;
expect ( body . code ) . toEqual ( Parse . Error . INVALID _CLASS _NAME ) ;
2016-03-02 21:33:33 -08:00
expect ( body . error ) . toEqual ( 'Class MyOtherClass does not exist.' ) ;
2016-02-29 19:45:12 -08:00
done ( ) ;
2016-02-17 19:00:17 -08:00
} ) ;
} ) ;
} ) ;
2016-02-29 19:45:12 -08:00
} ) . then ( ( ) => {
2016-02-17 19:00:17 -08:00
} , error => {
fail ( error ) ;
2016-02-29 19:45:12 -08:00
done ( ) ;
2016-02-17 19:00:17 -08:00
} ) ;
} ) ;
2016-02-03 11:55:44 -08:00
} ) ;