Skip to content

Commit ae8f6fd

Browse files
Checkpoint
1 parent 7f94c74 commit ae8f6fd

File tree

3 files changed

+30
-212
lines changed

3 files changed

+30
-212
lines changed

packages/firestore/src/util/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function isSafeInteger(value: unknown): boolean {
6767
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
6868
if (value === -0) {
6969
// +0 != -0
70-
return value !== 0 || 1 / value === 1 / -0;
70+
return 1 / value === 1 / 0;
7171
} else {
7272
return (
7373
isInteger(value) &&

packages/firestore/test/unit/model/field_value.test.ts

Lines changed: 0 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -25,201 +25,6 @@ import * as typeUtils from '../../../src/util/types';
2525
import { blob, field, mask, wrap, wrapObject } from '../../util/helpers';
2626

2727
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-
22328
it('can extract fields', () => {
22429
const objValue = wrapObject({ foo: { a: 1, b: true, c: 'string' } });
22530

packages/firestore/test/unit/remote/node/serializer.test.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {
7979
wrap,
8080
wrapObject,
8181
byteStringFromString,
82-
testUserDataWriter
82+
testUserDataWriter, blob
8383
} from '../../../util/helpers';
8484
import { ByteString } from '../../../../src/util/byte_string';
8585

@@ -107,7 +107,7 @@ describe('Serializer', () => {
107107
return new TargetData(target, 1, TargetPurpose.Listen, 2);
108108
}
109109

110-
describe('converts value', () => {
110+
describe.only('converts value', () => {
111111
addEqualityMatcher();
112112

113113
/**
@@ -130,11 +130,6 @@ describe('Serializer', () => {
130130
* the same as jsonValue.
131131
*/
132132
protobufJsValue?: unknown;
133-
/**
134-
* If true, uses the proto3Json serializer (and skips the round-trip
135-
* through protobufJs).
136-
*/
137-
useProto3Json?: boolean;
138133
}): void {
139134
const { value, valueType, jsonValue } = opts;
140135
const protobufJsValue =
@@ -147,7 +142,6 @@ describe('Serializer', () => {
147142
expect(actualJsonProto).to.deep.equal({ [valueType]: jsonValue });
148143

149144
// If we're using protobufJs JSON (not Proto3Json), then round-trip through protobufjs.
150-
if (!opts.useProto3Json) {
151145
// Convert JSON to protobufjs and verify value.
152146
const actualProtobufjsProto: ProtobufJS.Message = ValueMessage.fromObject(
153147
actualJsonProto
@@ -162,16 +156,14 @@ describe('Serializer', () => {
162156
protoLoaderOptions
163157
);
164158
expect(returnJsonProto).to.deep.equal(actualJsonProto);
165-
}
166159

167160
// Convert JSON back to value.
168161
const actualReturnFieldValue = userDataWriter.convertValue(
169162
actualJsonProto
170163
);
171164
expect(actualReturnFieldValue).to.deep.equal(value);
172165
}
173-
174-
// TODO(mrschmidt): Tests should have two modes or be removed/moved
166+
175167
it('converts NullValue', () => {
176168
verifyFieldValueRoundTrip({
177169
value: null,
@@ -218,11 +210,11 @@ describe('Serializer', () => {
218210
it('converts DoubleValue', () => {
219211
const examples = [
220212
Number.MIN_VALUE,
221-
-10.0,
222-
-1.0,
213+
-10.1,
214+
-1.1,
223215
0.0,
224-
1.0,
225-
10.0,
216+
1.1,
217+
10.1,
226218
Number.MAX_VALUE,
227219
NaN,
228220
Number.POSITIVE_INFINITY,
@@ -255,7 +247,28 @@ describe('Serializer', () => {
255247
}
256248
});
257249

258-
it('converts TimestampValue from proto', () => {
250+
it('converts Dates', () => {
251+
const examples = [
252+
new Date(Date.UTC(2016, 0, 2, 10, 20, 50, 850)),
253+
new Date(Date.UTC(2016, 5, 17, 10, 50, 15, 0))
254+
];
255+
256+
const expectedJson = [
257+
{ seconds: '1451730050', nanos: 850000000 },
258+
{ seconds: '1466160615', nanos: 0 }
259+
];
260+
261+
for (let i = 0; i < examples.length; i++) {
262+
verifyFieldValueRoundTrip({
263+
value: Timestamp.fromDate(examples[i]),
264+
valueType: 'timestampValue',
265+
jsonValue: expectedJson[i],
266+
protobufJsValue: TimestampMessage.fromObject(expectedJson[i])
267+
});
268+
}
269+
});
270+
271+
it('converts Timestamps', () => {
259272
const examples = [
260273
new Date(Date.UTC(2016, 0, 2, 10, 20, 50, 850)),
261274
new Date(Date.UTC(2016, 5, 17, 10, 50, 15, 0))

0 commit comments

Comments
 (0)