2
2
3
3
var transform = require ( '../transform' ) ;
4
4
5
- var dummyConfig = {
6
- schema : {
5
+ var dummySchema = {
7
6
data : { } ,
8
7
getExpectedType : function ( className , key ) {
9
8
if ( key == 'userPointer' ) {
10
9
return '*_User' ;
10
+ } else if ( key == 'picture' ) {
11
+ return 'file' ;
12
+ } else if ( key == 'location' ) {
13
+ return 'geopoint' ;
11
14
}
12
15
return ;
13
16
}
14
- }
15
17
} ;
16
18
17
19
18
20
describe ( 'transformCreate' , ( ) => {
19
21
20
22
it ( 'a basic number' , ( done ) => {
21
23
var input = { five : 5 } ;
22
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
24
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
23
25
jequal ( input , output ) ;
24
26
done ( ) ;
25
27
} ) ;
@@ -29,7 +31,7 @@ describe('transformCreate', () => {
29
31
createdAt : "2015-10-06T21:24:50.332Z" ,
30
32
updatedAt : "2015-10-06T21:24:50.332Z"
31
33
} ;
32
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
34
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
33
35
expect ( output . _created_at instanceof Date ) . toBe ( true ) ;
34
36
expect ( output . _updated_at instanceof Date ) . toBe ( true ) ;
35
37
done ( ) ;
@@ -41,29 +43,29 @@ describe('transformCreate', () => {
41
43
objectId : 'myId' ,
42
44
className : 'Blah' ,
43
45
} ;
44
- var out = transform . transformCreate ( dummyConfig , null , { pointers : [ pointer ] } ) ;
46
+ var out = transform . transformCreate ( dummySchema , null , { pointers : [ pointer ] } ) ;
45
47
jequal ( [ pointer ] , out . pointers ) ;
46
48
done ( ) ;
47
49
} ) ;
48
50
49
51
it ( 'a delete op' , ( done ) => {
50
52
var input = { deleteMe : { __op : 'Delete' } } ;
51
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
53
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
52
54
jequal ( output , { } ) ;
53
55
done ( ) ;
54
56
} ) ;
55
57
56
58
it ( 'basic ACL' , ( done ) => {
57
59
var input = { ACL : { '0123' : { 'read' : true , 'write' : true } } } ;
58
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
60
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
59
61
// This just checks that it doesn't crash, but it should check format.
60
62
done ( ) ;
61
63
} ) ;
62
64
} ) ;
63
65
64
66
describe ( 'transformWhere' , ( ) => {
65
67
it ( 'objectId' , ( done ) => {
66
- var out = transform . transformWhere ( dummyConfig , null , { objectId : 'foo' } ) ;
68
+ var out = transform . transformWhere ( dummySchema , null , { objectId : 'foo' } ) ;
67
69
expect ( out . _id ) . toEqual ( 'foo' ) ;
68
70
done ( ) ;
69
71
} ) ;
@@ -72,7 +74,7 @@ describe('transformWhere', () => {
72
74
var input = {
73
75
objectId : { '$in' : [ 'one' , 'two' , 'three' ] } ,
74
76
} ;
75
- var output = transform . transformWhere ( dummyConfig , null , input ) ;
77
+ var output = transform . transformWhere ( dummySchema , null , input ) ;
76
78
jequal ( input . objectId , output . _id ) ;
77
79
done ( ) ;
78
80
} ) ;
@@ -81,17 +83,66 @@ describe('transformWhere', () => {
81
83
describe ( 'untransformObject' , ( ) => {
82
84
it ( 'built-in timestamps' , ( done ) => {
83
85
var input = { createdAt : new Date ( ) , updatedAt : new Date ( ) } ;
84
- var output = transform . untransformObject ( dummyConfig , null , input ) ;
86
+ var output = transform . untransformObject ( dummySchema , null , input ) ;
85
87
expect ( typeof output . createdAt ) . toEqual ( 'string' ) ;
86
88
expect ( typeof output . updatedAt ) . toEqual ( 'string' ) ;
87
89
done ( ) ;
88
90
} ) ;
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
+ } ) ;
89
140
} ) ;
90
141
91
142
describe ( 'transformKey' , ( ) => {
92
143
it ( 'throws out _password' , ( done ) => {
93
144
try {
94
- transform . transformKey ( dummyConfig , '_User' , '_password' ) ;
145
+ transform . transformKey ( dummySchema , '_User' , '_password' ) ;
95
146
fail ( 'should have thrown' ) ;
96
147
} catch ( e ) {
97
148
done ( ) ;
@@ -105,7 +156,7 @@ describe('transform schema key changes', () => {
105
156
var input = {
106
157
somePointer : { __type : 'Pointer' , className : 'Micro' , objectId : 'oft' }
107
158
} ;
108
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
159
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
109
160
expect ( typeof output . _p_somePointer ) . toEqual ( 'string' ) ;
110
161
expect ( output . _p_somePointer ) . toEqual ( 'Micro$oft' ) ;
111
162
done ( ) ;
@@ -115,7 +166,7 @@ describe('transform schema key changes', () => {
115
166
var input = {
116
167
userPointer : { __type : 'Pointer' , className : '_User' , objectId : 'qwerty' }
117
168
} ;
118
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
169
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
119
170
expect ( typeof output . _p_userPointer ) . toEqual ( 'string' ) ;
120
171
expect ( output . _p_userPointer ) . toEqual ( '_User$qwerty' ) ;
121
172
done ( ) ;
@@ -128,7 +179,7 @@ describe('transform schema key changes', () => {
128
179
"Kevin" : { "write" : true }
129
180
}
130
181
} ;
131
- var output = transform . transformCreate ( dummyConfig , null , input ) ;
182
+ var output = transform . transformCreate ( dummySchema , null , input ) ;
132
183
expect ( typeof output . _rperm ) . toEqual ( 'object' ) ;
133
184
expect ( typeof output . _wperm ) . toEqual ( 'object' ) ;
134
185
expect ( output . ACL ) . toBeUndefined ( ) ;
@@ -142,7 +193,7 @@ describe('transform schema key changes', () => {
142
193
_rperm : [ "*" ] ,
143
194
_wperm : [ "Kevin" ]
144
195
} ;
145
- var output = transform . untransformObject ( dummyConfig , null , input ) ;
196
+ var output = transform . untransformObject ( dummySchema , null , input ) ;
146
197
expect ( typeof output . ACL ) . toEqual ( 'object' ) ;
147
198
expect ( output . _rperm ) . toBeUndefined ( ) ;
148
199
expect ( output . _wperm ) . toBeUndefined ( ) ;
0 commit comments