@@ -2045,4 +2045,60 @@ describe('Parse Object', () => {
2045
2045
expect ( obj . get ( 'string' ) ) . toBeDefined ( ) ;
2046
2046
expect ( obj . get ( 'string' ) ) . toBeInstanceOf ( String ) ;
2047
2047
} ) ;
2048
+
2049
+ it ( 'allowCustomObjectId' , async ( ) => {
2050
+ await reconfigureServer ( { allowCustomObjectId : true } ) ;
2051
+ Parse . allowCustomObjectId = true ;
2052
+ const customId = `${ Date . now ( ) } ` ;
2053
+ const object = new Parse . Object ( 'TestObject' ) ;
2054
+ try {
2055
+ await object . save ( ) ;
2056
+ fail ( ) ;
2057
+ } catch ( error ) {
2058
+ expect ( error . message ) . toBe ( 'objectId must not be empty, null or undefined' ) ;
2059
+ }
2060
+ object . id = customId ;
2061
+ object . set ( 'foo' , 'bar' ) ;
2062
+ await object . save ( ) ;
2063
+ expect ( object . id ) . toBe ( customId ) ;
2064
+
2065
+ const query = new Parse . Query ( 'TestObject' ) ;
2066
+ const result = await query . get ( customId ) ;
2067
+ expect ( result . get ( 'foo' ) ) . toBe ( 'bar' ) ;
2068
+ expect ( result . id ) . toBe ( customId ) ;
2069
+
2070
+ result . set ( 'foo' , 'baz' ) ;
2071
+ await result . save ( ) ;
2072
+
2073
+ const afterSave = await query . get ( customId ) ;
2074
+ expect ( afterSave . get ( 'foo' ) ) . toBe ( 'baz' ) ;
2075
+ Parse . allowCustomObjectId = false ;
2076
+ } ) ;
2077
+
2078
+ it ( 'allowCustomObjectId saveAll' , async ( ) => {
2079
+ await reconfigureServer ( { allowCustomObjectId : true } ) ;
2080
+ Parse . allowCustomObjectId = true ;
2081
+ const customId1 = `${ Date . now ( ) } ` ;
2082
+ const customId2 = `${ Date . now ( ) } ` ;
2083
+ const obj1 = new TestObject ( { foo : 'bar' } ) ;
2084
+ const obj2 = new TestObject ( { foo : 'baz' } ) ;
2085
+ try {
2086
+ await Parse . Object . saveAll ( [ obj1 , obj2 ] ) ;
2087
+ fail ( ) ;
2088
+ } catch ( error ) {
2089
+ expect ( error . message ) . toBe ( 'objectId must not be empty, null or undefined' ) ;
2090
+ }
2091
+ obj1 . id = customId1 ;
2092
+ obj2 . id = customId2 ;
2093
+ await Parse . Object . saveAll ( [ obj1 , obj2 ] ) ;
2094
+ expect ( obj1 . id ) . toBe ( customId1 ) ;
2095
+ expect ( obj2 . id ) . toBe ( customId2 ) ;
2096
+
2097
+ const query = new Parse . Query ( TestObject ) ;
2098
+ const results = await query . find ( ) ;
2099
+ results . forEach ( result => {
2100
+ expect ( [ customId1 , customId2 ] . includes ( result . id ) ) ;
2101
+ } ) ;
2102
+ Parse . allowCustomObjectId = false ;
2103
+ } ) ;
2048
2104
} ) ;
0 commit comments