@@ -108,10 +108,15 @@ AV.Cloud.define('testAVObjectsArrayParams', function(request, response) {
108108} ) ;
109109
110110AV . Cloud . define ( 'testUser' , function ( request , response ) {
111- assert . equal ( request . user . className , '_User' ) ;
112- assert . equal ( request . user . id , '54fd6a03e4b06c41e00b1f40' ) ;
113- assert . equal ( request . user . get ( 'username' ) , 'admin' ) ;
114- assert . equal ( request . user , AV . User . current ( ) ) ;
111+ if ( request . params . expectedUserId ) {
112+ assert . equal ( request . user . className , '_User' ) ;
113+ assert . equal ( request . user . id , '54fd6a03e4b06c41e00b1f40' ) ;
114+ assert . equal ( request . user . id , request . params . expectedUserId ) ;
115+ assert . equal ( request . user . get ( 'username' ) , 'admin' ) ;
116+ assert . equal ( request . user , AV . User . current ( ) ) ;
117+ } else {
118+ assert . equal ( request . user , undefined ) ;
119+ }
115120 response . success ( "ok" ) ;
116121} ) ;
117122
@@ -160,7 +165,7 @@ AV.Cloud.define('testRun_promise', function(request, response) {
160165} ) ;
161166
162167AV . Cloud . define ( 'testRunWithUser' , function ( request , response ) {
163- AV . Cloud . run ( 'testUser' , { } , {
168+ AV . Cloud . run ( 'testUser' , { expectedUserId : '54fd6a03e4b06c41e00b1f40' } , {
164169 success : function ( data ) {
165170 assert . equal ( 'ok' , data ) ;
166171 response . success ( ) ;
@@ -268,6 +273,7 @@ describe('functions', function() {
268273
269274 // 测试返回包含 AVObject 的复杂对象
270275 it ( 'return_complexObject' , function ( done ) {
276+ this . timeout ( 20000 ) ;
271277 request ( AV . Cloud )
272278 . post ( '/1.1/call/complexObject' )
273279 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -325,6 +331,7 @@ describe('functions', function() {
325331
326332 // 返回单个 AVObject
327333 it ( 'return_bareAVObject' , function ( done ) {
334+ this . timeout ( 20000 ) ;
328335 request ( AV . Cloud )
329336 . post ( '/1.1/call/bareAVObject' )
330337 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -339,6 +346,7 @@ describe('functions', function() {
339346
340347 // 返回 AVObject 数组
341348 it ( 'return_AVObjectsArray' , function ( done ) {
349+ this . timeout ( 20000 ) ;
342350 request ( AV . Cloud )
343351 . post ( '/1.1/call/AVObjects' )
344352 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -483,6 +491,9 @@ describe('functions', function() {
483491 . set ( 'X-AVOSCloud-Application-Id' , appId )
484492 . set ( 'X-AVOSCloud-Application-Key' , appKey )
485493 . set ( 'x-avoscloud-session-token' , sessionToken_admin )
494+ . send ( {
495+ expectedUserId : '54fd6a03e4b06c41e00b1f40'
496+ } )
486497 . expect ( 200 , done ) ;
487498 } ) ;
488499
@@ -500,6 +511,20 @@ describe('functions', function() {
500511 } ) ;
501512 } ) ;
502513
514+ it ( 'testUser_invalid_body_user' , function ( done ) {
515+ request ( AV . Cloud )
516+ . post ( '/1/functions/testUser' )
517+ . set ( 'X-AVOSCloud-Application-Id' , appId )
518+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
519+ . send ( {
520+ "user" : {
521+ "username" : "admin" ,
522+ "objectId" : "52aebbdee4b0c8b6fa455aa7"
523+ }
524+ } )
525+ . expect ( 200 , done ) ;
526+ } ) ;
527+
503528 // 测试调用 run 方法时,传递 user 对象的有效性
504529 it ( 'testRunWithUser' , function ( done ) {
505530 request ( AV . Cloud )
0 commit comments