test(db): add InitiativeRepository findByStatus tests

- Test empty array for no matches
- Test filtering by active/completed/archived status
This commit is contained in:
Lukas May
2026-01-31 19:23:44 +01:00
parent 567d863a4a
commit de57c15666

View File

@@ -121,4 +121,32 @@ describe('DrizzleInitiativeRepository', () => {
);
});
});
describe('findByStatus', () => {
it('should return empty array for no matches', async () => {
await repo.create({ name: 'Active 1', status: 'active' });
const completed = await repo.findByStatus('completed');
expect(completed).toEqual([]);
});
it('should filter by status', async () => {
await repo.create({ name: 'Active 1', status: 'active' });
await repo.create({ name: 'Active 2', status: 'active' });
await repo.create({ name: 'Completed', status: 'completed' });
await repo.create({ name: 'Archived', status: 'archived' });
const active = await repo.findByStatus('active');
expect(active).toHaveLength(2);
expect(active.every((i) => i.status === 'active')).toBe(true);
const completed = await repo.findByStatus('completed');
expect(completed).toHaveLength(1);
expect(completed[0].name).toBe('Completed');
const archived = await repo.findByStatus('archived');
expect(archived).toHaveLength(1);
expect(archived[0].name).toBe('Archived');
});
});
});