From a61530359ab33462ef2b370462731619a1acb24b Mon Sep 17 00:00:00 2001 From: Lukas May Date: Sun, 1 Feb 2026 11:54:43 +0100 Subject: [PATCH] test(12-07): add PlanRepository getNextNumber tests Add tests for getNextNumber method: - Returns 1 for phase with no plans - Returns max + 1 for phase with existing plans - Not affected by plans in other phases --- src/db/repositories/drizzle/plan.test.ts | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/db/repositories/drizzle/plan.test.ts b/src/db/repositories/drizzle/plan.test.ts index 31baeb4..b8b795b 100644 --- a/src/db/repositories/drizzle/plan.test.ts +++ b/src/db/repositories/drizzle/plan.test.ts @@ -118,6 +118,41 @@ describe('DrizzlePlanRepository', () => { }); }); + describe('getNextNumber', () => { + it('should return 1 for phase with no plans', async () => { + const nextNumber = await planRepo.getNextNumber(testPhaseId); + expect(nextNumber).toBe(1); + }); + + it('should return max + 1 for phase with plans', async () => { + await planRepo.create({ phaseId: testPhaseId, number: 1, name: 'Plan 1' }); + await planRepo.create({ phaseId: testPhaseId, number: 5, name: 'Plan 5' }); + + const nextNumber = await planRepo.getNextNumber(testPhaseId); + expect(nextNumber).toBe(6); + }); + + it('should not be affected by plans in other phases', async () => { + // Create another phase + const initiative = await initiativeRepo.create({ name: 'Another Initiative' }); + const otherPhase = await phaseRepo.create({ + initiativeId: initiative.id, + number: 2, + name: 'Other Phase', + }); + + // Add plans to other phase + await planRepo.create({ phaseId: otherPhase.id, number: 10, name: 'High Plan' }); + + // Add a plan to test phase + await planRepo.create({ phaseId: testPhaseId, number: 3, name: 'Plan 3' }); + + // Next number for test phase should be 4, not 11 + const nextNumber = await planRepo.getNextNumber(testPhaseId); + expect(nextNumber).toBe(4); + }); + }); + describe('update', () => { it('should update fields and updatedAt', async () => { const created = await planRepo.create({