testTaskDeleteComplicated function

Future testTaskDeleteComplicated()

Complicated Test

Implementation

Future testTaskDeleteComplicated() async {
  /// Create 2 tasks
  final taskA = await createTask();
  final taskB = await createTask();

  /// assign taskA to 3 users
  await Assign.create(taskId: taskA.id, uid: my!.uid);
  await Assign.create(taskId: taskA.id, uid: 'abc');
  await Assign.create(taskId: taskA.id, uid: 'def');

  /// assign taskB to 2 users
  await Assign.create(taskId: taskB.id, uid: '1');
  await Assign.create(taskId: taskB.id, uid: '2');

  /// Check if taskA has 3 assigns
  final List<Assign> assigns1 = await TodoService.instance.getAssigns(taskA.id);
  isTrue(assigns1.length == 3, 'Expect: success on assign create.');

  /// Delete taskA
  await taskA.delete();

  /// Check if taskA has 0 assigns
  final List<Assign> assigns1AfterDelete =
      await TodoService.instance.getAssigns(taskA.id);
  isTrue(assigns1AfterDelete.isEmpty, 'Expect: success on assign delete.');

  /// Check if taskB is not affected.
  final List<Assign> assigns2 = await TodoService.instance.getAssigns(taskB.id);
  isTrue(assigns2.length == 2, 'Expect: success on assign create.');
}