Added validation when task type, category, signatories and action taken are empty upon completing a task

This commit is contained in:
2026-02-23 21:27:55 +08:00
parent 1074572905
commit 98355c3707
3 changed files with 90 additions and 12 deletions
+39 -2
View File
@@ -90,8 +90,8 @@ void main() {
// note: controller expects SupabaseClient; using dynamic bypass.
});
test('cannot complete a task without request details', () async {
// insert a task with no metadata
test('cannot complete a task without required metadata', () async {
// insert a task with no metadata at all
final row = {'id': 'tsk-1', 'status': 'queued'};
fake.tables['tasks']!.add(row);
@@ -101,6 +101,43 @@ void main() {
);
});
test('cannot complete when signatories or action taken missing', () async {
// insert a task that has the basic request metadata but nothing else
final row = {
'id': 'tsk-3',
'status': 'queued',
'request_type': 'Repair',
'request_category': 'Hardware',
};
fake.tables['tasks']!.add(row);
// still missing signatories/actionTaken
expect(
() => controller.updateTaskStatus(taskId: 'tsk-3', status: 'completed'),
throwsA(isA<Exception>()),
);
// add signatories but actionTaken still missing
await controller.updateTask(
taskId: 'tsk-3',
requestedBy: 'Alice',
notedBy: 'Bob',
receivedBy: 'Carol',
);
expect(
() => controller.updateTaskStatus(taskId: 'tsk-3', status: 'completed'),
throwsA(isA<Exception>()),
);
// add action taken (empty JSON string)
await controller.updateTask(taskId: 'tsk-3', actionTaken: '{}');
await controller.updateTaskStatus(taskId: 'tsk-3', status: 'completed');
expect(
fake.tables['tasks']!.firstWhere((t) => t['id'] == 'tsk-3')['status'],
'completed',
);
});
test('completing after adding metadata succeeds', () async {
// insert a task
final row = {'id': 'tsk-2', 'status': 'queued'};