Ailton Sávio
Ailton Sávio

Reputation: 11

Unit testing firebase admin SDK authentication on node.JS

Is there any way I can write unit tests for firebase authentication to store locally? I want to do something like mongodb-memory-server, so all the data saved doesn't persists when the tests are over. I want to create some tests to those two functions specifically:

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);
}

Upvotes: 0

Views: 1540

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598623

While for some Firebase products there is now an emulator suite that you can run locally for precisely such use-cases, Firebase Authentication is currently not in there.

If you don't want to hit the real project, you will have to mock the service and inject it.

Upvotes: 2

Related Questions