Skip to content

Commit 0fc16bd

Browse files
committed
fix(integration_tests): fix storage tests
1 parent a3f9021 commit 0fc16bd

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

integration_test_declarative/scripts/generate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ for (const suite of suites) {
155155
timestamp: new Date().toISOString(),
156156
};
157157

158+
// Debug: Log the context for storage templates
159+
if (service === "storage") {
160+
console.log(" 🔍 Debug - Template context:", JSON.stringify(context, null, 2));
161+
}
162+
158163
// Generate the test file for this suite
159164
generateFromTemplate(templatePath, `functions/src/${version}/${service}-tests.ts`, context);
160165

integration_test_declarative/scripts/run-suite.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,17 @@ echo -e "${GREEN}☁️ Step 3/4: Deploying to Firebase${NC}"
173173
echo -e "${BLUE}──────────────────────────────────────────────────────────${NC}"
174174

175175
cd "$ROOT_DIR/generated"
176-
firebase deploy --only functions --project "$PROJECT_ID" || {
176+
177+
# Source the utility functions for retry logic
178+
source "$ROOT_DIR/scripts/util.sh"
179+
180+
# Deploy with exponential backoff retry
181+
retry_with_backoff 3 30 120 600 firebase deploy --only functions --project "$PROJECT_ID" || {
177182
# Check if it's just the cleanup policy warning
178183
if firebase functions:list --project "$PROJECT_ID" 2>/dev/null | grep -q "$TEST_RUN_ID"; then
179184
echo -e "${YELLOW}⚠️ Functions deployed with warnings (cleanup policy)${NC}"
180185
else
181-
echo -e "${RED}❌ Deployment failed${NC}"
186+
echo -e "${RED}❌ Deployment failed after all retry attempts${NC}"
182187
exit 1
183188
fi
184189
}
@@ -202,6 +207,25 @@ fi
202207
# Run the tests
203208
export GOOGLE_APPLICATION_CREDENTIALS="$ROOT_DIR/sa.json"
204209

210+
# Extract deployed functions from suite names
211+
DEPLOYED_FUNCTIONS=""
212+
for SUITE_NAME in "${SUITE_NAMES[@]}"; do
213+
case "$SUITE_NAME" in
214+
v1_auth_nonblocking)
215+
DEPLOYED_FUNCTIONS="${DEPLOYED_FUNCTIONS},onCreate,onDelete"
216+
;;
217+
v1_auth_before_create)
218+
DEPLOYED_FUNCTIONS="${DEPLOYED_FUNCTIONS},beforeCreate"
219+
;;
220+
v1_auth_before_signin)
221+
DEPLOYED_FUNCTIONS="${DEPLOYED_FUNCTIONS},beforeSignIn"
222+
;;
223+
esac
224+
done
225+
226+
# Remove leading comma
227+
DEPLOYED_FUNCTIONS="${DEPLOYED_FUNCTIONS#,}"
228+
205229
# Collect test files for all suites
206230
TEST_FILES=()
207231
for SUITE_NAME in "${SUITE_NAMES[@]}"; do
@@ -267,10 +291,10 @@ for SUITE_NAME in "${SUITE_NAMES[@]}"; do
267291
done
268292

