FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
parse-server/spec/ParseAPI.spec.js at master · codelabsprodev/parse-server · GitHub
codelabsprodev
/
parse-server
Public
forked from
parse-community/parse-server
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
parse-server
/
spec
/
ParseAPI.spec.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
615 lines (575 loc) · 18.3 KB
Breadcrumbs
parse-server
/
spec
/
ParseAPI.spec.js
Copy path
File metadata and controls
615 lines (575 loc) · 18.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// A bunch of different tests are in here - it isn't very thematic.
// It would probably be better to refactor them into different files.
var
DatabaseAdapter
=
require
(
'../DatabaseAdapter'
)
;
var
request
=
require
(
'request'
)
;
describe
(
'miscellaneous'
,
function
(
)
{
it
(
'create a GameScore object'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'GameScore'
)
;
obj
.
set
(
'score'
,
1337
)
;
obj
.
save
(
)
.
then
(
function
(
obj
)
{
expect
(
typeof
obj
.
id
)
.
toBe
(
'string'
)
;
expect
(
typeof
obj
.
createdAt
.
toGMTString
(
)
)
.
toBe
(
'string'
)
;
done
(
)
;
}
,
function
(
err
)
{
console
.
log
(
err
)
;
}
)
;
}
)
;
it
(
'get a TestObject'
,
function
(
done
)
{
create
(
{
'bloop'
:
'blarg'
}
,
function
(
obj
)
{
var
t2
=
new
TestObject
(
{
objectId
:
obj
.
id
}
)
;
t2
.
fetch
(
{
success
:
function
(
obj2
)
{
expect
(
obj2
.
get
(
'bloop'
)
)
.
toEqual
(
'blarg'
)
;
expect
(
obj2
.
id
)
.
toBeTruthy
(
)
;
expect
(
obj2
.
id
)
.
toEqual
(
obj
.
id
)
;
done
(
)
;
}
,
error
:
fail
}
)
;
}
)
;
}
)
;
it
(
'create a valid parse user'
,
function
(
done
)
{
createTestUser
(
function
(
data
)
{
expect
(
data
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
data
.
getSessionToken
(
)
)
.
not
.
toBeUndefined
(
)
;
expect
(
data
.
get
(
'password'
)
)
.
toBeUndefined
(
)
;
done
(
)
;
}
,
function
(
err
)
{
console
.
log
(
err
)
;
fail
(
err
)
;
}
)
;
}
)
;
it
(
'fail to create a duplicate username'
,
function
(
done
)
{
createTestUser
(
function
(
data
)
{
createTestUser
(
function
(
data
)
{
fail
(
'Should not have been able to save duplicate username.'
)
;
}
,
function
(
error
)
{
expect
(
error
.
code
)
.
toEqual
(
Parse
.
Error
.
USERNAME_TAKEN
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
it
(
'succeed in logging in'
,
function
(
done
)
{
createTestUser
(
function
(
u
)
{
expect
(
typeof
u
.
id
)
.
toEqual
(
'string'
)
;
Parse
.
User
.
logIn
(
'test'
,
'moon-y'
,
{
success
:
function
(
user
)
{
expect
(
typeof
user
.
id
)
.
toEqual
(
'string'
)
;
expect
(
user
.
get
(
'password'
)
)
.
toBeUndefined
(
)
;
expect
(
user
.
getSessionToken
(
)
)
.
not
.
toBeUndefined
(
)
;
Parse
.
User
.
logOut
(
)
;
done
(
)
;
}
,
error
:
function
(
error
)
{
fail
(
error
)
;
}
}
)
;
}
,
fail
)
;
}
)
;
it
(
'increment with a user object'
,
function
(
done
)
{
createTestUser
(
)
.
then
(
(
user
)
=>
{
user
.
increment
(
'foo'
)
;
return
user
.
save
(
)
;
}
)
.
then
(
(
)
=>
{
return
Parse
.
User
.
logIn
(
'test'
,
'moon-y'
)
;
}
)
.
then
(
(
user
)
=>
{
expect
(
user
.
get
(
'foo'
)
)
.
toEqual
(
1
)
;
user
.
increment
(
'foo'
)
;
return
user
.
save
(
)
;
}
)
.
then
(
(
)
=>
{
Parse
.
User
.
logOut
(
)
;
return
Parse
.
User
.
logIn
(
'test'
,
'moon-y'
)
;
}
)
.
then
(
(
user
)
=>
{
expect
(
user
.
get
(
'foo'
)
)
.
toEqual
(
2
)
;
Parse
.
User
.
logOut
(
)
;
done
(
)
;
}
,
(
error
)
=>
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'save various data types'
,
function
(
done
)
{
var
obj
=
new
TestObject
(
)
;
obj
.
set
(
'date'
,
new
Date
(
)
)
;
obj
.
set
(
'array'
,
[
1
,
2
,
3
]
)
;
obj
.
set
(
'object'
,
{
one
:
1
,
two
:
2
}
)
;
obj
.
save
(
)
.
then
(
(
)
=>
{
var
obj2
=
new
TestObject
(
{
objectId
:
obj
.
id
}
)
;
return
obj2
.
fetch
(
)
;
}
)
.
then
(
(
obj2
)
=>
{
expect
(
obj2
.
get
(
'date'
)
instanceof
Date
)
.
toBe
(
true
)
;
expect
(
obj2
.
get
(
'array'
)
instanceof
Array
)
.
toBe
(
true
)
;
expect
(
obj2
.
get
(
'object'
)
instanceof
Array
)
.
toBe
(
false
)
;
expect
(
obj2
.
get
(
'object'
)
instanceof
Object
)
.
toBe
(
true
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'query with limit'
,
function
(
done
)
{
var
baz
=
new
TestObject
(
{
foo
:
'baz'
}
)
;
var
qux
=
new
TestObject
(
{
foo
:
'qux'
}
)
;
baz
.
save
(
)
.
then
(
(
)
=>
{
return
qux
.
save
(
)
;
}
)
.
then
(
(
)
=>
{
var
query
=
new
Parse
.
Query
(
TestObject
)
;
query
.
limit
(
1
)
;
return
query
.
find
(
)
;
}
)
.
then
(
(
results
)
=>
{
expect
(
results
.
length
)
.
toEqual
(
1
)
;
done
(
)
;
}
,
(
error
)
=>
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'basic saveAll'
,
function
(
done
)
{
var
alpha
=
new
TestObject
(
{
letter
:
'alpha'
}
)
;
var
beta
=
new
TestObject
(
{
letter
:
'beta'
}
)
;
Parse
.
Object
.
saveAll
(
[
alpha
,
beta
]
)
.
then
(
(
)
=>
{
expect
(
alpha
.
id
)
.
toBeTruthy
(
)
;
expect
(
beta
.
id
)
.
toBeTruthy
(
)
;
return
new
Parse
.
Query
(
TestObject
)
.
find
(
)
;
}
)
.
then
(
(
results
)
=>
{
expect
(
results
.
length
)
.
toEqual
(
2
)
;
done
(
)
;
}
,
(
error
)
=>
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test cloud function'
,
function
(
done
)
{
Parse
.
Cloud
.
run
(
'hello'
,
{
}
,
function
(
result
)
{
expect
(
result
)
.
toEqual
(
'Hello world!'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'basic beforeSave rejection'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeSaveFailure'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
fail
(
'Should not have been able to save BeforeSaveFailure class.'
)
;
done
(
)
;
}
,
function
(
error
)
{
done
(
)
;
}
)
}
)
;
it
(
'test beforeSave unchanged success'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeSaveUnchanged'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test beforeSave changed object success'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeSaveChanged'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
var
query
=
new
Parse
.
Query
(
'BeforeSaveChanged'
)
;
query
.
get
(
obj
.
id
)
.
then
(
function
(
objAgain
)
{
expect
(
objAgain
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test afterSave ran and created an object'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'AfterSaveTest'
)
;
obj
.
save
(
)
;
setTimeout
(
function
(
)
{
var
query
=
new
Parse
.
Query
(
'AfterSaveProof'
)
;
query
.
equalTo
(
'proof'
,
obj
.
id
)
;
query
.
find
(
)
.
then
(
function
(
results
)
{
expect
(
results
.
length
)
.
toEqual
(
1
)
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
,
500
)
;
}
)
;
it
(
'test beforeSave happens on update'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeSaveChanged'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
obj
.
set
(
'foo'
,
'bar'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
function
(
)
{
var
query
=
new
Parse
.
Query
(
'BeforeSaveChanged'
)
;
return
query
.
get
(
obj
.
id
)
.
then
(
function
(
objAgain
)
{
expect
(
objAgain
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
done
(
)
;
}
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test beforeDelete failure'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeDeleteFail'
)
;
var
id
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
(
)
=>
{
id
=
obj
.
id
;
return
obj
.
destroy
(
)
;
}
)
.
then
(
(
)
=>
{
fail
(
'obj.destroy() should have failed, but it succeeded'
)
;
done
(
)
;
}
,
(
error
)
=>
{
expect
(
error
.
code
)
.
toEqual
(
Parse
.
Error
.
SCRIPT_FAILED
)
;
expect
(
error
.
message
)
.
toEqual
(
'Nope'
)
;
var
objAgain
=
new
Parse
.
Object
(
'BeforeDeleteFail'
,
{
objectId
:
id
}
)
;
return
objAgain
.
fetch
(
)
;
}
)
.
then
(
(
objAgain
)
=>
{
expect
(
objAgain
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
done
(
)
;
}
,
(
error
)
=>
{
// We should have been able to fetch the object again
fail
(
error
)
;
}
)
;
}
)
;
it
(
'test beforeDelete success'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'BeforeDeleteTest'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
return
obj
.
destroy
(
)
;
}
)
.
then
(
function
(
)
{
var
objAgain
=
new
Parse
.
Object
(
'BeforeDeleteTest'
,
obj
.
id
)
;
return
objAgain
.
fetch
(
)
.
then
(
fail
,
done
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test afterDelete ran and created an object'
,
function
(
done
)
{
var
obj
=
new
Parse
.
Object
(
'AfterDeleteTest'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
obj
.
destroy
(
)
;
}
)
;
setTimeout
(
function
(
)
{
var
query
=
new
Parse
.
Query
(
'AfterDeleteProof'
)
;
query
.
equalTo
(
'proof'
,
obj
.
id
)
;
query
.
find
(
)
.
then
(
function
(
results
)
{
expect
(
results
.
length
)
.
toEqual
(
1
)
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
,
500
)
;
}
)
;
it
(
'test save triggers get user'
,
function
(
done
)
{
var
user
=
new
Parse
.
User
(
)
;
user
.
set
(
"password"
,
"asdf"
)
;
user
.
set
(
"email"
,
"asdf@example.com"
)
;
user
.
set
(
"username"
,
"zxcv"
)
;
user
.
signUp
(
null
,
{
success
:
function
(
)
{
var
obj
=
new
Parse
.
Object
(
'SaveTriggerUser'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
}
)
;
}
)
;
it
(
'test cloud function return types'
,
function
(
done
)
{
Parse
.
Cloud
.
run
(
'foo'
)
.
then
(
(
result
)
=>
{
expect
(
result
.
object
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
result
.
object
.
className
)
.
toEqual
(
'Foo'
)
;
expect
(
result
.
object
.
get
(
'x'
)
)
.
toEqual
(
2
)
;
var
bar
=
result
.
object
.
get
(
'relation'
)
;
expect
(
bar
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
bar
.
className
)
.
toEqual
(
'Bar'
)
;
expect
(
bar
.
get
(
'x'
)
)
.
toEqual
(
3
)
;
expect
(
Array
.
isArray
(
result
.
array
)
)
.
toEqual
(
true
)
;
expect
(
result
.
array
[
0
]
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
result
.
array
[
0
]
.
get
(
'x'
)
)
.
toEqual
(
2
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test rest_create_app'
,
function
(
done
)
{
var
appId
;
Parse
.
_request
(
'POST'
,
'rest_create_app'
)
.
then
(
(
res
)
=>
{
expect
(
typeof
res
.
application_id
)
.
toEqual
(
'string'
)
;
expect
(
res
.
master_key
)
.
toEqual
(
'master'
)
;
appId
=
res
.
application_id
;
Parse
.
initialize
(
appId
,
'unused'
)
;
var
obj
=
new
Parse
.
Object
(
'TestObject'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
(
)
=>
{
var
db
=
DatabaseAdapter
.
getDatabaseConnection
(
appId
)
;
return
db
.
mongoFind
(
'TestObject'
,
{
}
,
{
}
)
;
}
)
.
then
(
(
results
)
=>
{
expect
(
results
.
length
)
.
toEqual
(
1
)
;
expect
(
results
[
0
]
[
'foo'
]
)
.
toEqual
(
'bar'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test beforeSave get full object on create and update'
,
function
(
done
)
{
var
triggerTime
=
0
;
// Register a mock beforeSave hook
Parse
.
Cloud
.
beforeSave
(
'GameScore'
,
function
(
req
,
res
)
{
var
object
=
req
.
object
;
expect
(
object
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
object
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
object
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
if
(
triggerTime
==
0
)
{
// Create
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
}
else
if
(
triggerTime
==
1
)
{
// Update
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
}
else
{
res
.
error
(
)
;
}
triggerTime
++
;
res
.
success
(
)
;
}
)
;
var
obj
=
new
Parse
.
Object
(
'GameScore'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
set
(
'fooAgain'
,
'barAgain'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
// We only update foo
obj
.
set
(
'foo'
,
'baz'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
function
(
)
{
// Make sure the checking has been triggered
expect
(
triggerTime
)
.
toBe
(
2
)
;
// Clear mock beforeSave
delete
Parse
.
Cloud
.
Triggers
.
beforeSave
.
GameScore
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test afterSave get full object on create and update'
,
function
(
done
)
{
var
triggerTime
=
0
;
// Register a mock beforeSave hook
Parse
.
Cloud
.
afterSave
(
'GameScore'
,
function
(
req
,
res
)
{
var
object
=
req
.
object
;
expect
(
object
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
object
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
object
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
if
(
triggerTime
==
0
)
{
// Create
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
}
else
if
(
triggerTime
==
1
)
{
// Update
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
}
else
{
res
.
error
(
)
;
}
triggerTime
++
;
res
.
success
(
)
;
}
)
;
var
obj
=
new
Parse
.
Object
(
'GameScore'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
set
(
'fooAgain'
,
'barAgain'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
// We only update foo
obj
.
set
(
'foo'
,
'baz'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
function
(
)
{
// Make sure the checking has been triggered
expect
(
triggerTime
)
.
toBe
(
2
)
;
// Clear mock afterSave
delete
Parse
.
Cloud
.
Triggers
.
afterSave
.
GameScore
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test beforeSave get original object on update'
,
function
(
done
)
{
var
triggerTime
=
0
;
// Register a mock beforeSave hook
Parse
.
Cloud
.
beforeSave
(
'GameScore'
,
function
(
req
,
res
)
{
var
object
=
req
.
object
;
expect
(
object
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
object
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
object
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
var
originalObject
=
req
.
original
;
if
(
triggerTime
==
0
)
{
// Create
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
// Check the originalObject is undefined
expect
(
originalObject
)
.
toBeUndefined
(
)
;
}
else
if
(
triggerTime
==
1
)
{
// Update
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
// Check the originalObject
expect
(
originalObject
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
originalObject
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
originalObject
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
}
else
{
res
.
error
(
)
;
}
triggerTime
++
;
res
.
success
(
)
;
}
)
;
var
obj
=
new
Parse
.
Object
(
'GameScore'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
set
(
'fooAgain'
,
'barAgain'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
// We only update foo
obj
.
set
(
'foo'
,
'baz'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
function
(
)
{
// Make sure the checking has been triggered
expect
(
triggerTime
)
.
toBe
(
2
)
;
// Clear mock beforeSave
delete
Parse
.
Cloud
.
Triggers
.
beforeSave
.
GameScore
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test afterSave get original object on update'
,
function
(
done
)
{
var
triggerTime
=
0
;
// Register a mock beforeSave hook
Parse
.
Cloud
.
afterSave
(
'GameScore'
,
function
(
req
,
res
)
{
var
object
=
req
.
object
;
expect
(
object
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
object
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
object
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
object
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
var
originalObject
=
req
.
original
;
if
(
triggerTime
==
0
)
{
// Create
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
// Check the originalObject is undefined
expect
(
originalObject
)
.
toBeUndefined
(
)
;
}
else
if
(
triggerTime
==
1
)
{
// Update
expect
(
object
.
get
(
'foo'
)
)
.
toEqual
(
'baz'
)
;
// Check the originalObject
expect
(
originalObject
instanceof
Parse
.
Object
)
.
toBeTruthy
(
)
;
expect
(
originalObject
.
get
(
'fooAgain'
)
)
.
toEqual
(
'barAgain'
)
;
expect
(
originalObject
.
id
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
createdAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
updatedAt
)
.
not
.
toBeUndefined
(
)
;
expect
(
originalObject
.
get
(
'foo'
)
)
.
toEqual
(
'bar'
)
;
}
else
{
res
.
error
(
)
;
}
triggerTime
++
;
res
.
success
(
)
;
}
)
;
var
obj
=
new
Parse
.
Object
(
'GameScore'
)
;
obj
.
set
(
'foo'
,
'bar'
)
;
obj
.
set
(
'fooAgain'
,
'barAgain'
)
;
obj
.
save
(
)
.
then
(
function
(
)
{
// We only update foo
obj
.
set
(
'foo'
,
'baz'
)
;
return
obj
.
save
(
)
;
}
)
.
then
(
function
(
)
{
// Make sure the checking has been triggered
expect
(
triggerTime
)
.
toBe
(
2
)
;
// Clear mock afterSave
delete
Parse
.
Cloud
.
Triggers
.
afterSave
.
GameScore
;
done
(
)
;
}
,
function
(
error
)
{
fail
(
error
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'test cloud function error handling'
,
(
done
)
=>
{
// Register a function which will fail
Parse
.
Cloud
.
define
(
'willFail'
,
(
req
,
res
)
=>
{
res
.
error
(
'noway'
)
;
}
)
;
Parse
.
Cloud
.
run
(
'willFail'
)
.
then
(
(
s
)
=>
{
fail
(
'Should not have succeeded.'
)
;
delete
Parse
.
Cloud
.
Functions
[
'willFail'
]
;
done
(
)
;
}
,
(
e
)
=>
{
expect
(
e
.
code
)
.
toEqual
(
141
)
;
expect
(
e
.
message
)
.
toEqual
(
'noway'
)
;
delete
Parse
.
Cloud
.
Functions
[
'willFail'
]
;
done
(
)
;
}
)
;
}
)
;
it
(
'fails on invalid client key'
,
done
=>
{
var
headers
=
{
'Content-Type'
:
'application/octet-stream'
,
'X-Parse-Application-Id'
:
'test'
,
'X-Parse-Client-Key'
:
'notclient'
}
;
request
.
get
(
{
headers
:
headers
,
url
:
'http://localhost:8378/1/classes/TestObject'
}
,
(
error
,
response
,
body
)
=>
{
expect
(
error
)
.
toBe
(
null
)
;
var
b
=
JSON
.
parse
(
body
)
;
expect
(
b
.
error
)
.
toEqual
(
'unauthorized'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'fails on invalid windows key'
,
done
=>
{
var
headers
=
{
'Content-Type'
:
'application/octet-stream'
,
'X-Parse-Application-Id'
:
'test'
,
'X-Parse-Windows-Key'
:
'notwindows'
}
;
request
.
get
(
{
headers
:
headers
,
url
:
'http://localhost:8378/1/classes/TestObject'
}
,
(
error
,
response
,
body
)
=>
{
expect
(
error
)
.
toBe
(
null
)
;
var
b
=
JSON
.
parse
(
body
)
;
expect
(
b
.
error
)
.
toEqual
(
'unauthorized'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'fails on invalid javascript key'
,
done
=>
{
var
headers
=
{
'Content-Type'
:
'application/octet-stream'
,
'X-Parse-Application-Id'
:
'test'
,
'X-Parse-Javascript-Key'
:
'notjavascript'
}
;
request
.
get
(
{
headers
:
headers
,
url
:
'http://localhost:8378/1/classes/TestObject'
}
,
(
error
,
response
,
body
)
=>
{
expect
(
error
)
.
toBe
(
null
)
;
var
b
=
JSON
.
parse
(
body
)
;
expect
(
b
.
error
)
.
toEqual
(
'unauthorized'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'fails on invalid rest api key'
,
done
=>
{
var
headers
=
{
'Content-Type'
:
'application/octet-stream'
,
'X-Parse-Application-Id'
:
'test'
,
'X-Parse-REST-API-Key'
:
'notrest'
}
;
request
.
get
(
{
headers
:
headers
,
url
:
'http://localhost:8378/1/classes/TestObject'
}
,
(
error
,
response
,
body
)
=>
{
expect
(
error
)
.
toBe
(
null
)
;
var
b
=
JSON
.
parse
(
body
)
;
expect
(
b
.
error
)
.
toEqual
(
'unauthorized'
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL