@@ -951,57 +951,154 @@ describe('miscellaneous', function () {
951951 ) ;
952952 } ) ;
953953
954- it ( 'should return the updated fields on PUT' , done => {
954+ it ( 'return the updated fields on PUT' , async ( ) => {
955955 const obj = new Parse . Object ( 'GameScore' ) ;
956- obj
957- . save ( { a : 'hello' , c : 1 , d : [ '1' ] , e : [ '1' ] , f : [ '1' , '2' ] } )
958- . then ( ( ) => {
959- const headers = {
960- 'Content-Type' : 'application/json' ,
961- 'X-Parse-Application-Id' : 'test' ,
962- 'X-Parse-REST-API-Key' : 'rest' ,
963- 'X-Parse-Installation-Id' : 'yolo' ,
964- } ;
965- request ( {
966- method : 'PUT' ,
967- headers : headers ,
968- url : 'http://localhost:8378/1/classes/GameScore/' + obj . id ,
969- body : JSON . stringify ( {
970- a : 'b' ,
971- c : { __op : 'Increment' , amount : 2 } ,
972- d : { __op : 'Add' , objects : [ '2' ] } ,
973- e : { __op : 'AddUnique' , objects : [ '1' , '2' ] } ,
974- f : { __op : 'Remove' , objects : [ '2' ] } ,
975- selfThing : {
976- __type : 'Pointer' ,
977- className : 'GameScore' ,
978- objectId : obj . id ,
979- } ,
980- } ) ,
981- } ) . then ( response => {
982- try {
983- const body = response . data ;
984- expect ( body . a ) . toBeUndefined ( ) ;
985- expect ( body . c ) . toEqual ( 3 ) ; // 2+1
986- expect ( body . d . length ) . toBe ( 2 ) ;
987- expect ( body . d . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
988- expect ( body . d . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
989- expect ( body . e . length ) . toBe ( 2 ) ;
990- expect ( body . e . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
991- expect ( body . e . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
992- expect ( body . f . length ) . toBe ( 1 ) ;
993- expect ( body . f . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
994- // return nothing on other self
995- expect ( body . selfThing ) . toBeUndefined ( ) ;
996- // updatedAt is always set
997- expect ( body . updatedAt ) . not . toBeUndefined ( ) ;
998- } catch ( e ) {
999- fail ( e ) ;
1000- }
1001- done ( ) ;
1002- } ) ;
956+ const pointer = new Parse . Object ( 'Child' ) ;
957+ await pointer . save ( ) ;
958+ obj . set (
959+ 'point' ,
960+ new Parse . GeoPoint ( {
961+ latitude : 37.4848 ,
962+ longitude : - 122.1483 ,
1003963 } )
1004- . catch ( done . fail ) ;
964+ ) ;
965+ obj . set ( 'array' , [ 'obj1' , 'obj2' ] ) ;
966+ obj . set ( 'objects' , { a : 'b' } ) ;
967+ obj . set ( 'string' , 'abc' ) ;
968+ obj . set ( 'bool' , true ) ;
969+ obj . set ( 'number' , 1 ) ;
970+ obj . set ( 'date' , new Date ( ) ) ;
971+ obj . set ( 'pointer' , pointer ) ;
972+ const headers = {
973+ 'Content-Type' : 'application/json' ,
974+ 'X-Parse-Application-Id' : 'test' ,
975+ 'X-Parse-REST-API-Key' : 'rest' ,
976+ 'X-Parse-Installation-Id' : 'yolo' ,
977+ } ;
978+ const saveResponse = await request ( {
979+ method : 'POST' ,
980+ headers : headers ,
981+ url : 'http://localhost:8378/1/classes/GameScore' ,
982+ body : JSON . stringify ( {
983+ a : 'hello' ,
984+ c : 1 ,
985+ d : [ '1' ] ,
986+ e : [ '1' ] ,
987+ f : [ '1' , '2' ] ,
988+ ...obj . toJSON ( ) ,
989+ } ) ,
990+ } ) ;
991+ expect ( Object . keys ( saveResponse . data ) . sort ( ) ) . toEqual ( [ 'createdAt' , 'objectId' ] ) ;
992+ obj . id = saveResponse . data . objectId ;
993+ const response = await request ( {
994+ method : 'PUT' ,
995+ headers : headers ,
996+ url : 'http://localhost:8378/1/classes/GameScore/' + obj . id ,
997+ body : JSON . stringify ( {
998+ a : 'b' ,
999+ c : { __op : 'Increment' , amount : 2 } ,
1000+ d : { __op : 'Add' , objects : [ '2' ] } ,
1001+ e : { __op : 'AddUnique' , objects : [ '1' , '2' ] } ,
1002+ f : { __op : 'Remove' , objects : [ '2' ] } ,
1003+ selfThing : {
1004+ __type : 'Pointer' ,
1005+ className : 'GameScore' ,
1006+ objectId : obj . id ,
1007+ } ,
1008+ } ) ,
1009+ } ) ;
1010+ const body = response . data ;
1011+ expect ( Object . keys ( body ) . sort ( ) ) . toEqual ( [ 'c' , 'd' , 'e' , 'f' , 'updatedAt' ] ) ;
1012+ expect ( body . a ) . toBeUndefined ( ) ;
1013+ expect ( body . c ) . toEqual ( 3 ) ; // 2+1
1014+ expect ( body . d . length ) . toBe ( 2 ) ;
1015+ expect ( body . d . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1016+ expect ( body . d . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
1017+ expect ( body . e . length ) . toBe ( 2 ) ;
1018+ expect ( body . e . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1019+ expect ( body . e . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
1020+ expect ( body . f . length ) . toBe ( 1 ) ;
1021+ expect ( body . f . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1022+ expect ( body . selfThing ) . toBeUndefined ( ) ;
1023+ expect ( body . updatedAt ) . not . toBeUndefined ( ) ;
1024+ } ) ;
1025+
1026+ it ( 'should response should not change with triggers' , async ( ) => {
1027+ const obj = new Parse . Object ( 'GameScore' ) ;
1028+ const pointer = new Parse . Object ( 'Child' ) ;
1029+ Parse . Cloud . beforeSave ( 'GameScore' , request => {
1030+ return request . object ;
1031+ } ) ;
1032+ Parse . Cloud . afterSave ( 'GameScore' , request => {
1033+ return request . object ;
1034+ } ) ;
1035+ await pointer . save ( ) ;
1036+ obj . set (
1037+ 'point' ,
1038+ new Parse . GeoPoint ( {
1039+ latitude : 37.4848 ,
1040+ longitude : - 122.1483 ,
1041+ } )
1042+ ) ;
1043+ obj . set ( 'array' , [ 'obj1' , 'obj2' ] ) ;
1044+ obj . set ( 'objects' , { a : 'b' } ) ;
1045+ obj . set ( 'string' , 'abc' ) ;
1046+ obj . set ( 'bool' , true ) ;
1047+ obj . set ( 'number' , 1 ) ;
1048+ obj . set ( 'date' , new Date ( ) ) ;
1049+ obj . set ( 'pointer' , pointer ) ;
1050+ const headers = {
1051+ 'Content-Type' : 'application/json' ,
1052+ 'X-Parse-Application-Id' : 'test' ,
1053+ 'X-Parse-REST-API-Key' : 'rest' ,
1054+ 'X-Parse-Installation-Id' : 'yolo' ,
1055+ } ;
1056+ const saveResponse = await request ( {
1057+ method : 'POST' ,
1058+ headers : headers ,
1059+ url : 'http://localhost:8378/1/classes/GameScore' ,
1060+ body : JSON . stringify ( {
1061+ a : 'hello' ,
1062+ c : 1 ,
1063+ d : [ '1' ] ,
1064+ e : [ '1' ] ,
1065+ f : [ '1' , '2' ] ,
1066+ ...obj . toJSON ( ) ,
1067+ } ) ,
1068+ } ) ;
1069+ expect ( Object . keys ( saveResponse . data ) . sort ( ) ) . toEqual ( [ 'createdAt' , 'objectId' ] ) ;
1070+ obj . id = saveResponse . data . objectId ;
1071+ const response = await request ( {
1072+ method : 'PUT' ,
1073+ headers : headers ,
1074+ url : 'http://localhost:8378/1/classes/GameScore/' + obj . id ,
1075+ body : JSON . stringify ( {
1076+ a : 'b' ,
1077+ c : { __op : 'Increment' , amount : 2 } ,
1078+ d : { __op : 'Add' , objects : [ '2' ] } ,
1079+ e : { __op : 'AddUnique' , objects : [ '1' , '2' ] } ,
1080+ f : { __op : 'Remove' , objects : [ '2' ] } ,
1081+ selfThing : {
1082+ __type : 'Pointer' ,
1083+ className : 'GameScore' ,
1084+ objectId : obj . id ,
1085+ } ,
1086+ } ) ,
1087+ } ) ;
1088+ const body = response . data ;
1089+ expect ( Object . keys ( body ) . sort ( ) ) . toEqual ( [ 'c' , 'd' , 'e' , 'f' , 'updatedAt' ] ) ;
1090+ expect ( body . a ) . toBeUndefined ( ) ;
1091+ expect ( body . c ) . toEqual ( 3 ) ; // 2+1
1092+ expect ( body . d . length ) . toBe ( 2 ) ;
1093+ expect ( body . d . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1094+ expect ( body . d . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
1095+ expect ( body . e . length ) . toBe ( 2 ) ;
1096+ expect ( body . e . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1097+ expect ( body . e . indexOf ( '2' ) > - 1 ) . toBe ( true ) ;
1098+ expect ( body . f . length ) . toBe ( 1 ) ;
1099+ expect ( body . f . indexOf ( '1' ) > - 1 ) . toBe ( true ) ;
1100+ expect ( body . selfThing ) . toBeUndefined ( ) ;
1101+ expect ( body . updatedAt ) . not . toBeUndefined ( ) ;
10051102 } ) ;
10061103
10071104 it ( 'test cloud function error handling' , done => {
0 commit comments