@@ -78,7 +78,13 @@ describe('Serializer', () => {
78
78
const s = new JsonProtoSerializer ( partition , { useProto3Json : false } ) ;
79
79
const emptyResumeToken = new Uint8Array ( 0 ) ;
80
80
const protos = loadRawProtos ( ) ;
81
- const ds = protos [ 'google' ] [ 'firestore' ] [ 'v1' ] ;
81
+
82
+ // tslint:disable:variable-name
83
+ const ValueMessage = protos . lookupType ( 'google.firestore.v1.Value' ) ;
84
+ const LatLngMessage = protos . lookupType ( 'google.type.LatLng' ) ;
85
+ const TimestampMessage = protos . lookupType ( 'google.protobuf.Timestamp' ) ;
86
+ const MapValueMessage = protos . lookupType ( 'google.firestore.v1.MapValue' ) ;
87
+ // tslint:enable:variable-name
82
88
83
89
/**
84
90
* Wraps the given query in QueryData. This is useful because the APIs we're
@@ -100,9 +106,9 @@ describe('Serializer', () => {
100
106
/**
101
107
* Verifies that the given object can be parsed as a datastore Value proto.
102
108
*/
103
- function expectValue ( obj : unknown , tag : string ) : Chai . Assertion {
104
- const proto = new ds . Value ( obj ) ;
105
- expect ( proto . value_type ) . to . equal ( tag ) ;
109
+ function expectValue ( obj : api . Value , tag : string ) : Chai . Assertion {
110
+ const proto = ValueMessage . fromObject ( obj ) ;
111
+ expect ( proto [ 'valueType' ] ) . to . equal ( tag ) ;
106
112
return expect ( proto [ tag ] ) ;
107
113
}
108
114
@@ -207,7 +213,7 @@ describe('Serializer', () => {
207
213
const expected = { timestampValue : expectedJson [ i ] } ;
208
214
expect ( obj ) . to . deep . equal ( expected ) ;
209
215
expectValue ( obj , 'timestampValue' ) . to . deep . equal (
210
- new protos [ 'google' ] [ 'protobuf' ] . Timestamp ( expectedJson [ i ] ) ,
216
+ TimestampMessage . fromObject ( expectedJson [ i ] ) ,
211
217
'for date ' + example
212
218
) ;
213
219
}
@@ -226,7 +232,7 @@ describe('Serializer', () => {
226
232
const obj = s . toValue ( new fieldValue . GeoPointValue ( example ) ) ;
227
233
expect ( obj ) . to . deep . equal ( expected ) ;
228
234
expectValue ( obj , 'geoPointValue' ) . to . deep . equal (
229
- new protos [ 'google' ] [ 'type' ] . LatLng ( 1.23 , 4.56 )
235
+ LatLngMessage . fromObject ( expected . geoPointValue )
230
236
) ;
231
237
} ) ;
232
238
@@ -273,7 +279,9 @@ describe('Serializer', () => {
273
279
const obj = s . toValue ( fieldValue . ObjectValue . EMPTY ) ;
274
280
expect ( obj ) . to . deep . equal ( { mapValue : { fields : { } } } ) ;
275
281
276
- expectValue ( obj , 'mapValue' ) . to . deep . equal ( new ds . MapValue ( ) ) ;
282
+ expectValue ( obj , 'mapValue' ) . to . deep . equal (
283
+ MapValueMessage . fromObject ( { } )
284
+ ) ;
277
285
} ) ;
278
286
279
287
it ( 'converts nested ObjectValues' , ( ) => {
@@ -340,11 +348,8 @@ describe('Serializer', () => {
340
348
const obj = s . toValue ( objValue ) ;
341
349
expect ( obj ) . to . deep . equal ( expectedJson ) ;
342
350
343
- // Compare the raw object representation rather than the Message because
344
- // occasionally Jasmine will hang trying to generate the string form in
345
- // the event of an inequality.
346
- expect ( new ds . Value ( obj ) . toRaw ( true , true ) ) . to . deep . equal (
347
- new ds . Value ( expectedJson ) . toRaw ( true , true )
351
+ expectValue ( obj , 'mapValue' ) . to . deep . equal (
352
+ MapValueMessage . fromObject ( expectedJson . mapValue )
348
353
) ;
349
354
// clang-format on
350
355
} ) ;
@@ -355,15 +360,17 @@ describe('Serializer', () => {
355
360
356
361
it ( 'converts NullValue' , ( ) => {
357
362
const proto : api . Value = { nullValue : 'NULL_VALUE' } ;
358
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'nullValue' ) ;
363
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal ( 'nullValue' ) ;
359
364
expect ( s . fromValue ( proto ) ) . to . equal ( fieldValue . NullValue . INSTANCE ) ;
360
365
} ) ;
361
366
362
367
it ( 'converts BooleanValue' , ( ) => {
363
368
const examples = [ true , false ] ;
364
369
for ( const example of examples ) {
365
370
const proto = { booleanValue : example } ;
366
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'booleanValue' ) ;
371
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
372
+ 'booleanValue'
373
+ ) ;
367
374
expect ( s . fromValue ( proto ) ) . to . deep . equal (
368
375
fieldValue . BooleanValue . of ( example )
369
376
) ;
@@ -382,7 +389,9 @@ describe('Serializer', () => {
382
389
] ;
383
390
for ( const example of examples ) {
384
391
const proto : api . Value = { integerValue : '' + example } ;
385
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'integerValue' ) ;
392
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
393
+ 'integerValue'
394
+ ) ;
386
395
expect ( s . fromValue ( proto ) ) . to . deep . equal (
387
396
new fieldValue . IntegerValue ( example )
388
397
) ;
@@ -404,7 +413,9 @@ describe('Serializer', () => {
404
413
] ;
405
414
for ( const example of examples ) {
406
415
const proto = { doubleValue : example } ;
407
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'doubleValue' ) ;
416
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
417
+ 'doubleValue'
418
+ ) ;
408
419
expect ( s . fromValue ( proto ) ) . to . deep . equal (
409
420
new fieldValue . DoubleValue ( example )
410
421
) ;
@@ -422,7 +433,9 @@ describe('Serializer', () => {
422
433
] ;
423
434
for ( const example of examples ) {
424
435
const proto = { stringValue : example } ;
425
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'stringValue' ) ;
436
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
437
+ 'stringValue'
438
+ ) ;
426
439
expect ( s . fromValue ( proto ) ) . to . deep . equal (
427
440
new fieldValue . StringValue ( example )
428
441
) ;
@@ -433,7 +446,9 @@ describe('Serializer', () => {
433
446
const proto = {
434
447
arrayValue : { values : [ { booleanValue : true } , { stringValue : 'foo' } ] }
435
448
} ;
436
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'arrayValue' ) ;
449
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
450
+ 'arrayValue'
451
+ ) ;
437
452
expect ( s . fromValue ( proto ) ) . to . deep . equal (
438
453
new fieldValue . ArrayValue ( [
439
454
fieldValue . BooleanValue . TRUE ,
@@ -444,13 +459,17 @@ describe('Serializer', () => {
444
459
445
460
it ( 'converts empty ArrayValue' , ( ) => {
446
461
const proto = { arrayValue : { } } ;
447
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'arrayValue' ) ;
462
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
463
+ 'arrayValue'
464
+ ) ;
448
465
expect ( s . fromValue ( proto ) ) . to . deep . equal ( new fieldValue . ArrayValue ( [ ] ) ) ;
449
466
} ) ;
450
467
451
468
it ( 'converts ObjectValue.EMPTY' , ( ) => {
452
469
const proto = { mapValue : { fields : { } } } ;
453
- expect ( new ds . Value ( proto ) . mapValue ) . to . deep . equal ( new ds . MapValue ( ) ) ;
470
+ expect ( ValueMessage . fromObject ( proto ) [ 'mapValue' ] ) . to . deep . equal (
471
+ MapValueMessage . fromObject ( { } )
472
+ ) ;
454
473
expect ( s . fromValue ( proto ) ) . to . deep . equal ( fieldValue . ObjectValue . EMPTY ) ;
455
474
} ) ;
456
475
@@ -471,7 +490,9 @@ describe('Serializer', () => {
471
490
// because the proto interface definition isn't comprehensive.
472
491
// tslint:disable-next-line:no-any
473
492
const proto : api . Value = { timestampValue : example as any } ;
474
- expect ( new ds . Value ( proto ) . value_type ) . to . equal ( 'timestampValue' ) ;
493
+ expect ( ValueMessage . fromObject ( proto ) [ 'valueType' ] ) . to . equal (
494
+ 'timestampValue'
495
+ ) ;
475
496
expect ( s . fromValue ( proto ) ) . to . deep . equal (
476
497
new fieldValue . TimestampValue ( Timestamp . fromDate ( date ) )
477
498
) ;
0 commit comments