@@ -25,201 +25,6 @@ import * as typeUtils from '../../../src/util/types';
25
25
import { blob , field , mask , wrap , wrapObject } from '../../util/helpers' ;
26
26
27
27
describe ( 'FieldValue' , ( ) => {
28
- const date1 = new Date ( 2016 , 4 , 2 , 1 , 5 ) ;
29
- const date2 = new Date ( 2016 , 5 , 20 , 10 , 20 , 30 ) ;
30
-
31
- // TODO(mrschmidt): Move to values test
32
- it ( 'can parse integers' , ( ) => {
33
- const primitiveValues = [
34
- typeUtils . MIN_SAFE_INTEGER ,
35
- - 1 ,
36
- 0 ,
37
- 1 ,
38
- 2 ,
39
- typeUtils . MAX_SAFE_INTEGER
40
- ] ;
41
- const values = primitiveValues . map ( v => wrap ( v ) ) ;
42
-
43
- values . forEach ( v => {
44
- expect ( typeOrder ( v ) ) . to . equal ( TypeOrder . NumberValue ) ;
45
- } ) ;
46
-
47
- for ( let i = 0 ; i < primitiveValues . length ; i ++ ) {
48
- const primitiveValue = primitiveValues [ i ] ;
49
- const value = values [ i ] ;
50
- expect ( value ) . to . deep . equal ( { integerValue : `${ primitiveValue } ` } ) ;
51
- }
52
- } ) ;
53
-
54
- it ( 'can parse doubles' , ( ) => {
55
- const primitiveValues = [
56
- typeUtils . MIN_SAFE_INTEGER - 1 ,
57
- - 1.1 ,
58
- 0.1 ,
59
- typeUtils . MAX_SAFE_INTEGER + 1 ,
60
- NaN ,
61
- Infinity ,
62
- - Infinity
63
- ] ;
64
- const values = primitiveValues . map ( v => wrap ( v ) ) ;
65
-
66
- values . forEach ( v => {
67
- expect ( typeOrder ( v ) ) . to . equal ( TypeOrder . NumberValue ) ;
68
- } ) ;
69
-
70
- for ( let i = 0 ; i < primitiveValues . length ; i ++ ) {
71
- const primitiveValue = primitiveValues [ i ] ;
72
- const value = values [ i ] ;
73
- if ( isNaN ( primitiveValue ) ) {
74
- expect ( value ) . to . deep . equal ( { doubleValue : 'NaN' } ) ;
75
- } else if ( primitiveValue === Infinity ) {
76
- expect ( value ) . to . deep . equal ( { doubleValue : 'Infinity' } ) ;
77
- } else if ( primitiveValue === - Infinity ) {
78
- expect ( value ) . to . deep . equal ( { doubleValue : '-Infinity' } ) ;
79
- } else {
80
- expect ( value ) . to . deep . equal ( { doubleValue : primitiveValue } ) ;
81
- }
82
- }
83
- } ) ;
84
-
85
- it ( 'can parse null' , ( ) => {
86
- const nullValue = wrap ( null ) ;
87
-
88
- expect ( typeOrder ( nullValue ) ) . to . equal ( TypeOrder . NullValue ) ;
89
- expect ( nullValue ) . to . deep . equal ( { nullValue : 'NULL_VALUE' } ) ;
90
- } ) ;
91
-
92
- it ( 'can parse booleans' , ( ) => {
93
- const trueValue = wrap ( true ) ;
94
- const falseValue = wrap ( false ) ;
95
-
96
- expect ( typeOrder ( trueValue ) ) . to . equal ( TypeOrder . BooleanValue ) ;
97
- expect ( typeOrder ( falseValue ) ) . to . equal ( TypeOrder . BooleanValue ) ;
98
-
99
- expect ( trueValue ) . to . deep . equal ( { booleanValue : true } ) ;
100
- expect ( falseValue ) . to . deep . equal ( { booleanValue : false } ) ;
101
- } ) ;
102
-
103
- it ( 'can parse dates' , ( ) => {
104
- const dateValue1 = wrap ( date1 ) ;
105
- const dateValue2 = wrap ( date2 ) ;
106
-
107
- expect ( typeOrder ( dateValue1 ) ) . to . equal ( TypeOrder . TimestampValue ) ;
108
- expect ( typeOrder ( dateValue2 ) ) . to . equal ( TypeOrder . TimestampValue ) ;
109
-
110
- expect ( dateValue1 ) . to . deep . equal ( {
111
- timestampValue : { seconds : 1462176300 , nanos : 0 }
112
- } ) ;
113
- expect ( dateValue2 ) . to . deep . equal ( {
114
- timestampValue : { seconds : 1466443230 , nanos : 0 }
115
- } ) ;
116
- } ) ;
117
-
118
- it ( 'can parse geo points' , ( ) => {
119
- const latLong1 = new GeoPoint ( 1.23 , 4.56 ) ;
120
- const latLong2 = new GeoPoint ( - 20 , 100 ) ;
121
- const value1 = wrap ( latLong1 ) ;
122
- const value2 = wrap ( latLong2 ) ;
123
-
124
- expect ( typeOrder ( value1 ) ) . to . equal ( TypeOrder . GeoPointValue ) ;
125
- expect ( typeOrder ( value2 ) ) . to . equal ( TypeOrder . GeoPointValue ) ;
126
-
127
- expect ( value1 ) . to . deep . equal ( {
128
- geoPointValue : { latitude : 1.23 , longitude : 4.56 }
129
- } ) ;
130
- expect ( value2 ) . to . deep . equal ( {
131
- geoPointValue : { latitude : - 20 , longitude : 100 }
132
- } ) ;
133
- } ) ;
134
-
135
- it ( 'can parse bytes' , ( ) => {
136
- const bytesValue = wrap ( blob ( 0 , 1 , 2 ) ) ;
137
-
138
- expect ( typeOrder ( bytesValue ) ) . to . equal ( TypeOrder . BlobValue ) ;
139
- expect ( bytesValue ) . to . deep . equal ( { bytesValue : 'AAEC' } ) ;
140
- } ) ;
141
-
142
- it ( 'can parse simple objects' , ( ) => {
143
- const objValue = wrap ( { a : 'foo' , b : 1 , c : true , d : null } ) ;
144
-
145
- expect ( typeOrder ( objValue ) ) . to . equal ( TypeOrder . ObjectValue ) ;
146
- expect ( objValue ) . to . deep . equal ( {
147
- 'mapValue' : {
148
- 'fields' : {
149
- 'a' : {
150
- 'stringValue' : 'foo'
151
- } ,
152
- 'b' : {
153
- 'integerValue' : 1
154
- } ,
155
- 'c' : {
156
- 'booleanValue' : true
157
- } ,
158
- 'd' : {
159
- 'nullValue' : 'NULL_VALUE'
160
- }
161
- }
162
- }
163
- } ) ;
164
- } ) ;
165
-
166
- it ( 'can parse nested objects' , ( ) => {
167
- const objValue = wrap ( { foo : { bar : 1 , baz : [ 1 , 2 , { a : 'b' } ] } } ) ;
168
-
169
- expect ( typeOrder ( objValue ) ) . to . equal ( TypeOrder . ObjectValue ) ;
170
- expect ( objValue ) . to . deep . equal ( {
171
- 'mapValue' : {
172
- 'fields' : {
173
- 'foo' : {
174
- 'mapValue' : {
175
- 'fields' : {
176
- 'bar' : {
177
- 'integerValue' : 1
178
- } ,
179
- 'baz' : {
180
- 'arrayValue' : {
181
- 'values' : [
182
- {
183
- 'integerValue' : 1
184
- } ,
185
- {
186
- 'integerValue' : 2
187
- } ,
188
- {
189
- 'mapValue' : {
190
- 'fields' : {
191
- 'a' : {
192
- 'stringValue' : 'b'
193
- }
194
- }
195
- }
196
- }
197
- ]
198
- }
199
- }
200
- }
201
- }
202
- }
203
- }
204
- }
205
- } ) ;
206
- } ) ;
207
-
208
- it ( 'can parse empty objects' , ( ) => {
209
- const objValue = wrap ( { foo : { } } ) ;
210
-
211
- expect ( typeOrder ( objValue ) ) . to . equal ( TypeOrder . ObjectValue ) ;
212
- expect ( objValue ) . to . deep . equal ( {
213
- 'mapValue' : {
214
- 'fields' : {
215
- 'foo' : {
216
- 'mapValue' : { }
217
- }
218
- }
219
- }
220
- } ) ;
221
- } ) ;
222
-
223
28
it ( 'can extract fields' , ( ) => {
224
29
const objValue = wrapObject ( { foo : { a : 1 , b : true , c : 'string' } } ) ;
225
30
0 commit comments