You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two seemingly identical GeoPoint types are provided from firebase-admin (for production) and @firebase/testing (for testing). The two GeoPoints are not compatible - we
can't put a firebase-admin GeoPoint in a @firebase/testing database and vice
versa.
Trying to place a firebase-admin GeoPoint into a test Firestore database created with @firebase/testing results in the error:
Error [FirebaseError]: Function DocumentReference.set() called with invalid data. Unsupported field value: a custom object (found in field home in document some/location)
A bit of manual type introspection (with util.inspect) reveals that the internal structure of these GeoPoint types differs, but ideally these would be compatible. For example, consider a GeoPoint at latitude 10, longitude 10.
@firebase/testing Geopoint:
GeoPoint { _lat: 10, _long: 10 }
firebase-admin GeoPoint:
GeoPoint { _latitude: 10, _longitude: 10 }
This is an issue because it means that existing models and functions that we would like to test (that only accept firebase-admin GeoPoints) will fail when we try to add them to the database.
Steps to reproduce:
Create a test Firestore database with @firebase/testing.
Try to insert a GeoPoint created from firebase-admin into the test database.
The operation fails with the error message provided above.
Relevant Code:
import*asfirebasefrom"@firebase/testing";import{firestoreasfirebaseAdminFirestore}from"firebase-admin";import"mocha";import{assert}from"chai";constmakeDocReferencesIfNeeded=(data)=>{for(constdocPathindata){constdoc=data[docPath];for(constkeyindoc){constvalue=doc[key];if(typeofvalue==="string"&&value.startsWith("path:/")){doc[key]=current.admin.doc(value.substr(5));}}}};describe("GeoPoint",async()=>{it("can set a 'firebase-admin' geopoint in the database",async()=>{constadmin=firebase.initializeAdminApp({projectId: "some-project-id",});constdb=admin.firestore();constgeopoint=newfirebaseAdminFirestore.GeoPoint(10,10);constutil=require("util");console.log(util.inspect(geopoint));constmockDatabase={};mockDatabase["some/location"]={home: geopoint,};makeDocReferencesIfNeeded(mockDatabase);try{for(constkeyinmockDatabase){// all we need is to set data without errorconstref=admin.doc(key);awaitref.set(mockDatabase[key]);}assert.ok(true);}catch(error){console.error(error);assert.fail();}});});
The text was updated successfully, but these errors were encountered:
Apologies for the confusion, but the firebase-admin and @firebase/testing types are not meant to be compatible. See discussion and how to adjust your tests in a prior issue on this topic.
The TL;DR on this is:
@firebase/testing is intended to be used for testing security rules only
Just connect to the emulator directly when testing admin SDK code
The underlying problem is that @firebase/testing is based on the Web SDK, but you're exercising the Admin SDK. Though these interfaces look similar they're actually different implementations and have incompatible types.
Thanks for the info, this is unfortunate that this is the case though. It makes testing security rules with existing TypeScript data models a tad more difficult.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Two seemingly identical GeoPoint types are provided from
firebase-admin
(for production) and@firebase/testing
(for testing). The two GeoPoints are not compatible - wecan't put a
firebase-admin
GeoPoint in a@firebase/testing
database and viceversa.
Trying to place a
firebase-admin
GeoPoint into a test Firestore database created with@firebase/testing
results in the error:A bit of manual type introspection (with
util.inspect
) reveals that the internal structure of these GeoPoint types differs, but ideally these would be compatible. For example, consider a GeoPoint at latitude 10, longitude 10.@firebase/testing
Geopoint:firebase-admin
GeoPoint:This is an issue because it means that existing models and functions that we would like to test (that only accept
firebase-admin
GeoPoints) will fail when we try to add them to the database.Steps to reproduce:
Create a test Firestore database with
@firebase/testing
.Try to insert a GeoPoint created from
firebase-admin
into the test database.The operation fails with the error message provided above.
Relevant Code:
The text was updated successfully, but these errors were encountered: