Added validation when task type, category, signatories and action taken are empty upon completing a task
This commit is contained in:
@@ -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'};
|
||||
|
||||
Reference in New Issue
Block a user