@@ -55,13 +55,26 @@ describe('Bytes', () => {
5555 expectEqual ( blob ( 1 , 2 , 3 ) , blob ( 1 , 2 , 3 ) ) ;
5656 expectNotEqual ( blob ( 1 , 2 , 3 ) , blob ( 4 , 5 , 6 ) ) ;
5757 } ) ;
58-
58+
5959 it ( 'fromJSON reconstructs the value from toJSON' , ( ) => {
60- const bytes = Bytes . fromUint8Array ( new Uint8Array ( [ 0 , 1 , 2 , 3 , 4 , 5 ] ) ) ;
61- expect ( ( ) => { Bytes . fromJSON ( bytes . toJSON ( ) ) } ) . to . not . throw ;
60+ const bytes = Bytes . fromUint8Array ( new Uint8Array ( [ 0 , 1 , 2 , 3 , 4 , 5 ] ) ) ;
61+ expect ( ( ) => {
62+ Bytes . fromJSON ( bytes . toJSON ( ) ) ;
63+ } ) . to . not . throw ;
6264 expect ( Bytes . fromJSON ( bytes . toJSON ( ) ) . isEqual ( bytes ) ) . to . be . true ;
6365 } ) ;
6466
67+ it ( 'fromJSON parameter order does not matter' , ( ) => {
68+ const type = 'firestore/bytes/1.0' ;
69+ const data = 'AA==' ;
70+ expect ( ( ) => {
71+ Bytes . fromJSON ( { data, type } ) ;
72+ } ) . to . not . throw ;
73+ expect ( ( ) => {
74+ Bytes . fromJSON ( { type, data } ) ;
75+ } ) . to . not . throw ;
76+ } ) ;
77+
6578 it ( 'toJSON -> fromJSON bytes comparison' , ( ) => {
6679 Object . keys ( base64Mappings ) . forEach ( base64Str => {
6780 const bytesToSerialize = Bytes . fromBase64String ( base64Str ) ;
@@ -74,12 +87,20 @@ describe('Bytes', () => {
7487 expect ( actualUint8Array [ i ] ) . to . equal ( expectedUint8Array [ i ] ) ;
7588 }
7689 } ) ;
77- } )
90+ } ) ;
7891
7992 it ( 'fromJSON misisng fields throws' , ( ) => {
80- expect ( ( ) => { Bytes . fromJSON ( { type : 'firestore/bytes/1.0' /* missing data */ } ) } ) . to . throw ;
81- expect ( ( ) => { Bytes . fromJSON ( { data : 'AA==' /* missing type */ } ) } ) . to . throw ;
82- expect ( ( ) => { Bytes . fromJSON ( { type : 1 , data : 'AA==' } ) } ) . to . throw ;
83- expect ( ( ) => { Bytes . fromJSON ( { type : 'firestore/bytes/1.0' , data : 1 } ) } ) . to . throw ;
93+ expect ( ( ) => {
94+ Bytes . fromJSON ( { type : 'firestore/bytes/1.0' /* missing data */ } ) ;
95+ } ) . to . throw ;
96+ expect ( ( ) => {
97+ Bytes . fromJSON ( { data : 'AA==' /* missing type */ } ) ;
98+ } ) . to . throw ;
99+ expect ( ( ) => {
100+ Bytes . fromJSON ( { type : 1 , data : 'AA==' } ) ;
101+ } ) . to . throw ;
102+ expect ( ( ) => {
103+ Bytes . fromJSON ( { type : 'firestore/bytes/1.0' , data : 1 } ) ;
104+ } ) . to . throw ;
84105 } ) ;
85106} ) ;
0 commit comments