11describe ( "AV.Cloud" , function ( ) {
2+ var originalServerURL , originalAppId , originalAppKey , originalUseMasterKey ;
3+
4+ before ( function ( ) {
5+ originalServerURL = AV . serverURL ;
6+ originalAppId = AV . applicationId ;
7+ originalAppKey = AV . applicationKey ;
8+ originalUseMasterKey = AV . _useMasterKey ;
9+
10+ AV . serverURL = 'https://leancloud.cn'
11+ AV . applicationId = '4h2h4okwiyn8b6cle0oig00vitayum8ephrlsvg7xo8o19ne' ;
12+ AV . applicationKey = '3xjj1qw91cr3ygjq9lt0g8c3qpet38rrxtwmmp0yffyoy2t4' ;
13+ AV . _useMasterKey = false ;
14+
15+ AV . User . _currentUser = null ;
16+ } ) ;
17+
218 describe ( "#getServerDate" , function ( ) {
3-
419 it ( "should return a date." , function ( done ) {
520 AV . Cloud . getServerDate ( ) . then ( function ( date ) {
621 expect ( date ) . to . be . a ( 'object' ) ;
@@ -11,4 +26,123 @@ describe("AV.Cloud", function() {
1126 } ) ;
1227 } ) ;
1328 } ) ;
29+
30+ describe ( '#rpc' , function ( ) {
31+ it ( 'receive complex object' , function ( done ) {
32+ AV . Cloud . rpc ( 'complexObject' , null , {
33+ success : function ( result ) {
34+ expect ( result . foo ) . to . be ( 'bar' ) ;
35+ expect ( result . t ) . to . be . a ( Date ) ;
36+ expect ( result . t . toISOString ( ) ) . to . be ( '2015-05-14T09:21:18.273Z' ) ;
37+
38+ expect ( result . avObject ) . to . be . a ( AV . Object ) ;
39+ expect ( result . avObject . className ) . to . be ( 'ComplexObject' ) ;
40+ expect ( result . avObject . get ( 'numberColumn' ) ) . to . be ( 1.23 ) ;
41+ expect ( result . avObject . get ( 'arrayColumn' ) ) . to . eql ( [ 1 , 2 , 3 ] ) ;
42+ expect ( result . avObject . get ( 'objectColumn' ) ) . to . eql ( { foo : 'bar' } ) ;
43+ expect ( result . avObject . get ( 'stringColumn' ) ) . to . be ( 'testString' ) ;
44+ expect ( result . avObject . get ( 'anyColumn' ) ) . to . be ( '' ) ;
45+ expect ( result . avObject . get ( 'booleanColumn' ) ) . to . be ( true ) ;
46+ expect ( result . avObject . get ( 'pointerColumn' ) ) . to . be . a ( AV . Object ) ;
47+ expect ( result . avObject . get ( 'pointerColumn' ) . id ) . to . be ( '55069e5be4b0c93838ed8e6c' ) ;
48+ expect ( result . avObject . get ( 'relationColumn' ) ) . to . be . a ( AV . Relation ) ;
49+ expect ( result . avObject . get ( 'relationColumn' ) . targetClassName ) . to . be ( 'TestObject' ) ;
50+ expect ( result . avObject . get ( 'geopointColumn' ) ) . to . be . a ( AV . GeoPoint ) ;
51+ expect ( result . avObject . get ( 'geopointColumn' ) . latitude ) . to . be ( 0 ) ;
52+ expect ( result . avObject . get ( 'geopointColumn' ) . longitude ) . to . be ( 30 ) ;
53+ expect ( result . avObject . get ( 'dateColumn' ) ) . to . be . a ( Date ) ;
54+ expect ( result . avObject . get ( 'dateColumn' ) . toISOString ( ) ) . to . be ( '2015-05-14T06:24:47.000Z' ) ;
55+ expect ( result . avObject . get ( 'fileColumn' ) ) . to . be . a ( AV . File ) ;
56+ expect ( result . avObject . get ( 'fileColumn' ) . name ( ) ) . to . be ( 'ttt.jpg' ) ;
57+ expect ( result . avObject . get ( 'fileColumn' ) . url ( ) ) . to . be ( 'http://ac-4h2h4okw.clouddn.com/4qSbLMO866Tf4YtT9QEwJwysTlHGC9sMl7bpTwhQ.jpg' ) ;
58+
59+ result . avObjects . forEach ( function ( object ) {
60+ expect ( object ) . to . be . a ( AV . Object ) ;
61+ expect ( object . className ) . to . be ( 'ComplexObject' ) ;
62+ } ) ;
63+
64+ done ( ) ;
65+ } ,
66+ error : done
67+ } ) ;
68+ } ) ;
69+
70+ it ( 'receive bare AVObject' , function ( done ) {
71+ AV . Cloud . rpc ( 'bareAVObject' , null , {
72+ success : function ( result ) {
73+ expect ( result ) . to . be . a ( AV . Object ) ;
74+ expect ( result . className ) . to . be ( 'ComplexObject' ) ;
75+ expect ( result . get ( 'fileColumn' ) ) . to . be . a ( AV . File ) ;
76+ done ( ) ;
77+ } ,
78+ error : done
79+ } ) ;
80+ } ) ;
81+
82+ it ( 'receive array of AVObjects' , function ( done ) {
83+ AV . Cloud . rpc ( 'AVObjects' , null , {
84+ success : function ( result ) {
85+ result . forEach ( function ( object ) {
86+ expect ( object ) . to . be . a ( AV . Object ) ;
87+ expect ( object . className ) . to . be ( 'ComplexObject' ) ;
88+ } ) ;
89+ done ( ) ;
90+ } ,
91+ error : done
92+ } )
93+ } ) ;
94+
95+ it ( 'send AVObject' , function ( done ) {
96+ var avObject = new AV . Object ( 'ComplexObject' ) ;
97+ var avObjectItem = new AV . Object ( 'ComplexObject' ) ;
98+
99+ avObject . set ( {
100+ name : 'avObject' ,
101+ pointerColumn : AV . Object . createWithoutData ( '_User' , '55069e5be4b0c93838ed8e6c' ) . _toPointer ( )
102+ } ) ;
103+
104+ avObjectItem . set ( {
105+ name : 'avObjects'
106+ } ) ;
107+
108+ AV . Object . saveAll ( [ avObject , avObjectItem ] , {
109+ success : function ( ) {
110+ AV . Cloud . rpc ( 'testAVObjectParams' , {
111+ avObject : avObject ,
112+ avFile : AV . File . withURL ( 'hello.txt' , 'http://ac-1qdney6b.qiniudn.com/3zLG4o0d27MsCQ0qHGRg4JUKbaXU2fiE35HdhC8j.txt' ) ,
113+ avObjects : [ avObjectItem ]
114+ } , {
115+ success : function ( ) {
116+ done ( )
117+ } ,
118+ error : done
119+ } ) ;
120+ } ,
121+ error : done
122+ } ) ;
123+ } ) ;
124+
125+ it ( 'send bare AVObject' , function ( done ) {
126+ var avObject = new AV . Object ( 'ComplexObject' ) ;
127+
128+ avObject . set ( {
129+ name : 'avObject' ,
130+ avFile : AV . File . withURL ( 'hello.txt' , 'http://ac-1qdney6b.qiniudn.com/3zLG4o0d27MsCQ0qHGRg4JUKbaXU2fiE35HdhC8j.txt' )
131+ } ) ;
132+
133+ AV . Cloud . rpc ( 'testBareAVObjectParams' , avObject , {
134+ success : function ( ) {
135+ done ( )
136+ } ,
137+ error : done
138+ } ) ;
139+ } ) ;
140+ } ) ;
141+
142+ after ( function ( ) {
143+ AV . serverURL = originalServerURL ;
144+ AV . applicationId = originalAppId ;
145+ AV . applicationKey = originalAppKey ;
146+ AV . _useMasterKey = originalUseMasterKey ;
147+ } ) ;
14148} ) ;
0 commit comments