@@ -101,6 +101,73 @@ describe('ParseServerRESTController', () => {
101
101
) ;
102
102
} ) ;
103
103
104
+ it ( 'should handle response status' , async ( ) => {
105
+ const router = ParseServer . promiseRouter ( { appId : Parse . applicationId } ) ;
106
+ spyOn ( router , 'tryRouteRequest' ) . and . callThrough ( ) ;
107
+ RESTController = ParseServerRESTController ( Parse . applicationId , router ) ;
108
+ const resp = await RESTController . request ( 'POST' , '/classes/MyObject' ) ;
109
+ const {
110
+ status,
111
+ response,
112
+ location,
113
+ } = await router . tryRouteRequest . calls . all ( ) [ 0 ] . returnValue ;
114
+
115
+ expect ( status ) . toBe ( 201 ) ;
116
+ expect ( response ) . toEqual ( resp ) ;
117
+ expect ( location ) . toBe (
118
+ `http://localhost:8378/1/classes/MyObject/${ resp . objectId } `
119
+ ) ;
120
+ } ) ;
121
+
122
+ it ( 'should handle response status in batch' , async ( ) => {
123
+ const router = ParseServer . promiseRouter ( { appId : Parse . applicationId } ) ;
124
+ spyOn ( router , 'tryRouteRequest' ) . and . callThrough ( ) ;
125
+ RESTController = ParseServerRESTController ( Parse . applicationId , router ) ;
126
+ const resp = await RESTController . request (
127
+ 'POST' ,
128
+ 'batch' ,
129
+ {
130
+ requests : [
131
+ {
132
+ method : 'POST' ,
133
+ path : '/classes/MyObject' ,
134
+ } ,
135
+ {
136
+ method : 'POST' ,
137
+ path : '/classes/MyObject' ,
138
+ } ,
139
+ ] ,
140
+ } ,
141
+ {
142
+ returnStatus : true ,
143
+ }
144
+ ) ;
145
+ expect ( resp . length ) . toBe ( 2 ) ;
146
+ expect ( resp [ 0 ] . _status ) . toBe ( 201 ) ;
147
+ expect ( resp [ 1 ] . _status ) . toBe ( 201 ) ;
148
+ expect ( resp [ 0 ] . success ) . toBeDefined ( ) ;
149
+ expect ( resp [ 1 ] . success ) . toBeDefined ( ) ;
150
+ expect ( router . tryRouteRequest . calls . all ( ) . length ) . toBe ( 2 ) ;
151
+ } ) ;
152
+
153
+ it ( 'properly handle existed' , async done => {
154
+ const restController = Parse . CoreManager . getRESTController ( ) ;
155
+ Parse . CoreManager . setRESTController ( RESTController ) ;
156
+ Parse . Cloud . define ( 'handleStatus' , async ( ) => {
157
+ const obj = new Parse . Object ( 'TestObject' ) ;
158
+ expect ( obj . existed ( ) ) . toBe ( false ) ;
159
+ await obj . save ( ) ;
160
+ expect ( obj . existed ( ) ) . toBe ( false ) ;
161
+
162
+ const query = new Parse . Query ( 'TestObject' ) ;
163
+ const result = await query . get ( obj . id ) ;
164
+ expect ( result . existed ( ) ) . toBe ( true ) ;
165
+ Parse . CoreManager . setRESTController ( restController ) ;
166
+ done ( ) ;
167
+ } ) ;
168
+ await Parse . Cloud . run ( 'handleStatus' ) ;
169
+ } ) ;
170
+
104
171
if (
105
172
( semver . satisfies ( process . env . MONGODB_VERSION , '>=4.0.4' ) &&
106
173
process . env . MONGODB_TOPOLOGY === 'replicaset' &&
0 commit comments