【问题标题】:Unit testing firebase admin SDK authentication on node.JS在 node.JS 上对 firebase admin SDK 身份验证进行单元测试
【发布时间】:2020-07-29 23:15:26
【问题描述】:

有什么方法可以编写用于 Firebase 身份验证的单元测试以在本地存储?我想做一些类似 mongodb-memory-server 的事情,所以当测试结束时,所有保存的数据都不会保留。我想专门为这两个函数创建一些测试:

async function createResearcherOnFirebase(email, password) {
  return admin.auth().createUser({
    email,
    password,
  }).then((researcherRecord) => researcherRecord.uid).catch(() => false);
}


async function grantResearcherRole(uid) {
  return admin.auth().setCustomUserClaims(uid, { researcher: true })
    .then(() => true).catch(() => false);
}

【问题讨论】:

    标签: node.js firebase firebase-authentication jestjs firebase-admin


    【解决方案1】:

    虽然对于某些 Firebase 产品,现在有一个 emulator suite,您可以在本地针对此类用例运行,但目前还没有 Firebase 身份验证。

    如果你不想打真正的项目,你将不得不模拟服务并注入它。

    【讨论】:

    猜你喜欢
    • 2020-07-25
    • 1970-01-01
    • 2019-09-01
    • 2019-07-09
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    相关资源
    最近更新 更多