@@ -17,6 +17,7 @@ const mockObject = function(className) {
17
17
} ;
18
18
mockObject . registerSubclass = function ( ) { } ;
19
19
mockObject . prototype = {
20
+ id : 'objId123' ,
20
21
_getServerData ( ) {
21
22
return this . _serverData ;
22
23
} ,
@@ -38,6 +39,8 @@ mockObject.prototype = {
38
39
__type : 'Object' ,
39
40
className : this . className
40
41
} ;
42
+ seen = seen || [ ] ;
43
+ offline = offline || false ;
41
44
for ( const attr in this . attributes ) {
42
45
json [ attr ] = encode ( this . attributes [ attr ] , false , false , seen . concat ( this ) , offline ) ;
43
46
}
@@ -167,6 +170,64 @@ describe('encode', () => {
167
170
} ) ;
168
171
} ) ;
169
172
173
+ it ( 'encodes unsaved ParseObject' , ( ) => {
174
+ const obj = new ParseObject ( 'Item' ) ;
175
+ obj . id = undefined ;
176
+ obj . _serverData = { } ;
177
+ obj . attributes = {
178
+ str : 'string' ,
179
+ date : new Date ( Date . UTC ( 2015 , 1 , 1 ) )
180
+ } ;
181
+
182
+ expect ( encode ( obj ) ) . toEqual ( {
183
+ __type : 'Object' ,
184
+ className : 'Item' ,
185
+ str : 'string' ,
186
+ date : {
187
+ __type : 'Date' ,
188
+ iso : '2015-02-01T00:00:00.000Z'
189
+ }
190
+ } ) ;
191
+
192
+ const subobj = new ParseObject ( 'Subitem' )
193
+ subobj . id = undefined ;
194
+ subobj . _serverData = { } ;
195
+ subobj . attributes = {
196
+ str : 'substring' ,
197
+ } ;
198
+
199
+ obj . attributes = {
200
+ item : subobj
201
+ } ;
202
+
203
+ expect ( encode ( obj ) ) . toEqual ( {
204
+ __type : 'Object' ,
205
+ className : 'Item' ,
206
+ item : {
207
+ __type : 'Object' ,
208
+ className : 'Subitem' ,
209
+ str :'substring'
210
+ }
211
+ } ) ;
212
+
213
+ obj . attributes = {
214
+ items : [ subobj , subobj ]
215
+ } ;
216
+ expect ( encode ( obj ) ) . toEqual ( {
217
+ __type : 'Object' ,
218
+ className : 'Item' ,
219
+ items : [ {
220
+ __type : 'Object' ,
221
+ className : 'Subitem' ,
222
+ str :'substring'
223
+ } , {
224
+ __type : 'Object' ,
225
+ className : 'Subitem' ,
226
+ str :'substring'
227
+ } ]
228
+ } ) ;
229
+ } ) ;
230
+
170
231
it ( 'does not encode ParseObjects when they are disallowed' , ( ) => {
171
232
const obj = new ParseObject ( 'Item' ) ;
172
233
expect ( encode . bind ( null , obj , true ) ) . toThrow (
0 commit comments