Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Firebase规则单元测试库时,如果文档具有Firestore Geopoint字段,则始终无法创建文档_Node.js_Firebase_Google Cloud Firestore - Fatal编程技术网

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)
将来