feat(m11): calendar + milestones with progress calc, tests, e2e
- CalendarRepository (event CRUD, range query, soft-delete, project isolation) + MilestoneRepository (CRUD, findToDosByMilestone) + ScheduleService (aggregated getCalendarEvents = custom events+milestones+todos in range, milestone CRUD, milestone_updated activity, progress auto-calc 0-100) - APIs: calendar events GET/POST/PATCH/DELETE, milestones GET/POST/PATCH + progress - Screens: calendar list view + CalendarEventForm, milestones list with progress bars + MilestoneForm, ProjectNav links - Unit tests (CalendarRepository, MilestoneRepository, ScheduleService incl. progress calc 0/33/100) + e2e calendar
This commit is contained in:
93
tests/unit/repositories/CalendarRepository.test.ts
Normal file
93
tests/unit/repositories/CalendarRepository.test.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { createMigratedTestDb } from '@/tests/helpers/db';
|
||||
import type { SqliteDatabase } from '@/lib/db/sqlite';
|
||||
import { UserRepository } from '@/repositories/UserRepository';
|
||||
import { ProjectRepository } from '@/repositories/ProjectRepository';
|
||||
import { ProjectMemberRepository } from '@/repositories/ProjectMemberRepository';
|
||||
import { CalendarRepository } from '@/repositories/CalendarRepository';
|
||||
|
||||
describe('CalendarRepository', () => {
|
||||
let db: SqliteDatabase;
|
||||
let repo: CalendarRepository;
|
||||
let projectId: number;
|
||||
let userId: number;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createMigratedTestDb();
|
||||
repo = new CalendarRepository(db);
|
||||
userId = new UserRepository(db).create({
|
||||
name: 'U',
|
||||
email: 'u@example.com',
|
||||
passwordHash: 'h',
|
||||
}).id;
|
||||
projectId = new ProjectRepository(db).create({
|
||||
name: 'P',
|
||||
ownerId: userId,
|
||||
}).id;
|
||||
new ProjectMemberRepository(db).add(projectId, userId, 'admin');
|
||||
});
|
||||
|
||||
afterEach(() => db.close());
|
||||
|
||||
function createEvent(title: string, startAt: string) {
|
||||
return repo.create({
|
||||
projectId,
|
||||
title,
|
||||
type: 'custom',
|
||||
startAt,
|
||||
createdById: userId,
|
||||
});
|
||||
}
|
||||
|
||||
it('creates and finds an event by id', () => {
|
||||
const e = createEvent('E', '2026-06-15T10:00:00');
|
||||
expect(repo.findEventById(e.id)?.title).toBe('E');
|
||||
});
|
||||
|
||||
it('finds events in range and excludes out-of-range', () => {
|
||||
createEvent('in', '2026-06-15T10:00:00');
|
||||
createEvent('out', '2026-07-15T10:00:00');
|
||||
const events = repo.findByProjectInRange(
|
||||
projectId,
|
||||
'2026-06-01',
|
||||
'2026-06-30'
|
||||
);
|
||||
expect(events).toHaveLength(1);
|
||||
expect(events[0].title).toBe('in');
|
||||
});
|
||||
|
||||
it('excludes soft-deleted events', () => {
|
||||
const e = createEvent('E', '2026-06-15T10:00:00');
|
||||
repo.delete(e.id);
|
||||
expect(repo.findEventById(e.id)).toBeNull();
|
||||
expect(
|
||||
repo.findByProjectInRange(projectId, '2026-06-01', '2026-06-30')
|
||||
).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('isolates events by project', () => {
|
||||
createEvent('mine', '2026-06-15T10:00:00');
|
||||
const p2 = new ProjectRepository(db).create({
|
||||
name: 'P2',
|
||||
ownerId: userId,
|
||||
}).id;
|
||||
repo.create({
|
||||
projectId: p2,
|
||||
title: 'theirs',
|
||||
type: 'custom',
|
||||
startAt: '2026-06-15T10:00:00',
|
||||
createdById: userId,
|
||||
});
|
||||
expect(
|
||||
repo.findByProjectInRange(projectId, '2026-06-01', '2026-06-30')
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
repo.findByProjectInRange(p2, '2026-06-01', '2026-06-30')
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('updates an event', () => {
|
||||
const e = createEvent('E', '2026-06-15T10:00:00');
|
||||
expect(repo.update(e.id, { title: 'E2' })?.title).toBe('E2');
|
||||
});
|
||||
});
|
||||
84
tests/unit/repositories/MilestoneRepository.test.ts
Normal file
84
tests/unit/repositories/MilestoneRepository.test.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { createMigratedTestDb } from '@/tests/helpers/db';
|
||||
import type { SqliteDatabase } from '@/lib/db/sqlite';
|
||||
import { UserRepository } from '@/repositories/UserRepository';
|
||||
import { ProjectRepository } from '@/repositories/ProjectRepository';
|
||||
import { ProjectMemberRepository } from '@/repositories/ProjectMemberRepository';
|
||||
import { TodoRepository } from '@/repositories/TodoRepository';
|
||||
import { MilestoneRepository } from '@/repositories/MilestoneRepository';
|
||||
|
||||
describe('MilestoneRepository', () => {
|
||||
let db: SqliteDatabase;
|
||||
let repo: MilestoneRepository;
|
||||
let todoRepo: TodoRepository;
|
||||
let projectId: number;
|
||||
let userId: number;
|
||||
let columnId: number;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createMigratedTestDb();
|
||||
repo = new MilestoneRepository(db);
|
||||
todoRepo = new TodoRepository(db);
|
||||
userId = new UserRepository(db).create({
|
||||
name: 'U',
|
||||
email: 'u@example.com',
|
||||
passwordHash: 'h',
|
||||
}).id;
|
||||
projectId = new ProjectRepository(db).create({
|
||||
name: 'P',
|
||||
ownerId: userId,
|
||||
}).id;
|
||||
new ProjectMemberRepository(db).add(projectId, userId, 'admin');
|
||||
columnId = todoRepo.createColumn({
|
||||
projectId,
|
||||
name: 'Todo',
|
||||
orderIndex: 0,
|
||||
}).id;
|
||||
});
|
||||
|
||||
afterEach(() => db.close());
|
||||
|
||||
it('creates and lists milestones ordered by due_date', () => {
|
||||
repo.create({ projectId, title: 'M2', dueDate: '2026-12-31' });
|
||||
repo.create({ projectId, title: 'M1', dueDate: '2026-06-30' });
|
||||
const list = repo.findByProject(projectId);
|
||||
expect(list.map((m) => m.title)).toEqual(['M1', 'M2']);
|
||||
});
|
||||
|
||||
it('updates and deletes a milestone', () => {
|
||||
const m = repo.create({ projectId, title: 'M' });
|
||||
expect(repo.update(m.id, { status: 'closed' })?.status).toBe('closed');
|
||||
repo.delete(m.id);
|
||||
expect(repo.findById(m.id)).toBeNull();
|
||||
});
|
||||
|
||||
it('excludes soft-deleted milestones', () => {
|
||||
const m = repo.create({ projectId, title: 'M' });
|
||||
repo.delete(m.id);
|
||||
expect(repo.findByProject(projectId)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('findToDosByMilestone returns only linked, non-deleted todos', () => {
|
||||
const m = repo.create({ projectId, title: 'M' });
|
||||
const t1 = todoRepo.createItem({
|
||||
projectId,
|
||||
columnId,
|
||||
title: 't1',
|
||||
creatorId: userId,
|
||||
orderIndex: 0,
|
||||
});
|
||||
const t2 = todoRepo.createItem({
|
||||
projectId,
|
||||
columnId,
|
||||
title: 't2',
|
||||
creatorId: userId,
|
||||
orderIndex: 1,
|
||||
});
|
||||
todoRepo.updateItem(t1.id, { milestoneId: m.id });
|
||||
todoRepo.updateItem(t2.id, { milestoneId: m.id });
|
||||
todoRepo.deleteItem(t2.id); // soft delete
|
||||
const todos = repo.findToDosByMilestone(m.id);
|
||||
expect(todos).toHaveLength(1);
|
||||
expect(todos[0].id).toBe(t1.id);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user