Allow task completion even if signatories are still empty, put an indicator for completed tasks with incomplete details.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tasq/providers/tasks_provider.dart';
|
||||
import 'package:tasq/models/task.dart';
|
||||
|
||||
// Minimal fake supabase client similar to integration test work,
|
||||
// only implements the methods used by TasksController.
|
||||
@@ -101,7 +102,7 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot complete when signatories or action taken missing', () async {
|
||||
test('cannot complete when action taken is missing', () async {
|
||||
// insert a task that has the basic request metadata but nothing else
|
||||
final row = {
|
||||
'id': 'tsk-3',
|
||||
@@ -111,13 +112,14 @@ void main() {
|
||||
};
|
||||
fake.tables['tasks']!.add(row);
|
||||
|
||||
// still missing signatories/actionTaken
|
||||
// missing actionTaken should still prevent completion even though
|
||||
// signatories are not required.
|
||||
expect(
|
||||
() => controller.updateTaskStatus(taskId: 'tsk-3', status: 'completed'),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
|
||||
// add signatories but actionTaken still missing
|
||||
// add some signatories but no actionTaken yet
|
||||
await controller.updateTask(
|
||||
taskId: 'tsk-3',
|
||||
requestedBy: 'Alice',
|
||||
@@ -129,7 +131,9 @@ void main() {
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
|
||||
// add action taken (empty JSON string)
|
||||
// once action taken is provided completion should succeed even if
|
||||
// signatories remain empty (they already have values here, but the
|
||||
// previous checks show they aren't required).
|
||||
await controller.updateTask(taskId: 'tsk-3', actionTaken: '{}');
|
||||
await controller.updateTaskStatus(taskId: 'tsk-3', status: 'completed');
|
||||
expect(
|
||||
@@ -143,11 +147,12 @@ void main() {
|
||||
final row = {'id': 'tsk-2', 'status': 'queued'};
|
||||
fake.tables['tasks']!.add(row);
|
||||
|
||||
// update metadata via updateTask
|
||||
// update metadata via updateTask including actionTaken
|
||||
await controller.updateTask(
|
||||
taskId: 'tsk-2',
|
||||
requestType: 'Repair',
|
||||
requestCategory: 'Hardware',
|
||||
actionTaken: '{}',
|
||||
);
|
||||
|
||||
await controller.updateTaskStatus(taskId: 'tsk-2', status: 'completed');
|
||||
@@ -156,5 +161,49 @@ void main() {
|
||||
'completed',
|
||||
);
|
||||
});
|
||||
|
||||
test('Task.hasIncompleteDetails flag works correctly', () {
|
||||
final now = DateTime.now();
|
||||
final base = Task(
|
||||
id: 'x',
|
||||
ticketId: null,
|
||||
taskNumber: null,
|
||||
title: 't',
|
||||
description: '',
|
||||
officeId: null,
|
||||
status: 'completed',
|
||||
priority: 1,
|
||||
queueOrder: null,
|
||||
createdAt: now,
|
||||
creatorId: null,
|
||||
startedAt: null,
|
||||
completedAt: now,
|
||||
// leave all optional metadata null
|
||||
);
|
||||
expect(base.hasIncompleteDetails, isTrue);
|
||||
|
||||
final full = Task(
|
||||
id: 'x',
|
||||
ticketId: null,
|
||||
taskNumber: null,
|
||||
title: 't',
|
||||
description: '',
|
||||
officeId: null,
|
||||
status: 'completed',
|
||||
priority: 1,
|
||||
queueOrder: null,
|
||||
createdAt: now,
|
||||
creatorId: null,
|
||||
startedAt: null,
|
||||
completedAt: now,
|
||||
requestedBy: 'A',
|
||||
notedBy: 'B',
|
||||
receivedBy: 'C',
|
||||
requestType: 'foo',
|
||||
requestCategory: 'bar',
|
||||
actionTaken: '{}',
|
||||
);
|
||||
expect(full.hasIncompleteDetails, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user