Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions kits/firestore-incremental-capture/tests/wire-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,76 @@ describe("changelog wire format", () => {
});
});

test("tags a null array element as 'null'", () => {
// Not `{ type: "object" }`: the original extension tagged null elements
// with `typeof null`, which the pipeline cannot tell from a map.
expect(serializeDocument({ arrayValue: [null] })).toEqual({
arrayValue: {
type: "array",
value: [{ type: "null", value: null }],
},
});
});

test("tags a Buffer, DocumentReference or Timestamp array element", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this covers Buffer, DocumentReference and Timestamp, which leaves GeoPoint as the only type in serializeArrayElement's exclusion list with no element-level test. It would fit in this assertion alongside the other three.

It does look load-bearing. Dropping !(element instanceof GeoPoint) && from the guard keeps all 15 wire-format tests and the whole kit suite green, while a GeoPoint sitting directly in an array changes from { type: "geopoint", value: { latitude: ..., longitude: ... } } to a bare field map. Under the isTaggedValue rule that bare shape reads as a field map, so it would restore as a two-key map rather than a GeoPoint. The pipeline side pins the case already as geopointArrayElement.

const timestampValue = Timestamp.fromDate(
new Date("2026-01-02T03:04:05.000Z")
);

expect(
serializeDocument({
arrayValue: [Buffer.from("hi"), ref, timestampValue],
})
).toEqual({
arrayValue: {
type: "array",
value: [
{ type: "binary", value: "aGk=" },
{ type: "reference", value: "products/abc" },
{ type: "timestamp", value: "2026-01-02T03:04:05.000Z" },
],
},
});
});

test("tags a nested array element as 'array'", () => {
expect(serializeDocument({ arrayValue: [["a", 1]] })).toEqual({
arrayValue: {
type: "array",
value: [
{
type: "array",
value: [
{ type: "string", value: "a" },
{ type: "number", value: 1 },
],
},
],
},
});
});

test("keeps a map element's own 'type' key distinct from a type tag", () => {
// The pipeline reads an element as a tagged value only when its `type` is
// a string. A user map's `type` field is serialized to an object, so a map
// element carrying `type` and `value` keys stays unambiguous.
const serialized = serializeDocument({
arrayValue: [{ type: "invoice", value: 10 }],
});

expect(serialized).toEqual({
arrayValue: {
type: "array",
value: [
{
type: { type: "string", value: "invoice" },
value: { type: "number", value: 10 },
},
],
},
});
});

test("base64-encodes a Buffer", () => {
expect(serializeDocument({ binaryValue: Buffer.from("hi") })).toEqual({
binaryValue: { type: "binary", value: "aGk=" },
Expand Down
Loading