test: update recipe update test for new behavior
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 1m34s
Basil CI/CD Pipeline / Code Linting (push) Successful in 1m37s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m53s
Basil CI/CD Pipeline / Web Tests (push) Successful in 1m55s
Basil CI/CD Pipeline / API Tests (push) Successful in 1m58s
Basil CI/CD Pipeline / Build All Packages (push) Successful in 1m31s
Basil CI/CD Pipeline / E2E Tests (push) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (push) Has been cancelled
Basil CI/CD Pipeline / Build & Push Docker Images (push) Has been cancelled
Some checks failed
Basil CI/CD Pipeline / Shared Package Tests (push) Successful in 1m34s
Basil CI/CD Pipeline / Code Linting (push) Successful in 1m37s
Basil CI/CD Pipeline / Security Scanning (push) Successful in 1m53s
Basil CI/CD Pipeline / Web Tests (push) Successful in 1m55s
Basil CI/CD Pipeline / API Tests (push) Successful in 1m58s
Basil CI/CD Pipeline / Build All Packages (push) Successful in 1m31s
Basil CI/CD Pipeline / E2E Tests (push) Has been skipped
Basil CI/CD Pipeline / Trigger Deployment (push) Has been cancelled
Basil CI/CD Pipeline / Build & Push Docker Images (push) Has been cancelled
- Test now validates that only specified relations are deleted - First test: updating only title doesn't delete any relations - Second test: updating tags and ingredients only deletes those - Reflects new patch-like behavior of PUT endpoint
This commit is contained in:
@@ -390,7 +390,7 @@ describe('Recipes Routes - Real Integration Tests', () => {
|
||||
expect(prisma.recipe.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should delete old relations before update', async () => {
|
||||
it('should only delete relations that are being updated', async () => {
|
||||
(prisma.recipeSection.deleteMany as any).mockResolvedValue({});
|
||||
(prisma.ingredient.deleteMany as any).mockResolvedValue({});
|
||||
(prisma.instruction.deleteMany as any).mockResolvedValue({});
|
||||
@@ -406,22 +406,46 @@ describe('Recipes Routes - Real Integration Tests', () => {
|
||||
});
|
||||
(prisma.cookbook.findMany as any).mockResolvedValue([]);
|
||||
|
||||
// Test 1: Only updating title - should not delete any relations
|
||||
await request(app)
|
||||
.put('/api/recipes/1')
|
||||
.send({ title: 'Updated' });
|
||||
|
||||
expect(prisma.recipeSection.deleteMany).toHaveBeenCalledWith({
|
||||
where: { recipeId: '1' },
|
||||
expect(prisma.recipeSection.deleteMany).not.toHaveBeenCalled();
|
||||
expect(prisma.ingredient.deleteMany).not.toHaveBeenCalled();
|
||||
expect(prisma.instruction.deleteMany).not.toHaveBeenCalled();
|
||||
expect(prisma.recipeTag.deleteMany).not.toHaveBeenCalled();
|
||||
|
||||
// Reset mocks
|
||||
vi.clearAllMocks();
|
||||
(prisma.ingredient.deleteMany as any).mockResolvedValue({});
|
||||
(prisma.recipeTag.deleteMany as any).mockResolvedValue({});
|
||||
(prisma.recipe.update as any).mockResolvedValue({
|
||||
id: '1',
|
||||
title: 'Updated',
|
||||
ingredients: [],
|
||||
tags: [],
|
||||
});
|
||||
(prisma.cookbook.findMany as any).mockResolvedValue([]);
|
||||
|
||||
// Test 2: Updating tags and ingredients - should only delete those
|
||||
await request(app)
|
||||
.put('/api/recipes/1')
|
||||
.send({
|
||||
title: 'Updated',
|
||||
ingredients: [],
|
||||
tags: []
|
||||
});
|
||||
|
||||
expect(prisma.ingredient.deleteMany).toHaveBeenCalledWith({
|
||||
where: { recipeId: '1' },
|
||||
});
|
||||
expect(prisma.instruction.deleteMany).toHaveBeenCalledWith({
|
||||
where: { recipeId: '1' },
|
||||
});
|
||||
expect(prisma.recipeTag.deleteMany).toHaveBeenCalledWith({
|
||||
where: { recipeId: '1' },
|
||||
});
|
||||
// These should NOT be called since we didn't send them
|
||||
expect(prisma.recipeSection.deleteMany).not.toHaveBeenCalled();
|
||||
expect(prisma.instruction.deleteMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return 500 on update error', async () => {
|
||||
|
||||
Reference in New Issue
Block a user