fix: add null checks in meal-plans test cleanup
Some checks failed
Basil CI/CD Pipeline / Code Linting (push) Successful in 1m4s
Basil CI/CD Pipeline / API Tests (push) Failing after 1m17s
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 52s
Basil CI/CD Pipeline / Web Tests (push) Failing after 1m13s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m7s
Basil CI/CD Pipeline / Build All Packages (push) Has been skipped
Basil CI/CD Pipeline / E2E Tests (push) Has been skipped
Basil CI/CD Pipeline / Build & Push Docker Images (push) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (push) Has been skipped

- Add conditional checks for testUserId, testRecipeId, and otherUserId
- Prevents Prisma validation errors when cleanup runs after failed setup
- Ensures test cleanup only attempts to delete records that were created

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-14 15:48:36 +00:00
parent 2c1bfda143
commit fbd60e31bc

View File

@@ -45,15 +45,21 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
afterAll(async () => {
// Cleanup in order: meal plans (cascade deletes meals), recipes, user
await prisma.mealPlan.deleteMany({ where: { userId: testUserId } });
if (testUserId) {
await prisma.mealPlan.deleteMany({ where: { userId: testUserId } });
}
// Delete recipe and its relations
await prisma.ingredient.deleteMany({ where: { recipeId: testRecipeId } });
await prisma.instruction.deleteMany({ where: { recipeId: testRecipeId } });
await prisma.recipe.delete({ where: { id: testRecipeId } });
// Delete recipe and its relations (only if recipe was created)
if (testRecipeId) {
await prisma.ingredient.deleteMany({ where: { recipeId: testRecipeId } });
await prisma.instruction.deleteMany({ where: { recipeId: testRecipeId } });
await prisma.recipe.delete({ where: { id: testRecipeId } });
}
// Delete user
await prisma.user.delete({ where: { id: testUserId } });
// Delete user (only if user was created)
if (testUserId) {
await prisma.user.delete({ where: { id: testUserId } });
}
});
beforeEach(async () => {
@@ -493,9 +499,11 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
});
afterAll(async () => {
// Cleanup other user
await prisma.mealPlan.deleteMany({ where: { userId: otherUserId } });
await prisma.user.delete({ where: { id: otherUserId } });
// Cleanup other user (only if created)
if (otherUserId) {
await prisma.mealPlan.deleteMany({ where: { userId: otherUserId } });
await prisma.user.delete({ where: { id: otherUserId } });
}
});
beforeEach(async () => {