@@ -16,7 +16,7 @@ app.listen(12345);
16
16
17
17
18
18
describe ( 'Hooks' , ( ) => {
19
-
19
+
20
20
it ( "should have some hooks registered" , ( done ) => {
21
21
Parse . Hooks . getFunctions ( ) . then ( ( res ) => {
22
22
expect ( res . constructor ) . toBe ( Array . prototype . constructor ) ;
@@ -26,7 +26,7 @@ describe('Hooks', () => {
26
26
done ( ) ;
27
27
} ) ;
28
28
} ) ;
29
-
29
+
30
30
it ( "should have some triggers registered" , ( done ) => {
31
31
Parse . Hooks . getTriggers ( ) . then ( ( res ) => {
32
32
expect ( res . constructor ) . toBe ( Array . prototype . constructor ) ;
@@ -59,7 +59,7 @@ describe('Hooks', () => {
59
59
} ) . then ( ( res ) => {
60
60
expect ( res . functionName ) . toBe ( "My-Test-Function" ) ;
61
61
expect ( res . url ) . toBe ( "http://anotherurl" )
62
-
62
+
63
63
return Parse . Hooks . deleteFunction ( "My-Test-Function" ) ;
64
64
} , ( err ) => {
65
65
fail ( err ) ;
@@ -81,7 +81,7 @@ describe('Hooks', () => {
81
81
done ( ) ;
82
82
} )
83
83
} ) ;
84
-
84
+
85
85
it ( "should CRUD a trigger registration" , ( done ) => {
86
86
// Create
87
87
Parse . Hooks . createTrigger ( "MyClass" , "beforeDelete" , "http://someurl" ) . then ( ( res ) => {
@@ -105,7 +105,7 @@ describe('Hooks', () => {
105
105
} ) . then ( ( res ) => {
106
106
expect ( res . className ) . toBe ( "MyClass" ) ;
107
107
expect ( res . url ) . toBe ( "http://anotherurl" )
108
-
108
+
109
109
return Parse . Hooks . deleteTrigger ( "MyClass" , "beforeDelete" ) ;
110
110
} , ( err ) => {
111
111
fail ( err ) ;
@@ -127,7 +127,7 @@ describe('Hooks', () => {
127
127
done ( ) ;
128
128
} ) ;
129
129
} ) ;
130
-
130
+
131
131
it ( "should fail to register hooks without Master Key" , ( done ) => {
132
132
request . post ( Parse . serverURL + "/hooks/functions" , {
133
133
headers : {
@@ -141,7 +141,7 @@ describe('Hooks', () => {
141
141
done ( ) ;
142
142
} )
143
143
} ) ;
144
-
144
+
145
145
it ( "should fail trying to create two times the same function" , ( done ) => {
146
146
Parse . Hooks . createFunction ( "my_new_function" , "http://url.com" ) . then ( ( ) => {
147
147
return Parse . Hooks . createFunction ( "my_new_function" , "http://url.com" )
@@ -162,7 +162,7 @@ describe('Hooks', () => {
162
162
done ( ) ;
163
163
} )
164
164
} ) ;
165
-
165
+
166
166
it ( "should fail trying to create two times the same trigger" , ( done ) => {
167
167
Parse . Hooks . createTrigger ( "MyClass" , "beforeSave" , "http://url.com" ) . then ( ( ) => {
168
168
return Parse . Hooks . createTrigger ( "MyClass" , "beforeSave" , "http://url.com" )
@@ -181,7 +181,7 @@ describe('Hooks', () => {
181
181
done ( ) ;
182
182
} )
183
183
} ) ;
184
-
184
+
185
185
it ( "should fail trying to update a function that don't exist" , ( done ) => {
186
186
Parse . Hooks . updateFunction ( "A_COOL_FUNCTION" , "http://url.com" ) . then ( ( ) => {
187
187
fail ( "Should not succeed" )
@@ -198,7 +198,7 @@ describe('Hooks', () => {
198
198
done ( ) ;
199
199
} ) ;
200
200
} ) ;
201
-
201
+
202
202
it ( "should fail trying to update a trigger that don't exist" , ( done ) => {
203
203
Parse . Hooks . updateTrigger ( "AClassName" , "beforeSave" , "http://url.com" ) . then ( ( ) => {
204
204
fail ( "Should not succeed" )
@@ -215,8 +215,8 @@ describe('Hooks', () => {
215
215
done ( ) ;
216
216
} ) ;
217
217
} ) ;
218
-
219
-
218
+
219
+
220
220
it ( "should fail trying to create a malformed function" , ( done ) => {
221
221
Parse . Hooks . createFunction ( "MyFunction" ) . then ( ( res ) => {
222
222
fail ( res ) ;
@@ -226,7 +226,7 @@ describe('Hooks', () => {
226
226
done ( ) ;
227
227
} ) ;
228
228
} ) ;
229
-
229
+
230
230
it ( "should fail trying to create a malformed function (REST)" , ( done ) => {
231
231
request . post ( Parse . serverURL + "/hooks/functions" , {
232
232
headers : {
@@ -241,16 +241,16 @@ describe('Hooks', () => {
241
241
done ( ) ;
242
242
} )
243
243
} ) ;
244
-
245
-
244
+
245
+
246
246
it ( "should create hooks and properly preload them" , ( done ) => {
247
-
247
+
248
248
var promises = [ ] ;
249
249
for ( var i = 0 ; i < 5 ; i ++ ) {
250
250
promises . push ( Parse . Hooks . createTrigger ( "MyClass" + i , "beforeSave" , "http://url.com/beforeSave/" + i ) ) ;
251
251
promises . push ( Parse . Hooks . createFunction ( "AFunction" + i , "http://url.com/function" + i ) ) ;
252
252
}
253
-
253
+
254
254
Parse . Promise . when ( promises ) . then ( function ( results ) {
255
255
for ( var i = 0 ; i < 5 ; i ++ ) {
256
256
// Delete everything from memory, as the server just started
@@ -263,7 +263,7 @@ describe('Hooks', () => {
263
263
return hooksController . load ( )
264
264
} , ( err ) => {
265
265
console . error ( err ) ;
266
- fail ( ) ;
266
+ fail ( 'Should properly create all hooks' ) ;
267
267
done ( ) ;
268
268
} ) . then ( function ( ) {
269
269
for ( var i = 0 ; i < 5 ; i ++ ) {
@@ -273,17 +273,17 @@ describe('Hooks', () => {
273
273
done ( ) ;
274
274
} , ( err ) => {
275
275
console . error ( err ) ;
276
- fail ( ) ;
276
+ fail ( 'should properly load all hooks' ) ;
277
277
done ( ) ;
278
278
} )
279
279
} ) ;
280
-
280
+
281
281
it ( "should run the function on the test server" , ( done ) => {
282
-
282
+
283
283
app . post ( "/SomeFunction" , function ( req , res ) {
284
284
res . json ( { success :"OK!" } ) ;
285
285
} ) ;
286
-
286
+
287
287
Parse . Hooks . createFunction ( "SOME_TEST_FUNCTION" , hookServerURL + "/SomeFunction" ) . then ( function ( ) {
288
288
return Parse . Cloud . run ( "SOME_TEST_FUNCTION" )
289
289
} , ( err ) => {
@@ -299,9 +299,9 @@ describe('Hooks', () => {
299
299
done ( ) ;
300
300
} )
301
301
} ) ;
302
-
302
+
303
303
it ( "should run the function on the test server" , ( done ) => {
304
-
304
+
305
305
app . post ( "/SomeFunctionError" , function ( req , res ) {
306
306
res . json ( { error : { code : 1337 , error : "hacking that one!" } } ) ;
307
307
} ) ;
@@ -322,8 +322,8 @@ describe('Hooks', () => {
322
322
done ( ) ;
323
323
} ) ;
324
324
} ) ;
325
-
326
-
325
+
326
+
327
327
it ( "should run the beforeSave hook on the test server" , ( done ) => {
328
328
var triggerCount = 0 ;
329
329
app . post ( "/BeforeSaveSome" , function ( req , res ) {
@@ -350,7 +350,7 @@ describe('Hooks', () => {
350
350
done ( ) ;
351
351
} ) ;
352
352
} ) ;
353
-
353
+
354
354
it ( "should run the afterSave hook on the test server" , ( done ) => {
355
355
var triggerCount = 0 ;
356
356
var newObjectId ;
@@ -387,4 +387,4 @@ describe('Hooks', () => {
387
387
done ( ) ;
388
388
} ) ;
389
389
} ) ;
390
- } ) ;
390
+ } ) ;
0 commit comments