Repository: PalisadoesFoundation/talawa (language: dart)

Issue:
Bug Report: SignUp (Mobile)
**Describe the bug**

The Talawa App is not able to run locally because of certain GrapphQL errors on the client side 


![image](https://github.com/PalisadoesFoundation/talawa/assets/99138286/d22e02fc-7fa5-45ca-a4aa-d33e39d74a69)

On server Talawa-API  `userRegistrationRequired` is not defined for the type Organizations in `types.ts`

<img width="364" alt="image" src="https://github.com/PalisadoesFoundation/talawa/assets/99138286/88378447-d948-46e8-8edb-88626d13414b">



During Login there is a GraphQL error 

![image](https://github.com/PalisadoesFoundation/talawa/assets/99138286/b69ba434-9fee-4ffd-90a4-7cffc9ceb789)
<img width="224" alt="image" src="https://github.com/PalisadoesFoundation/talawa/assets/99138286/3592c3f9-e27b-4c1c-a2b1-e8aa5b063a59">

<img width="477" alt="image" src="https://github.com/PalisadoesFoundation/talawa/assets/99138286/27d2c3ab-13b8-4a37-8d82-daba4404f827">


**To Reproduce**
Steps to reproduce the behavior:

1. Fix Login by taking care of `appUserProfile` 
2. Fix Sign Up by taking care of `userRegistrationRequired`

**Expected behavior**
Run Talawa Mobile successfully without any errors.

**Actual behavior**
- Error while login and signup.
- Error fetching organizations.


**Additional details**
I'll create an issue in Talawa-API to add the particular fields described in screenshot in `types.ts` 

**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:
I would like to work on this issue
@ArinNigam Before working on this, please verify this issue is happening in the develop march.  Please close this if it is not needed. 
The error is being caused by `userRegistrationRequired`. The server issue has been closed. Apparently the fields are present in `develop` branch and I mistook `main` branch as  the `develop`

Though the issue with SignUp and Login still exist at client side: 

`GraphQLError(message: Cannot return null for non-nullable field Organization.userRegistrationRequired.`


https://github.com/PalisadoesFoundation/talawa/assets/99138286/6d4868f1-e038-488d-bc5a-82bac1e9ec56



https://github.com/PalisadoesFoundation/talawa/assets/99138286/8744bc46-9161-4974-b325-879e84ac153e



Hi, just checked that sample imports were old in my databases and were causing issues for `login` and `signup` where it was giving `userRegistrationRequired`  to be null since it was not defined in the database initially. 

https://github.com/PalisadoesFoundation/talawa/assets/99138286/5f762c5d-159c-4ee1-911f-5a507768a771

https://github.com/PalisadoesFoundation/talawa/assets/99138286/ea985977-9abc-4b90-9b45-e8889be22c42


Login works perfectly fine. But still there is an issue persists with signup which is most probably be caused from the server side. Attaching the logs 

This is when you click on **signup** after filling all the details

_From Server_ 
```
error Field "UserInput.selectedOrganization" of required type "ID!" was not provided. {
"locations": [
    {
        "line": 3,
        "column": 16
    }
],
"extensions": {
    "code": "GRAPHQL_VALIDATION_FAILED",
     "stacktrace": [
        "GraphQLError: Field \"UserInput.selectedOrganization\" of required type \"ID!\" was not provided.",
        "    at Object.ObjectValue (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/graphql/validation/rules/ValuesOfCorrectTypeRule.js:64:13)",
        "    at Object.enter (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/graphql/language/visitor.js:301:32)",
        "    at Object.enter (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/graphql/utilities/TypeInfo.js:391:27)",
        "    at visit (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/graphql/language/visitor.js:197:21)",
        "    at validate (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/graphql/validation/validate.js:91:24)",
        "    at processGraphQLRequest (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/@apollo/server/src/requestPipeline.ts:247:40)",
        "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
        "    at internalExecuteOperation (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/@apollo/server/src/ApolloServer.ts:1313:12)",
        "    at runHttpQuery (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/@apollo/server/src/runHttpQuery.ts:232:27)",
        "    at runPotentiallyBatchedHttpQuery (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/@apollo/server/src/httpBatching.ts:85:12)",
        "    at ApolloServer.executeHTTPGraphQLRequest (/Users/arinnigam/Desktop/AppDev/talawa/talawa-api/node_modules/@apollo/server/src/ApolloServer.ts:1087:14)"
    ]
}
}
```

_From Client_
```
I/flutter (17501): ServerException(
  originalException: null, 
  originalStackTrace: null, 
  parsedResponse: 
    Response
      (data: null,
      errors: [GraphQLError(message: Field "UserInput.selectedOrganization" of required type "ID!" was not provided.,
      locations: null, path: null, extensions: null)],
      context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}), 
      response: {
        errors: [{message: Field "UserInput.selectedOrganization" of required type "ID!" was not provided.,
        status: GRAPHQL_VALIDATION_FAILED,
        data: []}]}
      ))
```
The current issue persists for `SignUp` page which is most probably is being caused from the server side. I would like to know to if there is any existing issue in `talawa-api` who are working on this thing or should I link this issue and create one on `talawa-api`.

---

I am not closing this issue since there still persists an issue with signup on the mobile app. Once it gets solved on the backend side. I'll close this issue.





Pull request: Bug-Fix SignUp
**What kind of change does this PR introduce?**
Bug-Fix
<!-- E.g. a bugfix, feature, refactoring, etc… -->

**Issue Number:**
Fixes #2454 

**Did you add tests for your changes?**
Yes, I have made changed in the unit tests to make sure workflow doesn't fail.

**Snapshots/Videos:**
SignUp is working fine now

https://github.com/PalisadoesFoundation/talawa/assets/99138286/8834c360-8894-48ef-92bb-ccebd466caca

**If relevant, did you update the documentation?**
No

**Summary**
SignUp was failing for the app continuously which was acting as an hindrance to the other issues after the signup process. It solves the problem of SignUp and now the user can log in after signing it without any problem.


**Does this PR introduce a breaking change?**
Yes
<!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. -->

**Have you read the [contributing guide](https://github.com/PalisadoesFoundation/talawa/blob/master/CONTRIBUTING.md)?**
Yes
<!--Yes or No-->


Test command: nan

Fix patch:
diff --git a/lib/utils/queries.dart b/lib/utils/queries.dart
index 256aa26516..60234d4228 100644
--- a/lib/utils/queries.dart
+++ b/lib/utils/queries.dart
@@ -10,6 +10,7 @@ class Queries {
   /// * `lastName`: user's data.
   /// * `email`: user's data.
   /// * `password`: user's data.
+  /// * `selectedOrganization`: ID of the selected organization.
   ///
   /// **returns**:
   /// * `String`: Return the mutation in string type to be passed to graphql client.
@@ -18,10 +19,11 @@ class Queries {
     String lastName,
     String email,
     String password,
+    String? selectedOrganization,
   ) {
     return """
         mutation{
-          signUp(data: {firstName: "$firstName", lastName: "$lastName", email: "$email", password: "$password"})
+          signUp(data: {firstName: "$firstName", lastName: "$lastName", email: "$email", password: "$password", selectedOrganization: "$selectedOrganization"})
           {
             appUserProfile{
               adminFor{
diff --git a/lib/view_model/pre_auth_view_models/signup_details_view_model.dart b/lib/view_model/pre_auth_view_models/signup_details_view_model.dart
index 2fc3c14515..494afac0b5 100644
--- a/lib/view_model/pre_auth_view_models/signup_details_view_model.dart
+++ b/lib/view_model/pre_auth_view_models/signup_details_view_model.dart
@@ -135,6 +135,7 @@ class SignupDetailsViewModel extends BaseModel {
             Encryptor.encryptString(
               password.text,
             ),
+            selectedOrganization.id,
           ),
         );
         navigationService.pop();


Test patch:
diff --git a/test/utils_tests/queries_test.dart b/test/utils_tests/queries_test.dart
index 6fffa67398..cdb43da4da 100644
--- a/test/utils_tests/queries_test.dart
+++ b/test/utils_tests/queries_test.dart
@@ -10,8 +10,13 @@ void main() {
       var mutation = false;
       expect(mutation, false);
 
-      final fnData = Queries()
-          .registerUser('Ayush', 'Chaudhary', 'ayush@gmail.com', 'password');
+      final fnData = Queries().registerUser(
+        'Ayush',
+        'Chaudhary',
+        'ayush@gmail.com',
+        'password',
+        'orgId123',
+      );
       if (fnData.contains('Ayush')) {
         mutation = true;
       }
diff --git a/test/view_model_tests/pre_auth_view_models/signup_details_view_model_test.dart b/test/view_model_tests/pre_auth_view_models/signup_details_view_model_test.dart
index cfd954522b..a98bf1a029 100644
--- a/test/view_model_tests/pre_auth_view_models/signup_details_view_model_test.dart
+++ b/test/view_model_tests/pre_auth_view_models/signup_details_view_model_test.dart
@@ -49,7 +49,7 @@ class SignUpMock extends StatelessWidget {
 }
 
 OrgInfo get org => OrgInfo(
-      id: '3',
+      id: '',
       name: 'test org 3',
       userRegistrationRequired: userRegistrationRequired,
       creatorInfo: User(firstName: 'test', lastName: '1'),
@@ -84,13 +84,13 @@ void main() {
         source: QueryResultSource.network,
         data: data,
         options: QueryOptions(
-          document: gql(queries.registerUser('', '', '', '')),
+          document: gql(queries.registerUser('', '', '', '', '')),
         ),
       );
       when(graphqlConfig.getToken()).thenAnswer((_) async => true);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => result);
       when(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)))
@@ -116,7 +116,7 @@ void main() {
       verify(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)));
       verify(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       );
       verify(
@@ -143,12 +143,12 @@ void main() {
       locator.registerSingleton<UserConfig>(MockUserConfig());
 
       final model = SignupDetailsViewModel();
-
+      model.selectedOrganization = OrgInfo(id: "");
       await tester.pumpWidget(SignUpMock(formKey: model.formKey));
 
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => null);
 
@@ -194,13 +194,13 @@ void main() {
         source: QueryResultSource.network,
         data: data,
         options: QueryOptions(
-          document: gql(queries.registerUser('', '', '', '')),
+          document: gql(queries.registerUser('', '', '', '', '')),
         ),
       );
       when(graphqlConfig.getToken()).thenAnswer((_) async => false);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => result);
 
@@ -301,13 +301,13 @@ void main() {
         source: QueryResultSource.network,
         data: data,
         options: QueryOptions(
-          document: gql(queries.registerUser('', '', '', '')),
+          document: gql(queries.registerUser('', '', '', '', '')),
         ),
       );
       when(graphqlConfig.getToken()).thenAnswer((_) async => true);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => result);
       when(
@@ -340,7 +340,7 @@ void main() {
       );
       verify(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       );
       verify(
@@ -364,7 +364,7 @@ void main() {
       when(graphqlConfig.getToken()).thenAnswer((_) async => true);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenThrow(Exception());
 
@@ -374,7 +374,7 @@ void main() {
 
       verify(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       );
       verifyNever(
@@ -416,13 +416,15 @@ void main() {
         source: QueryResultSource.network,
         data: data,
         options: QueryOptions(
-          document: gql(queries.registerUser('', '', '', '')),
+          document: gql(
+            queries.registerUser('', '', '', '', ''),
+          ),
         ),
       );
       when(graphqlConfig.getToken()).thenAnswer((_) async => true);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => result);
       when(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)))
@@ -435,7 +437,7 @@ void main() {
       verify(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)));
       verify(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       );
       verifyNever(
@@ -478,13 +480,15 @@ void main() {
         source: QueryResultSource.network,
         data: data,
         options: QueryOptions(
-          document: gql(queries.registerUser('', '', '', '')),
+          document: gql(
+            queries.registerUser('', '', '', '', ''),
+          ),
         ),
       );
       when(graphqlConfig.getToken()).thenAnswer((_) async => true);
       when(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       ).thenAnswer((_) async => result);
       when(
@@ -503,7 +507,7 @@ void main() {
       );
       verify(
         databaseFunctions.gqlNonAuthMutation(
-          queries.registerUser('', '', '', ''),
+          queries.registerUser('', '', '', '', ''),
         ),
       );
       verifyNever(