frontend direct testing result and fixes
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m42s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m42s
This commit is contained in:
@@ -232,6 +232,88 @@ describe('Recipe API Routes Integration Tests', () => {
|
||||
createdRecipeIds.push(forkedRecipe.recipe_id);
|
||||
});
|
||||
|
||||
it('should allow forking seed recipes (null user_id)', async () => {
|
||||
// First, find or create a seed recipe (one with null user_id)
|
||||
let seedRecipeId: number;
|
||||
const seedRecipeResult = await getPool().query(
|
||||
`SELECT recipe_id FROM public.recipes WHERE user_id IS NULL LIMIT 1`,
|
||||
);
|
||||
|
||||
if (seedRecipeResult.rows.length > 0) {
|
||||
seedRecipeId = seedRecipeResult.rows[0].recipe_id;
|
||||
} else {
|
||||
// Create a seed recipe if none exist
|
||||
const createSeedResult = await getPool().query(
|
||||
`INSERT INTO public.recipes (name, instructions, user_id, status, description)
|
||||
VALUES ('Seed Recipe for Fork Test', 'Seed recipe instructions.', NULL, 'public', 'A seed recipe.')
|
||||
RETURNING recipe_id`,
|
||||
);
|
||||
seedRecipeId = createSeedResult.rows[0].recipe_id;
|
||||
createdRecipeIds.push(seedRecipeId);
|
||||
}
|
||||
|
||||
// Fork the seed recipe - this should succeed
|
||||
const response = await request
|
||||
.post(`/api/recipes/${seedRecipeId}/fork`)
|
||||
.set('Authorization', `Bearer ${authToken}`);
|
||||
|
||||
// Forking should work - seed recipes should be forkable
|
||||
expect(response.status).toBe(201);
|
||||
const forkedRecipe: Recipe = response.body.data;
|
||||
expect(forkedRecipe.original_recipe_id).toBe(seedRecipeId);
|
||||
expect(forkedRecipe.user_id).toBe(testUser.user.user_id);
|
||||
|
||||
// Track for cleanup
|
||||
createdRecipeIds.push(forkedRecipe.recipe_id);
|
||||
});
|
||||
|
||||
describe('GET /api/recipes/:recipeId/comments', () => {
|
||||
it('should return comments for a recipe', async () => {
|
||||
// First add a comment
|
||||
await request
|
||||
.post(`/api/recipes/${testRecipe.recipe_id}/comments`)
|
||||
.set('Authorization', `Bearer ${authToken}`)
|
||||
.send({ content: 'Test comment for GET request' });
|
||||
|
||||
// Now fetch comments
|
||||
const response = await request.get(`/api/recipes/${testRecipe.recipe_id}/comments`);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
expect(response.body.data).toBeInstanceOf(Array);
|
||||
expect(response.body.data.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify comment structure
|
||||
const comment = response.body.data[0];
|
||||
expect(comment).toHaveProperty('recipe_comment_id');
|
||||
expect(comment).toHaveProperty('content');
|
||||
expect(comment).toHaveProperty('user_id');
|
||||
expect(comment).toHaveProperty('recipe_id');
|
||||
});
|
||||
|
||||
it('should return empty array for recipe with no comments', async () => {
|
||||
// Create a recipe specifically with no comments
|
||||
const createRes = await request
|
||||
.post('/api/users/recipes')
|
||||
.set('Authorization', `Bearer ${authToken}`)
|
||||
.send({
|
||||
name: 'Recipe With No Comments',
|
||||
instructions: 'No comments here.',
|
||||
description: 'Testing empty comments.',
|
||||
});
|
||||
|
||||
const noCommentsRecipe: Recipe = createRes.body.data;
|
||||
createdRecipeIds.push(noCommentsRecipe.recipe_id);
|
||||
|
||||
// Fetch comments for this recipe
|
||||
const response = await request.get(`/api/recipes/${noCommentsRecipe.recipe_id}/comments`);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body.success).toBe(true);
|
||||
expect(response.body.data).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/recipes/suggest', () => {
|
||||
it('should return a recipe suggestion based on ingredients', async () => {
|
||||
const ingredients = ['chicken', 'rice', 'broccoli'];
|
||||
|
||||
Reference in New Issue
Block a user