fix: add proper error checking to meal-plans test setup
Some checks failed
Basil CI/CD Pipeline / Code Linting (push) Successful in 56s
Basil CI/CD Pipeline / API Tests (push) Failing after 1m19s
Basil CI/CD Pipeline / Web Tests (push) Failing after 1m7s
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 53s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m8s
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
Some checks failed
Basil CI/CD Pipeline / Code Linting (push) Successful in 56s
Basil CI/CD Pipeline / API Tests (push) Failing after 1m19s
Basil CI/CD Pipeline / Web Tests (push) Failing after 1m7s
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 53s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m8s
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 .expect() assertions to all registration and login calls - Add validation that userId and authToken are properly set - Add error checking to meal plan creation in beforeEach hooks - This will produce clear error messages instead of cryptic "Cannot read properties of undefined" errors - Helps identify root cause of 401 authentication failures Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
email: testEmail,
|
||||
password: testPassword,
|
||||
name: 'Meal Plan Test User',
|
||||
});
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
testUserId = userResponse.body.user.id;
|
||||
if (!testUserId) {
|
||||
throw new Error(`Registration failed: ${JSON.stringify(userResponse.body)}`);
|
||||
}
|
||||
|
||||
// Login to get auth token
|
||||
const loginResponse = await request(app)
|
||||
@@ -32,9 +36,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
.send({
|
||||
email: testEmail,
|
||||
password: testPassword,
|
||||
});
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
authToken = loginResponse.body.accessToken;
|
||||
if (!authToken) {
|
||||
throw new Error(`Login failed: ${JSON.stringify(loginResponse.body)}`);
|
||||
}
|
||||
|
||||
// Create test recipe
|
||||
const recipeResponse = await request(app)
|
||||
@@ -191,9 +199,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
.send({
|
||||
date: '2025-01-20',
|
||||
notes: 'Test plan for meals',
|
||||
});
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
mealPlanId = response.body.data.id;
|
||||
if (!mealPlanId) {
|
||||
throw new Error(`Failed to create meal plan in Meal Management: ${JSON.stringify(response.body)}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('should add meal to meal plan', async () => {
|
||||
@@ -476,7 +488,8 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
{ mealType: 'BREAKFAST', recipeId: testRecipeId, servings: 4 },
|
||||
{ mealType: 'LUNCH', recipeId: testRecipeId, servings: 4 },
|
||||
],
|
||||
});
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
const mealPlanId = createResponse.body.data.id;
|
||||
const mealIds = createResponse.body.data.meals.map((m: any) => m.id);
|
||||
@@ -513,9 +526,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
email: otherEmail,
|
||||
password: otherPassword,
|
||||
name: 'Other User',
|
||||
});
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
otherUserId = userResponse.body.user.id;
|
||||
if (!otherUserId) {
|
||||
throw new Error(`Registration failed for other user: ${JSON.stringify(userResponse.body)}`);
|
||||
}
|
||||
|
||||
// Login to get auth token
|
||||
const loginResponse = await request(app)
|
||||
@@ -523,9 +540,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
.send({
|
||||
email: otherEmail,
|
||||
password: otherPassword,
|
||||
});
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
otherUserToken = loginResponse.body.accessToken;
|
||||
if (!otherUserToken) {
|
||||
throw new Error(`Login failed for other user: ${JSON.stringify(loginResponse.body)}`);
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -544,9 +565,13 @@ describe('Meal Plans Routes - Real Integration Tests', () => {
|
||||
.send({
|
||||
date: '2025-07-01',
|
||||
notes: 'User 1 plan',
|
||||
});
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
mealPlanId = response.body.data.id;
|
||||
if (!mealPlanId) {
|
||||
throw new Error(`Failed to create meal plan: ${JSON.stringify(response.body)}`);
|
||||
}
|
||||
});
|
||||
|
||||
it('should not allow user to read another users meal plan', async () => {
|
||||
|
||||
Reference in New Issue
Block a user