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
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user