Last active
July 18, 2021 14:43
-
-
Save danahartweg/ff6a0fcebf6197980a9b8645cee64958 to your computer and use it in GitHub Desktop.
Create user Cloud Function test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { auth, initializeApp } from 'firebase-admin'; | |
import { waitForCloudFunctionExecution } from '@helpers/wait'; | |
import { AdminFirestore } from '@test-helpers/types'; | |
import { Collections } from '@test-helpers/constants'; | |
import { getAdminApp, setup, teardown } from '@test-helpers/firestore'; | |
describe('create', () => { | |
const email = '[email protected]'; | |
const displayName = 'Test User'; | |
let db: AdminFirestore; | |
beforeAll(async () => { | |
await setup(); | |
initializeApp(); | |
await auth().createUser({ displayName, email }); | |
await auth().createUser({}); | |
db = getAdminApp().firestore(); | |
return waitForCloudFunctionExecution(); | |
}); | |
afterAll(teardown); | |
test('creates a user record with supplied data', async () => { | |
const userDocuments = await db | |
.collection(Collections.Users) | |
.where('displayName', '==', displayName) | |
.get(); | |
const [newUserDocument] = userDocuments.docs; | |
expect(newUserDocument.data()).toEqual({ | |
displayName, | |
email, | |
homesteads: {}, | |
}); | |
}); | |
test('creates a user record with fallback data', async () => { | |
const userDocuments = await db | |
.collection(Collections.Users) | |
.where('displayName', '==', '') | |
.get(); | |
const [newUserDocument] = userDocuments.docs; | |
expect(newUserDocument.data()).toEqual({ | |
displayName: '', | |
email: '', | |
homesteads: {}, | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment