我正在玩新的 firebase auth 模拟器(在节点管理 SDK 上),并且做了一些测试,如果我在每次测试之间手动删除创建的用户,这些测试可以完美运行,但我似乎无法自动删除它们?
我已经在我的 beforeEach() 中使用了此处定义的端点,但是我从响应调用中得到了“响应代码 401,未经授权”?
端点:删除: http://localhost:9099/emulator/v1/projects/{project-id}/accounts
我只是尝试使用 Postman 发送电话,它的回复如下:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
Run Code Online (Sandbox Code Playgroud)
除了向网络应用程序添加一个谷歌按钮之外,错误中的 URL 似乎没有给我太多帮助,这使我指向创建一个 OAuth2 网络帐户。我在现有的 localhost:9099 中输入了 localhost:9099,但不知道应该在哪里使用客户端 ID 和客户端密码?如果它们是我应该使用的。
我知道我需要某种用于删除调用的 Authorization 标头,但我只是不知道应该在该标头中放入什么,或者如何放入。
感谢您对此有任何了解。
编辑:我现在尝试了以下授权标头:
“行政”
""(空字符串) …
我正在编写一个应用程序,其后端编写为节点/express 服务器,通过 firebase 功能上的 Admin SDK 运行 firestore 命令。我想知道测试数据库功能的最佳方法是什么。此类函数的示例如下:
export const deleteDocument = async(id: string): Promise<void> => {
try {
await firestore.collection("sampleCollection").doc(id).delete();
} catch (e) {
throw new Error(`Could not delete ${id}`);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想运行一个像这样的单元测试(我知道这里的实际逻辑有点奇怪,但它是即时完成的,并不是问题的重点):
it('should delete a document from the sample collection', async () => {
//This would already be tested
const id = await createDocument(...);
if (id !== undefined) {
await deleteDocument(id);
try {
await getCollective(id);
expect(true).toBe(false);
} catch (e) {
expect(true).toBe(true);
}
} else {
expect(id).toBeDefined();
} …Run Code Online (Sandbox Code Playgroud) firebase typescript jestjs google-cloud-firestore firebase-cli
chai.require("server.js")我正在尝试运行一些客户端测试,这些测试连接到我用来设置的服务器上的端点。这在我的本地计算机上有效,但是当我尝试在 GitLab CI 上运行它时,它失败并说它无法在 server.js 文件中找到模块,即使它们存在于 node_modules 中(我打印了这些,并检查了确切的它要求的一个)。我还移动了 server.js 中的 require-s,它总是在第一个上失败/在所有上都失败。
这是我的 package.json 文件的相关部分
{
"name": "client",
"version": "0.1.0",
"private": true
"dependencies": {
"axios": "^0.19.1",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"esm": "^3.2.25",
"mocha": "^7.0.0",
"mysql": "^2.17.1"
"react-scripts": "3.3.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"install": "^0.13.0",
"jest": "^24.9.0",
"node": "^13.5.0",
"npm": "^6.13.4",
"require": "^2.4.20"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "mocha --require esm \"src/**/*.test.js\"",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 android studio 模拟器(Pixel 4 API 29)上的 React Native(0.63.3)上使用新的 firebase 身份验证模拟器。在最新的重大更新react-native-firebase(V 10.0.0)中,添加了对此的支持,我可以在包中看到函数和类型定义node-modules。但是当我尝试使用该函数时,它根本没有在对象上定义。许多其他函数已定义并按预期工作(在生产数据上),但不是该useEmulator函数。我尝试了几种访问该对象的方法:
直接导入:
import app from "@react-native-firebase/app";
import auth from "@react-native-firebase/auth";
app.initializeApp(...);
console.log(auth().useEmulator);
Run Code Online (Sandbox Code Playgroud)
像这样导入模块:
import app from "@react-native-firebase/app"
import "@react-native-firebase/auth";
const auth = app.auth();
console.log(auth.useEmulator);
Run Code Online (Sandbox Code Playgroud)
他们都记录了undefined。如果我能得到一些关于如何让它发挥作用的提示,我将不胜感激。与在生产数据中创建测试用户相比,在开发时访问模拟器使一切变得更加容易。和工作良好并且已定义,因此看起来 auth 函数有一些特定的内容functions.useEmulator。firestore.settings
我与这个问题相关的 npm 依赖项:
"react": "16.13.1",
"react-native": "0.63.3",
"@react-native-firebase/app": "^10.5.0",
"@react-native-firebase/auth": "^10.5.1",
"firebase": "^8.2.4",
Run Code Online (Sandbox Code Playgroud)
我的 android firebase auth 实现版本,如果有必要的话:
implementation "com.google.firebase:firebase-auth:20.0.2"
Run Code Online (Sandbox Code Playgroud) javascript react-native firebase-authentication react-native-firebase
firebase ×2
javascript ×2
chai ×1
firebase-cli ×1
gitlab ×1
gitlab-ci ×1
jestjs ×1
react-native ×1
typescript ×1