269293
if [ ${#TEST_FILES[@]} -gt 0 ]; then
270-
TEST_RUN_ID="$TEST_RUN_ID" npm test -- "${TEST_FILES[@]}"
294+
DEPLOYED_FUNCTIONS="$DEPLOYED_FUNCTIONS" TEST_RUN_ID="$TEST_RUN_ID" npm test -- "${TEST_FILES[@]}"
271295
else
272296
echo -e "${YELLOW} No test files found. Running all tests...${NC}"
273-
TEST_RUN_ID="$TEST_RUN_ID" npm test
297+
DEPLOYED_FUNCTIONS="$DEPLOYED_FUNCTIONS" TEST_RUN_ID="$TEST_RUN_ID" npm test
274298
fi
275299

276300
echo ""

integration_test_declarative/templates/functions/src/v1/storage-tests.ts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const {{name}}{{../testRunId}} = functions
1010
timeoutSeconds: {{timeout}}
1111
})
1212
.region(REGION)
13-
.storage.bucket("functions-integration-tests.firebasestorage.app")
13+
.storage.bucket("{{../projectId}}.firebasestorage.app")
1414
.object()
1515
.{{trigger}}(async (object{{#if (eq trigger "onFinalize")}}: unknown{{/if}}, context) => {
1616
{{#if (eq trigger "onFinalize")}}

integration_test_declarative/tests/v1/auth.test.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import * as admin from "firebase-admin";
22
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";
49
import { initializeFirebase } from "../firebaseSetup";
510
import { retry } from "../utils";
611

712
describe("Firebase Auth (v1)", () => {
813
const userIds: string[] = [];
914
const projectId = process.env.PROJECT_ID || "functions-integration-tests";
1015
const testId = process.env.TEST_RUN_ID;
16+
const deployedFunctions = process.env.DEPLOYED_FUNCTIONS?.split(",") || [];
1117

1218
if (!testId) {
1319
throw new Error("Environment configured incorrectly.");
@@ -17,13 +23,15 @@ describe("Firebase Auth (v1)", () => {
1723
let config;
1824
try {
1925
// Try to load from test-config.json first
20-
config = require('../../test-config.json');
26+
config = require("../../test-config.json");
2127
config.projectId = config.projectId || projectId;
2228
} catch {
2329
// Fall back to environment variables
2430
const apiKey = process.env.FIREBASE_API_KEY;
2531
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+
);
2735
test.skip("Auth tests require Firebase client SDK configuration", () => {});
2836
return;
2937
}
@@ -161,6 +169,11 @@ describe("Firebase Auth (v1)", () => {
161169
let loggedContext: admin.firestore.DocumentData | undefined;
162170

163171
beforeAll(async () => {
172+
if (!deployedFunctions.includes("beforeCreate")) {
173+
console.log("⏭️ Skipping beforeCreate tests - function not deployed in this suite");
174+
return;
175+
}
176+
164177
const auth = getAuth(app);
165178
userCredential = await createUserWithEmailAndPassword(
166179
auth,
@@ -184,14 +197,26 @@ describe("Firebase Auth (v1)", () => {
184197
});
185198

186199
it("should have the correct eventType", () => {
200+
if (!deployedFunctions.includes("beforeCreate")) {
201+
pending("beforeCreate function not deployed in this suite");
202+
return;
203+
}
187204
expect(loggedContext?.eventType).toEqual("providers/cloud.auth/eventTypes/user.beforeCreate");
188205
});
189206

190207
it("should have an eventId", () => {
208+
if (!deployedFunctions.includes("beforeCreate")) {
209+
pending("beforeCreate function not deployed in this suite");
210+
return;
211+
}
191212
expect(loggedContext?.eventId).toBeDefined();
192213
});
193214

194215
it("should have a timestamp", () => {
216+
if (!deployedFunctions.includes("beforeCreate")) {
217+
pending("beforeCreate function not deployed in this suite");
218+
return;
219+
}
195220
expect(loggedContext?.timestamp).toBeDefined();
196221
});
197222
});
@@ -202,6 +227,11 @@ describe("Firebase Auth (v1)", () => {
202227
let loggedContext: admin.firestore.DocumentData | undefined;
203228

204229
beforeAll(async () => {
230+
if (!deployedFunctions.includes("beforeSignIn")) {
231+
console.log("⏭️ Skipping beforeSignIn tests - function not deployed in this suite");
232+
return;
233+
}
234+
205235
userRecord = await admin.auth().createUser({
206236
email: `${testId}@beforesignin.com`,
207237
password: "secret456",
@@ -210,7 +240,8 @@ describe("Firebase Auth (v1)", () => {
210240
userIds.push(userRecord.uid);
211241

212242
const auth = getAuth(app);
213-
userCredential = await createUserWithEmailAndPassword(
243+
// Fix: Use signInWithEmailAndPassword instead of createUserWithEmailAndPassword
244+
userCredential = await signInWithEmailAndPassword(
214245
auth,
215246
`${testId}@beforesignin.com`,
216247
"secret456"
@@ -231,15 +262,27 @@ describe("Firebase Auth (v1)", () => {
231262
});
232263

233264
it("should have the correct eventType", () => {
265+
if (!deployedFunctions.includes("beforeSignIn")) {
266+
pending("beforeSignIn function not deployed in this suite");
267+
return;
268+
}
234269
expect(loggedContext?.eventType).toEqual("providers/cloud.auth/eventTypes/user.beforeSignIn");
235270
});
236271

237272
it("should have an eventId", () => {
273+
if (!deployedFunctions.includes("beforeSignIn")) {
274+
pending("beforeSignIn function not deployed in this suite");
275+
return;
276+
}
238277
expect(loggedContext?.eventId).toBeDefined();
239278
});
240279

241280
it("should have a timestamp", () => {
281+
if (!deployedFunctions.includes("beforeSignIn")) {
282+
pending("beforeSignIn function not deployed in this suite");
283+
return;
284+
}
242285
expect(loggedContext?.timestamp).toBeDefined();
243286
});
244287
});
245-
});
288+
});

0 commit comments

Comments
 (0)