testUpdateOperation function

Future<void> testUpdateOperation(
  1. FirestoreApp apiProvider
)

Implementation

Future<void> testUpdateOperation(FirestoreApp apiProvider) async {
  String competitionId = 'comp_1'; // Example for one competition
  String matchPath =
      'sports/soccer/competitions/$competitionId/matches/8c1UXnBgNupqfFVeK7U6';

  // Fetch the match before update
  dynamic beforeUpdateSnapshot = await apiProvider.performGetOperation({
    'path': matchPath,
  });
  var beforeUpdateData =
      (beforeUpdateSnapshot as DocumentSnapshot).data() as Map<String, dynamic>;
  print('Venue before update: ${beforeUpdateData['venue']}');

  String time = DateTime.now().toString();
  // Perform the update
  await apiProvider.performUpdateOperation({
    'path': matchPath,
    'data': {'venue': 'Updated Venue: $time'},
  });

  // Fetch the match after update
  dynamic afterUpdateSnapshot = await apiProvider.performGetOperation({
    'path': matchPath,
  });
  var afterUpdateData =
      (afterUpdateSnapshot as DocumentSnapshot).data() as Map<String, dynamic>;
  print('Venue after update: ${afterUpdateData['venue']}');

  // Validation
  if (afterUpdateData['venue'] == 'Updated Venue: $time') {
    print('Update validation successful.');
  } else {
    print('Update validation failed.');
  }
}