Node.js 使用Firebase规则单元测试库时,如果文档具有Firestore Geopoint字段,则始终无法创建文档
我正在尝试使用模拟器使用库对我的安全规则进行测试 我有这样的活动课Node.js 使用Firebase规则单元测试库时,如果文档具有Firestore Geopoint字段,则始终无法创建文档,node.js,firebase,google-cloud-firestore,Node.js,Firebase,Google Cloud Firestore,我正在尝试使用模拟器使用库对我的安全规则进行测试 我有这样的活动课 class Event { title: string coordinate: FirebaseFirestore.GeoPoint } request.resource.data.coordinate is latlng 创建一个实例 const event = new Event("event title", new admin.firestore.GeoPoint(-6.931980,
class Event {
title: string
coordinate: FirebaseFirestore.GeoPoint
}
request.resource.data.coordinate is latlng
创建一个实例
const event = new Event("event title", new admin.firestore.GeoPoint(-6.931980, 107.559540))
然后我用Mocha编写了这样的安全规则测试
import * as firebase from "@firebase/rules-unit-testing";
function getFirestore(auth?: TokenOptions) {
return firebase.initializeTestApp({projectId: projectID, auth: auth}).firestore();
}
it("should create an event document", async () => {
const db = getFirestore(myAuth);
const ref = db.collection("events").doc("myEvent");
const event = new Event("event title", new admin.firestore.GeoPoint(-6.931980, 107.559540))
const eventData = { ...event};
const promise = ref.set(eventData);
await firebase.assertSucceeds(promise);
});
但我有错误
FirebaseError:调用函数DocumentReference.set()时无效
数据。不支持的字段值:自定义对象(在字段中找到
协调文档中的事件/myEvent)
错误表示坐标属性使用自定义对象(即FirebaseFirestore.GeoPoint)
但我需要测试我的安全规则。我有这样的规定
class Event {
title: string
coordinate: FirebaseFirestore.GeoPoint
}
request.resource.data.coordinate is latlng
那么,我如何测试一个字段是否为Latling,但我无法创建一个Firestore地质点文档
这是一个bug吗?我从中找到了答案 这里的问题是web和admin SDK有单独的地理点 不可互操作的类。如果你正在使用 在初始化为etestApp()的web SDK中,您将必须访问地质点 从web SDK中初始化。在您的情况下,您需要使用web SDK的 地质点类别: 因此,我必须改变创建地质点数据的方式。从
new admin.firestore.GeoPoint(-6.931980, 107.559540)
将来