22
33var transform = require ( '../transform' ) ;
44
5- var dummyConfig = {
6- schema : {
5+ var dummySchema = {
76 data : { } ,
87 getExpectedType : function ( className , key ) {
98 if ( key == 'userPointer' ) {
109 return '*_User' ;
10+ } else if ( key == 'picture' ) {
11+ return 'file' ;
12+ } else if ( key == 'location' ) {
13+ return 'geopoint' ;
1114 }
1215 return ;
1316 }
14- }
1517} ;
1618
1719
1820describe ( 'transformCreate' , ( ) => {
1921
2022 it ( 'a basic number' , ( done ) => {
2123 var input = { five : 5 } ;
22- var output = transform . transformCreate ( dummyConfig , null , input ) ;
24+ var output = transform . transformCreate ( dummySchema , null , input ) ;
2325 jequal ( input , output ) ;
2426 done ( ) ;
2527 } ) ;
@@ -29,7 +31,7 @@ describe('transformCreate', () => {
2931 createdAt : "2015-10-06T21:24:50.332Z" ,
3032 updatedAt : "2015-10-06T21:24:50.332Z"
3133 } ;
32- var output = transform . transformCreate ( dummyConfig , null , input ) ;
34+ var output = transform . transformCreate ( dummySchema , null , input ) ;
3335 expect ( output . _created_at instanceof Date ) . toBe ( true ) ;
3436 expect ( output . _updated_at instanceof Date ) . toBe ( true ) ;
3537 done ( ) ;
@@ -41,29 +43,29 @@ describe('transformCreate', () => {
4143 objectId : 'myId' ,
4244 className : 'Blah' ,
4345 } ;
44- var out = transform . transformCreate ( dummyConfig , null , { pointers : [ pointer ] } ) ;
46+ var out = transform . transformCreate ( dummySchema , null , { pointers : [ pointer ] } ) ;
4547 jequal ( [ pointer ] , out . pointers ) ;
4648 done ( ) ;
4749 } ) ;
4850
4951 it ( 'a delete op' , ( done ) => {
5052 var input = { deleteMe : { __op : 'Delete' } } ;
51- var output = transform . transformCreate ( dummyConfig , null , input ) ;
53+ var output = transform . transformCreate ( dummySchema , null , input ) ;
5254 jequal ( output , { } ) ;
5355 done ( ) ;
5456 } ) ;
5557
5658 it ( 'basic ACL' , ( done ) => {
5759 var input = { ACL : { '0123' : { 'read' : true , 'write' : true } } } ;
58- var output = transform . transformCreate ( dummyConfig , null , input ) ;
60+ var output = transform . transformCreate ( dummySchema , null , input ) ;
5961 // This just checks that it doesn't crash, but it should check format.
6062 done ( ) ;
6163 } ) ;
6264} ) ;
6365
6466describe ( 'transformWhere' , ( ) => {
6567 it ( 'objectId' , ( done ) => {
66- var out = transform . transformWhere ( dummyConfig , null , { objectId : 'foo' } ) ;
68+ var out = transform . transformWhere ( dummySchema , null , { objectId : 'foo' } ) ;
6769 expect ( out . _id ) . toEqual ( 'foo' ) ;
6870 done ( ) ;
6971 } ) ;
@@ -72,7 +74,7 @@ describe('transformWhere', () => {
7274 var input = {
7375 objectId : { '$in' : [ 'one' , 'two' , 'three' ] } ,
7476 } ;
75- var output = transform . transformWhere ( dummyConfig , null , input ) ;
77+ var output = transform . transformWhere ( dummySchema , null , input ) ;
7678 jequal ( input . objectId , output . _id ) ;
7779 done ( ) ;
7880 } ) ;
@@ -81,17 +83,66 @@ describe('transformWhere', () => {
8183describe ( 'untransformObject' , ( ) => {
8284 it ( 'built-in timestamps' , ( done ) => {
8385 var input = { createdAt : new Date ( ) , updatedAt : new Date ( ) } ;
84- var output = transform . untransformObject ( dummyConfig , null , input ) ;
86+ var output = transform . untransformObject ( dummySchema , null , input ) ;
8587 expect ( typeof output . createdAt ) . toEqual ( 'string' ) ;
8688 expect ( typeof output . updatedAt ) . toEqual ( 'string' ) ;
8789 done ( ) ;
8890 } ) ;
91+
92+ it ( 'pointer' , ( done ) => {
93+ var input = { _p_userPointer : '_User$123' } ;
94+ var output = transform . untransformObject ( dummySchema , null , input ) ;
95+ expect ( typeof output . userPointer ) . toEqual ( 'object' ) ;
96+ expect ( output . userPointer ) . toEqual (
97+ { __type : 'Pointer' , className : '_User' , objectId : '123' }
98+ ) ;
99+ done ( ) ;
100+ } ) ;
101+
102+ it ( 'null pointer' , ( done ) => {
103+ var input = { _p_userPointer : null } ;
104+ var output = transform . untransformObject ( dummySchema , null , input ) ;
105+ expect ( output . userPointer ) . toBeUndefined ( ) ;
106+ done ( ) ;
107+ } ) ;
108+
109+ it ( 'file' , ( done ) => {
110+ var input = { picture : 'pic.jpg' } ;
111+ var output = transform . untransformObject ( dummySchema , null , input ) ;
112+ expect ( typeof output . picture ) . toEqual ( 'object' ) ;
113+ expect ( output . picture ) . toEqual ( { __type : 'File' , name : 'pic.jpg' } ) ;
114+ done ( ) ;
115+ } ) ;
116+
117+ it ( 'null file' , ( done ) => {
118+ var input = { picture : null } ;
119+ var output = transform . untransformObject ( dummySchema , null , input ) ;
120+ expect ( output . picture ) . toBeUndefined ( ) ;
121+ done ( ) ;
122+ } ) ;
123+
124+ it ( 'geopoint' , ( done ) => {
125+ var input = { location : [ 180 , - 180 ] } ;
126+ var output = transform . untransformObject ( dummySchema , null , input ) ;
127+ expect ( typeof output . location ) . toEqual ( 'object' ) ;
128+ expect ( output . location ) . toEqual (
129+ { __type : 'GeoPoint' , longitude : 180 , latitude : - 180 }
130+ ) ;
131+ done ( ) ;
132+ } ) ;
133+
134+ it ( 'null geopoint' , ( done ) => {
135+ var input = { location : null } ;
136+ var output = transform . untransformObject ( dummySchema , null , input ) ;
137+ expect ( output . location ) . toBeUndefined ( ) ;
138+ done ( ) ;
139+ } ) ;
89140} ) ;
90141
91142describe ( 'transformKey' , ( ) => {
92143 it ( 'throws out _password' , ( done ) => {
93144 try {
94- transform . transformKey ( dummyConfig , '_User' , '_password' ) ;
145+ transform . transformKey ( dummySchema , '_User' , '_password' ) ;
95146 fail ( 'should have thrown' ) ;
96147 } catch ( e ) {
97148 done ( ) ;
@@ -105,7 +156,7 @@ describe('transform schema key changes', () => {
105156 var input = {
106157 somePointer : { __type : 'Pointer' , className : 'Micro' , objectId : 'oft' }
107158 } ;
108- var output = transform . transformCreate ( dummyConfig , null , input ) ;
159+ var output = transform . transformCreate ( dummySchema , null , input ) ;
109160 expect ( typeof output . _p_somePointer ) . toEqual ( 'string' ) ;
110161 expect ( output . _p_somePointer ) . toEqual ( 'Micro$oft' ) ;
111162 done ( ) ;
@@ -115,7 +166,7 @@ describe('transform schema key changes', () => {
115166 var input = {
116167 userPointer : { __type : 'Pointer' , className : '_User' , objectId : 'qwerty' }
117168 } ;
118- var output = transform . transformCreate ( dummyConfig , null , input ) ;
169+ var output = transform . transformCreate ( dummySchema , null , input ) ;
119170 expect ( typeof output . _p_userPointer ) . toEqual ( 'string' ) ;
120171 expect ( output . _p_userPointer ) . toEqual ( '_User$qwerty' ) ;
121172 done ( ) ;
@@ -128,7 +179,7 @@ describe('transform schema key changes', () => {
128179 "Kevin" : { "write" : true }
129180 }
130181 } ;
131- var output = transform . transformCreate ( dummyConfig , null , input ) ;
182+ var output = transform . transformCreate ( dummySchema , null , input ) ;
132183 expect ( typeof output . _rperm ) . toEqual ( 'object' ) ;
133184 expect ( typeof output . _wperm ) . toEqual ( 'object' ) ;
134185 expect ( output . ACL ) . toBeUndefined ( ) ;
@@ -142,7 +193,7 @@ describe('transform schema key changes', () => {
142193 _rperm : [ "*" ] ,
143194 _wperm : [ "Kevin" ]
144195 } ;
145- var output = transform . untransformObject ( dummyConfig , null , input ) ;
196+ var output = transform . untransformObject ( dummySchema , null , input ) ;
146197 expect ( typeof output . ACL ) . toEqual ( 'object' ) ;
147198 expect ( output . _rperm ) . toBeUndefined ( ) ;
148199 expect ( output . _wperm ) . toBeUndefined ( ) ;
0 commit comments