Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(callFirestore): prevent coercing 0 values (#1039) #1058

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions src/firebase-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ export function isDocPath(slashPath: string): boolean {
}

/**
*
* @param ref
* @param whereSetting
* @param firestoreStatics
* Apply where setting to reference
* @param ref - Reference
* @param whereSetting - Where options
* @param firestoreStatics - Firestore statics
* @returns Refere with where applied
*/
export function applyWhere(
ref: firestore.CollectionReference | firestore.Query,
Expand Down
12 changes: 8 additions & 4 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ export function convertValueToTimestampOrGeoPointIfPossible(
}
/* eslint-enable no-underscore-dangle */
if (
typeof (dataVal && dataVal.seconds) === 'number' &&
typeof (dataVal && dataVal.nanoseconds) === 'number'
typeof dataVal !== 'undefined' &&
dataVal !== null &&
typeof dataVal.seconds === 'number' &&
typeof dataVal.nanoseconds === 'number'
) {
return new firestoreStatics.Timestamp(dataVal.seconds, dataVal.nanoseconds);
}
if (
typeof (dataVal && dataVal.latitude) === 'number' &&
typeof (dataVal && dataVal.longitude) === 'number'
typeof dataVal !== 'undefined' &&
dataVal !== null &&
typeof dataVal.latitude === 'number' &&
typeof dataVal.longitude === 'number'
) {
return new firestoreStatics.GeoPoint(dataVal.latitude, dataVal.longitude);
}
Expand Down
5 changes: 3 additions & 2 deletions test/unit/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ describe('tasks', () => {
expect(result).to.have.property('some', extraVal.some);
});

it('sets a document with null data', async () => {
const extraVal = { some: 'other', another: null };
it('sets a document with object containing null and 0', async () => {
const extraVal = { some: 'other', another: null, zeroField: 0 };
await tasks.callFirestore(
adminApp,
'set',
Expand All @@ -311,6 +311,7 @@ describe('tasks', () => {
expect(result).to.have.property('name', testProject.name);
expect(result).to.have.property('some', extraVal.some);
expect(result).to.have.property('another', null);
expect(result).to.have.property('zeroField', 0);
});

describe('with timestamps', () => {
Expand Down