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,97 @@ describe("AV.Cloud", function() {
1126 } ) ;
1227 } ) ;
1328 } ) ;
29+
30+ describe ( '#rpc' , function ( ) {
31+ it ( 'receive complex object' , function ( ) {
32+ return AV . Cloud . rpc ( 'complexObject' ) . then ( function ( result ) {
33+ expect ( result . foo ) . to . be ( 'bar' ) ;
34+ expect ( result . t ) . to . be . a ( Date ) ;
35+ expect ( result . t . toISOString ( ) ) . to . be ( '2015-05-14T09:21:18.273Z' ) ;
36+
37+ expect ( result . avObject ) . to . be . a ( AV . Object ) ;
38+ expect ( result . avObject . className ) . to . be ( 'ComplexObject' ) ;
39+ expect ( result . avObject . get ( 'numberColumn' ) ) . to . be ( 1.23 ) ;
40+ expect ( result . avObject . get ( 'arrayColumn' ) ) . to . eql ( [ 1 , 2 , 3 ] ) ;
41+ expect ( result . avObject . get ( 'objectColumn' ) ) . to . eql ( { foo : 'bar' } ) ;
42+ expect ( result . avObject . get ( 'stringColumn' ) ) . to . be ( 'testString' ) ;
43+ expect ( result . avObject . get ( 'anyColumn' ) ) . to . be ( '' ) ;
44+ expect ( result . avObject . get ( 'booleanColumn' ) ) . to . be ( true ) ;
45+ expect ( result . avObject . get ( 'pointerColumn' ) ) . to . be . a ( AV . Object ) ;
46+ expect ( result . avObject . get ( 'pointerColumn' ) . id ) . to . be ( '55069e5be4b0c93838ed8e6c' ) ;
47+ expect ( result . avObject . get ( 'relationColumn' ) ) . to . be . a ( AV . Relation ) ;
48+ expect ( result . avObject . get ( 'relationColumn' ) . targetClassName ) . to . be ( 'TestObject' ) ;
49+ expect ( result . avObject . get ( 'geopointColumn' ) ) . to . be . a ( AV . GeoPoint ) ;
50+ expect ( result . avObject . get ( 'geopointColumn' ) . latitude ) . to . be ( 0 ) ;
51+ expect ( result . avObject . get ( 'geopointColumn' ) . longitude ) . to . be ( 30 ) ;
52+ expect ( result . avObject . get ( 'dateColumn' ) ) . to . be . a ( Date ) ;
53+ expect ( result . avObject . get ( 'dateColumn' ) . toISOString ( ) ) . to . be ( '2015-05-14T06:24:47.000Z' ) ;
54+ expect ( result . avObject . get ( 'fileColumn' ) ) . to . be . a ( AV . File ) ;
55+ expect ( result . avObject . get ( 'fileColumn' ) . name ( ) ) . to . be ( 'ttt.jpg' ) ;
56+ expect ( result . avObject . get ( 'fileColumn' ) . url ( ) ) . to . be ( 'http://ac-4h2h4okw.clouddn.com/4qSbLMO866Tf4YtT9QEwJwysTlHGC9sMl7bpTwhQ.jpg' ) ;
57+
58+ result . avObjects . forEach ( function ( object ) {
59+ expect ( object ) . to . be . a ( AV . Object ) ;
60+ expect ( object . className ) . to . be ( 'ComplexObject' ) ;
61+ } ) ;
62+ } ) ;
63+ } ) ;
64+
65+ it ( 'receive bare AVObject' , function ( ) {
66+ return AV . Cloud . rpc ( 'bareAVObject' ) . then ( function ( result ) {
67+ expect ( result ) . to . be . a ( AV . Object ) ;
68+ expect ( result . className ) . to . be ( 'ComplexObject' ) ;
69+ expect ( result . get ( 'fileColumn' ) ) . to . be . a ( AV . File ) ;
70+ } ) ;
71+ } ) ;
72+
73+ it ( 'receive array of AVObjects' , function ( ) {
74+ return AV . Cloud . rpc ( 'AVObjects' ) . then ( function ( result ) {
75+ result . forEach ( function ( object ) {
76+ expect ( object ) . to . be . a ( AV . Object ) ;
77+ expect ( object . className ) . to . be ( 'ComplexObject' ) ;
78+ } ) ;
79+ } ) ;
80+ } ) ;
81+
82+ it ( 'send AVObject' , function ( ) {
83+ var avObject = new AV . Object ( 'ComplexObject' ) ;
84+ var avObjectItem = new AV . Object ( 'ComplexObject' ) ;
85+
86+ avObject . set ( {
87+ name : 'avObject' ,
88+ pointerColumn : AV . Object . createWithoutData ( '_User' , '55069e5be4b0c93838ed8e6c' ) . _toPointer ( )
89+ } ) ;
90+
91+ avObjectItem . set ( {
92+ name : 'avObjects'
93+ } ) ;
94+
95+ return AV . Object . saveAll ( [ avObject , avObjectItem ] ) . then ( function ( ) {
96+ return AV . Cloud . rpc ( 'testAVObjectParams' , {
97+ avObject : avObject ,
98+ avFile : AV . File . withURL ( 'hello.txt' , 'http://ac-1qdney6b.qiniudn.com/3zLG4o0d27MsCQ0qHGRg4JUKbaXU2fiE35HdhC8j.txt' ) ,
99+ avObjects : [ avObjectItem ]
100+ } ) ;
101+ } ) ;
102+ } ) ;
103+
104+ it ( 'send bare AVObject' , function ( ) {
105+ var avObject = new AV . Object ( 'ComplexObject' ) ;
106+
107+ avObject . set ( {
108+ name : 'avObject' ,
109+ avFile : AV . File . withURL ( 'hello.txt' , 'http://ac-1qdney6b.qiniudn.com/3zLG4o0d27MsCQ0qHGRg4JUKbaXU2fiE35HdhC8j.txt' )
110+ } ) ;
111+
112+ return AV . Cloud . rpc ( 'testBareAVObjectParams' , avObject ) ;
113+ } ) ;
114+ } ) ;
115+
116+ after ( function ( ) {
117+ AV . serverURL = originalServerURL ;
118+ AV . applicationId = originalAppId ;
119+ AV . applicationKey = originalAppKey ;
120+ AV . _useMasterKey = originalUseMasterKey ;
121+ } ) ;
14122} ) ;
0 commit comments