Repository: PalisadoesFoundation/talawa (language: dart)

Issue:
Error in Event Registration due Faulty mutation
**Describe the bug**
The `registerForEvent` mutation being used for register functionality was updated in Talawa API in https://github.com/PalisadoesFoundation/talawa-api/issues/1644 . Before update `registerForEvent` returned `Event` object, after update it returns `EventAttendee` object. Due to older implementation of `registerForEvent` the mutation fails. 

**To Reproduce**
Steps to reproduce the behavior:

1. Login in a organiszation.
2. Open Events Tab
3. Open a specific event (where you've not already registered)
4. Click on register.
5. Error is displayed as No mutation occurs.

**Expected behavior**
On click of register button, user should be registered for the event.

**Actual behavior**
On click of register button, error is displayed due to failing mutation.

**Screenshots**

https://github.com/PalisadoesFoundation/talawa/assets/109027247/899b8344-0c4e-4d91-bd83-38995c77fe6f


**Additional details**
Part (pre-requisite) for Event Parity project

**Potential internship candidates**
Please read this if you are planning to apply for a Palisadoes Foundation internship https://github.com/PalisadoesFoundation/talawa/issues/359



Discussion hints:
Would like to work on this issue

Pull request: Fixed registerForEvent mutation & update tests
**What kind of change does this PR introduce?**

bugfix

**Issue Number:**

Fixes #2467 

**Did you add tests for your changes?**

Yes

**Snapshots/Videos:**


https://github.com/PalisadoesFoundation/talawa/assets/109027247/3261ed92-cf07-4223-bc8a-bb7f017a5de6

**Summary**

- Modified `registerForEvent` mutation as per changes made in Talawa API.
- Updated the tests for same

**Does this PR introduce a breaking change?**

No


**Have you read the [contributing guide](https://github.com/PalisadoesFoundation/talawa/blob/master/CONTRIBUTING.md)?**

Yes 


Test command: nan

Fix patch:
diff --git a/lib/services/event_service.dart b/lib/services/event_service.dart
index eff3153edd..6b3146ec89 100644
--- a/lib/services/event_service.dart
+++ b/lib/services/event_service.dart
@@ -80,7 +80,6 @@ class EventService {
 
     final List eventsJson =
         (result as QueryResult).data!["eventsByOrganizationConnection"] as List;
-    debugPrint('Events: $eventsJson');
     eventsJson.forEach((eventJsonData) {
       final Event event = Event.fromJson(eventJsonData as Map<String, dynamic>);
       event.isRegistered = event.attendees?.any(
diff --git a/lib/utils/event_queries.dart b/lib/utils/event_queries.dart
index c68b8e3781..554c180f47 100644
--- a/lib/utils/event_queries.dart
+++ b/lib/utils/event_queries.dart
@@ -114,14 +114,11 @@ class EventQueries {
   String registerForEvent() {
     return """
      mutation registerForEvent(\$eventId: ID!) { 
-      registerForEvent(id: \$eventId)
-        {
+      registerForEvent(id: \$eventId) {
         _id
-        title
-        description
       }
-    }
-  """;
+     }
+    """;
   }
 
   /// Creates a GraphQL mutation for deleting an event.
diff --git a/lib/view_model/after_auth_view_models/event_view_models/event_info_view_model.dart b/lib/view_model/after_auth_view_models/event_view_models/event_info_view_model.dart
index 1eb36c925f..8835a662e0 100644
--- a/lib/view_model/after_auth_view_models/event_view_models/event_info_view_model.dart
+++ b/lib/view_model/after_auth_view_models/event_view_models/event_info_view_model.dart
@@ -61,19 +61,20 @@ class EventInfoViewModel extends BaseModel {
           await locator<EventService>().registerForAnEvent(event.id!);
       if (registerResult != null) {
         event.isRegistered = true;
+        final userConfig = locator<UserConfig>();
         attendees.add(
           Attendee(
-            id: UserConfig().currentUser.id,
-            firstName: UserConfig().currentUser.firstName,
-            lastName: UserConfig().currentUser.lastName,
-            image: UserConfig().currentUser.image,
+            id: userConfig.currentUser.id,
+            firstName: userConfig.currentUser.firstName,
+            lastName: userConfig.currentUser.lastName,
+            image: userConfig.currentUser.image,
           ),
         );
       }
-      print(registerResult);
       fabTitle = getFabTitle();
       navigationService.pop();
       notifyListeners();
+      await locator<EventService>().getEvents();
     }
   }
 


Test patch:
diff --git a/test/service_tests/event_service_test.dart b/test/service_tests/event_service_test.dart
index 5546bfa246..76c461bbde 100644
--- a/test/service_tests/event_service_test.dart
+++ b/test/service_tests/event_service_test.dart
@@ -1,5 +1,3 @@
-// ignore_for_file: talawa_api_doc
-
 import 'package:flutter_test/flutter_test.dart';
 import 'package:graphql_flutter/graphql_flutter.dart';
 import 'package:mockito/mockito.dart';
@@ -91,7 +89,6 @@ void main() {
           data: {
             'register for an event': {
               '_id': 'eventId',
-              'name': 'name',
             },
           },
           source: QueryResultSource.network,
diff --git a/test/utils/event_queries_test.dart b/test/utils/event_queries_test.dart
index 95e867f636..83342ae372 100644
--- a/test/utils/event_queries_test.dart
+++ b/test/utils/event_queries_test.dart
@@ -87,14 +87,11 @@ void main() {
     test("Check if registerForEvent works correctly", () {
       const data = """
      mutation registerForEvent(\$eventId: ID!) { 
-      registerForEvent(id: \$eventId)
-        {
+      registerForEvent(id: \$eventId) {
         _id
-        title
-        description
       }
-    }
-  """;
+     }
+    """;
 
       final fnData = EventQueries().registerForEvent();
       expect(fnData, data);