1
1
import * as admin from "firebase-admin" ;
2
2
import { initializeApp } from "firebase/app" ;
3
- import { createUserWithEmailAndPassword , getAuth , UserCredential } from "firebase/auth" ;
3
+ import {
4
+ createUserWithEmailAndPassword ,
5
+ signInWithEmailAndPassword ,
6
+ getAuth ,
7
+ UserCredential ,
8
+ } from "firebase/auth" ;
4
9
import { initializeFirebase } from "../firebaseSetup" ;
5
10
import { retry } from "../utils" ;
6
11
7
12
describe ( "Firebase Auth (v1)" , ( ) => {
8
13
const userIds : string [ ] = [ ] ;
9
14
const projectId = process . env . PROJECT_ID || "functions-integration-tests" ;
10
15
const testId = process . env . TEST_RUN_ID ;
16
+ const deployedFunctions = process . env . DEPLOYED_FUNCTIONS ?. split ( "," ) || [ ] ;
11
17
12
18
if ( ! testId ) {
13
19
throw new Error ( "Environment configured incorrectly." ) ;
@@ -17,13 +23,15 @@ describe("Firebase Auth (v1)", () => {
17
23
let config ;
18
24
try {
19
25
// Try to load from test-config.json first
20
- config = require ( ' ../../test-config.json' ) ;
26
+ config = require ( " ../../test-config.json" ) ;
21
27
config . projectId = config . projectId || projectId ;
22
28
} catch {
23
29
// Fall back to environment variables
24
30
const apiKey = process . env . FIREBASE_API_KEY ;
25
31
if ( ! apiKey ) {
26
- console . warn ( "Skipping Auth tests: No test-config.json found and FIREBASE_API_KEY not configured" ) ;
32
+ console . warn (
33
+ "Skipping Auth tests: No test-config.json found and FIREBASE_API_KEY not configured"
34
+ ) ;
27
35
test . skip ( "Auth tests require Firebase client SDK configuration" , ( ) => { } ) ;
28
36
return ;
29
37
}
@@ -161,6 +169,11 @@ describe("Firebase Auth (v1)", () => {
161
169
let loggedContext : admin . firestore . DocumentData | undefined ;
162
170
163
171
beforeAll ( async ( ) => {
172
+ if ( ! deployedFunctions . includes ( "beforeCreate" ) ) {
173
+ console . log ( "⏭️ Skipping beforeCreate tests - function not deployed in this suite" ) ;
174
+ return ;
175
+ }
176
+
164
177
const auth = getAuth ( app ) ;
165
178
userCredential = await createUserWithEmailAndPassword (
166
179
auth ,
@@ -184,14 +197,26 @@ describe("Firebase Auth (v1)", () => {
184
197
} ) ;
185
198
186
199
it ( "should have the correct eventType" , ( ) => {
200
+ if ( ! deployedFunctions . includes ( "beforeCreate" ) ) {
201
+ pending ( "beforeCreate function not deployed in this suite" ) ;
202
+ return ;
203
+ }
187
204
expect ( loggedContext ?. eventType ) . toEqual ( "providers/cloud.auth/eventTypes/user.beforeCreate" ) ;
188
205
} ) ;
189
206
190
207
it ( "should have an eventId" , ( ) => {
208
+ if ( ! deployedFunctions . includes ( "beforeCreate" ) ) {
209
+ pending ( "beforeCreate function not deployed in this suite" ) ;
210
+ return ;
211
+ }
191
212
expect ( loggedContext ?. eventId ) . toBeDefined ( ) ;
192
213
} ) ;
193
214
194
215
it ( "should have a timestamp" , ( ) => {
216
+ if ( ! deployedFunctions . includes ( "beforeCreate" ) ) {
217
+ pending ( "beforeCreate function not deployed in this suite" ) ;
218
+ return ;
219
+ }
195
220
expect ( loggedContext ?. timestamp ) . toBeDefined ( ) ;
196
221
} ) ;
197
222
} ) ;
@@ -202,6 +227,11 @@ describe("Firebase Auth (v1)", () => {
202
227
let loggedContext : admin . firestore . DocumentData | undefined ;
203
228
204
229
beforeAll ( async ( ) => {
230
+ if ( ! deployedFunctions . includes ( "beforeSignIn" ) ) {
231
+ console . log ( "⏭️ Skipping beforeSignIn tests - function not deployed in this suite" ) ;
232
+ return ;
233
+ }
234
+
205
235
userRecord = await admin . auth ( ) . createUser ( {
206
236
email : `${ testId } @beforesignin.com` ,
207
237
password : "secret456" ,
@@ -210,7 +240,8 @@ describe("Firebase Auth (v1)", () => {
210
240
userIds . push ( userRecord . uid ) ;
211
241
212
242
const auth = getAuth ( app ) ;
213
- userCredential = await createUserWithEmailAndPassword (
243
+ // Fix: Use signInWithEmailAndPassword instead of createUserWithEmailAndPassword
244
+ userCredential = await signInWithEmailAndPassword (
214
245
auth ,
215
246
`${ testId } @beforesignin.com` ,
216
247
"secret456"
@@ -231,15 +262,27 @@ describe("Firebase Auth (v1)", () => {
231
262
} ) ;
232
263
233
264
it ( "should have the correct eventType" , ( ) => {
265
+ if ( ! deployedFunctions . includes ( "beforeSignIn" ) ) {
266
+ pending ( "beforeSignIn function not deployed in this suite" ) ;
267
+ return ;
268
+ }
234
269
expect ( loggedContext ?. eventType ) . toEqual ( "providers/cloud.auth/eventTypes/user.beforeSignIn" ) ;
235
270
} ) ;
236
271
237
272
it ( "should have an eventId" , ( ) => {
273
+ if ( ! deployedFunctions . includes ( "beforeSignIn" ) ) {
274
+ pending ( "beforeSignIn function not deployed in this suite" ) ;
275
+ return ;
276
+ }
238
277
expect ( loggedContext ?. eventId ) . toBeDefined ( ) ;
239
278
} ) ;
240
279
241
280
it ( "should have a timestamp" , ( ) => {
281
+ if ( ! deployedFunctions . includes ( "beforeSignIn" ) ) {
282
+ pending ( "beforeSignIn function not deployed in this suite" ) ;
283
+ return ;
284
+ }
242
285
expect ( loggedContext ?. timestamp ) . toBeDefined ( ) ;
243
286
} ) ;
244
287
} ) ;
245
- } ) ;
288
+ } ) ;
0 commit comments