test(08-01): add failing tests for softDeleteTask, getCompletionCount, isActive filtering
- Tests for softDeleteTask sets isActive=false without removing from DB - Tests for getCompletionCount with 0 and N completions - Tests for watchTasksInRoom excludes inactive tasks - Tests for getOverdueTaskCount excludes inactive tasks - Test for hard deleteTask still removes task and completions
This commit is contained in:
@@ -204,5 +204,137 @@ void main() {
|
|||||||
// Only the task due Mar 10 is overdue (before Mar 15)
|
// Only the task due Mar 10 is overdue (before Mar 15)
|
||||||
expect(overdueCount, 1);
|
expect(overdueCount, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('softDeleteTask sets isActive to false without removing the task', () async {
|
||||||
|
final id = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Abspuelen',
|
||||||
|
intervalType: IntervalType.daily,
|
||||||
|
effortLevel: EffortLevel.low,
|
||||||
|
nextDueDate: DateTime(2026, 3, 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.tasksDao.softDeleteTask(id);
|
||||||
|
|
||||||
|
// Task should still exist in DB but isActive == false
|
||||||
|
final allTasks = await (db.select(db.tasks)).get();
|
||||||
|
expect(allTasks.length, 1);
|
||||||
|
expect(allTasks.first.isActive, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getCompletionCount returns 0 for task with no completions', () async {
|
||||||
|
final id = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Abspuelen',
|
||||||
|
intervalType: IntervalType.daily,
|
||||||
|
effortLevel: EffortLevel.low,
|
||||||
|
nextDueDate: DateTime(2026, 3, 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final count = await db.tasksDao.getCompletionCount(id);
|
||||||
|
expect(count, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getCompletionCount returns correct count after completions', () async {
|
||||||
|
final id = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Abspuelen',
|
||||||
|
intervalType: IntervalType.daily,
|
||||||
|
effortLevel: EffortLevel.low,
|
||||||
|
nextDueDate: DateTime(2026, 3, 13),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.tasksDao.completeTask(id, now: DateTime(2026, 3, 13));
|
||||||
|
await db.tasksDao.completeTask(id, now: DateTime(2026, 3, 14));
|
||||||
|
await db.tasksDao.completeTask(id, now: DateTime(2026, 3, 15));
|
||||||
|
|
||||||
|
final count = await db.tasksDao.getCompletionCount(id);
|
||||||
|
expect(count, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('watchTasksInRoom excludes soft-deleted (isActive=false) tasks', () async {
|
||||||
|
final activeId = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Active Task',
|
||||||
|
intervalType: IntervalType.daily,
|
||||||
|
effortLevel: EffortLevel.low,
|
||||||
|
nextDueDate: DateTime(2026, 3, 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final inactiveId = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Inactive Task',
|
||||||
|
intervalType: IntervalType.weekly,
|
||||||
|
effortLevel: EffortLevel.medium,
|
||||||
|
nextDueDate: DateTime(2026, 3, 10),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.tasksDao.softDeleteTask(inactiveId);
|
||||||
|
|
||||||
|
final tasks = await db.tasksDao.watchTasksInRoom(roomId).first;
|
||||||
|
expect(tasks.length, 1);
|
||||||
|
expect(tasks.first.id, activeId);
|
||||||
|
expect(tasks.first.name, 'Active Task');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getOverdueTaskCount excludes soft-deleted (isActive=false) tasks', () async {
|
||||||
|
// Active overdue task
|
||||||
|
await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Active Overdue',
|
||||||
|
intervalType: IntervalType.weekly,
|
||||||
|
effortLevel: EffortLevel.medium,
|
||||||
|
nextDueDate: DateTime(2026, 3, 10),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Inactive overdue task
|
||||||
|
final inactiveId = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Inactive Overdue',
|
||||||
|
intervalType: IntervalType.weekly,
|
||||||
|
effortLevel: EffortLevel.medium,
|
||||||
|
nextDueDate: DateTime(2026, 3, 5),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.tasksDao.softDeleteTask(inactiveId);
|
||||||
|
|
||||||
|
final overdueCount = await db.tasksDao.getOverdueTaskCount(
|
||||||
|
roomId,
|
||||||
|
today: DateTime(2026, 3, 15),
|
||||||
|
);
|
||||||
|
expect(overdueCount, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('hard deleteTask still removes task and its completions', () async {
|
||||||
|
final id = await db.tasksDao.insertTask(
|
||||||
|
TasksCompanion.insert(
|
||||||
|
roomId: roomId,
|
||||||
|
name: 'Abspuelen',
|
||||||
|
intervalType: IntervalType.daily,
|
||||||
|
effortLevel: EffortLevel.low,
|
||||||
|
nextDueDate: DateTime(2026, 3, 13),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await db.tasksDao.completeTask(id, now: DateTime(2026, 3, 13));
|
||||||
|
|
||||||
|
await db.tasksDao.deleteTask(id);
|
||||||
|
|
||||||
|
final tasks = await (db.select(db.tasks)).get();
|
||||||
|
final completions = await (db.select(db.taskCompletions)).get();
|
||||||
|
expect(tasks, isEmpty);
|
||||||
|
expect(completions, isEmpty);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user