|
1 | 1 | ---
|
2 | 2 | id: testing
|
3 |
| -title: Testing |
| 3 | +title: Testing & Validation |
4 | 4 | slug: /developer-resources/testing
|
5 | 5 | sidebar_position: 4
|
6 | 6 | ---
|
7 | 7 |
|
8 |
| -## Introduction |
| 8 | +This section covers important tests to validate the operation of the API. |
9 | 9 |
|
10 |
| -Coming soon. |
| 10 | +## Accessing the API |
| 11 | + |
| 12 | +These are some important URLs for coding and troubleshooting: |
| 13 | + |
| 14 | +### Validation |
| 15 | + |
| 16 | +1. By default talawa-api runs on port 4000. It is available on the following endpoint: |
| 17 | + |
| 18 | + ``` |
| 19 | + http://127.0.0.1:4000 |
| 20 | + ``` |
| 21 | + |
| 22 | + - If you navigate to the endpoint you and see a JSON response like this. |
| 23 | + |
| 24 | + ```json |
| 25 | + { |
| 26 | + "message": "Route GET:/ not found", |
| 27 | + "error": "Not Found", |
| 28 | + "statusCode": 404 |
| 29 | + } |
| 30 | + ``` |
| 31 | + |
| 32 | +### GraphQL |
| 33 | + |
| 34 | +This section covers how to access the GraphQL API interface. |
| 35 | + |
| 36 | +#### Interactive Web Queries With GraphiQL |
| 37 | + |
| 38 | +The url for accessing the GraphQL Playground is |
| 39 | + |
| 40 | +```bash |
| 41 | +http://127.0.0.1:4000/graphiql |
| 42 | +``` |
| 43 | + |
| 44 | +#### Programmatic Queries With GraphiQL |
| 45 | + |
| 46 | +The graphQL endpoint for handling `queries` and `mutations` is this: |
| 47 | + |
| 48 | +``` |
| 49 | +http://127.0.0.1:4000/graphql/ |
| 50 | +``` |
| 51 | + |
| 52 | +1. This is the Organization URL to be used for: |
| 53 | + 1. The Talawa Mobile app |
| 54 | + 1. The Talawa Admin app |
| 55 | +1. If you navigate to the endpoint you and see a JSON response like this. |
| 56 | + |
| 57 | +```json |
| 58 | +{ "data": null, "errors": [{ "message": "Unknown query" }] } |
| 59 | +``` |
| 60 | + |
| 61 | +#### Subscriptions with GraphQL |
| 62 | + |
| 63 | +The GraphQL endpoint for handling `subscriptions` is: |
| 64 | + |
| 65 | +``` |
| 66 | +ws://127.0.0.1:4000/graphql/ |
| 67 | +``` |
| 68 | + |
| 69 | +## Database Management |
| 70 | + |
| 71 | +This section covers easy ways for developers to validate their work |
| 72 | + |
| 73 | +### CloudBeaver |
| 74 | + |
| 75 | +CloudBeaver is a lightweight web application designed for comprehensive data management. It allows you to work with various data sources, including SQL, NoSQL, and cloud databases, all through a single secure cloud solution accessible via a browser. |
| 76 | + |
| 77 | +#### Accessing the PostgreSQL Database using CloudBeaver |
| 78 | + |
| 79 | +1. Open your preferred browser and navigate to: |
| 80 | + ```bash |
| 81 | + http://127.0.0.1:8978/ |
| 82 | + ``` |
| 83 | +2. Log in to the CloudBeaver UI using the following credentials (these credentials can be modified in the `.env.devcontainer` file by changing the `CLOUDBEAVER_ADMIN_NAME` and `CLOUDBEAVER_ADMIN_PASSWORD` variables): |
| 84 | + ``` |
| 85 | + Username: talawa |
| 86 | + Password: password |
| 87 | + ``` |
| 88 | +3. You should now see the CloudBeaver UI. Click on the "New Connection" button and select `PostgreSQL` from the list of available connections. |
| 89 | +4. Fill in the connection details as follows: |
| 90 | + ``` |
| 91 | + Name: talawa |
| 92 | + Host: postgres |
| 93 | + Port: 5432 |
| 94 | + Database: talawa |
| 95 | + Username: talawa |
| 96 | + Password: password |
| 97 | + ``` |
| 98 | + - **Note:** The host name should match the one specified in the Docker Compose file and credentials should match those specified in the `.env.development` file. |
| 99 | +5. Check the `Save credentials for all users with access` option to avoid entering the credentials each time. |
| 100 | +6. Check the following boxes in the Database list: |
| 101 | + ```sql |
| 102 | + show all databases |
| 103 | + show template databases |
| 104 | + show unavailable databases |
| 105 | + show database statistics |
| 106 | + ``` |
| 107 | +7. Click `Create` to save the connection. |
| 108 | +8. You should now see the `PostgreSql@postgres` connection in the list of available connections. Click on the connection to open the database. |
| 109 | +9. Navigate to `PostgreSql@postgres > Databases > talawa > Schemas > public > Tables` to view the available schemas. |
| 110 | + |
| 111 | +#### Accessing the PostgreSQL Test Database using CloudBeaver |
| 112 | + |
| 113 | +1. Click on the `New Connection` button and select `PostgreSQL` from the list of available connections. |
| 114 | +2. Fill in the connection details as follows: |
| 115 | + |
| 116 | + ``` |
| 117 | + Name: talawa |
| 118 | + Host: postgrestest |
| 119 | + Port: 5432 |
| 120 | + Database: talawa |
| 121 | + Username: talawa |
| 122 | + Password: password |
| 123 | + ``` |
| 124 | + |
| 125 | + - **Note:** The host name should match the one specified in the Docker Compose file and credentials should match those specified in the `.env.development` file. |
| 126 | + |
| 127 | +3. Check the `Save credentials for all users with access` option to avoid entering the credentials each time. |
| 128 | +4. Check the following boxes in the Database list: |
| 129 | + ```sql |
| 130 | + show all databases |
| 131 | + show template databases |
| 132 | + show unavailable databases |
| 133 | + show database statistics |
| 134 | + ``` |
| 135 | +5. Click `Create` to save the connection. |
| 136 | +6. You should now see the `PostgreSql@postgres-test` connection in the list of available connections. Click on the connection to open the database. |
| 137 | +7. Navigate to `PostgreSql@postgres-test > Databases > talawa > Schemas > public > Tables` to view the available tables. |
| 138 | + |
| 139 | +## Object Storage Management |
| 140 | + |
| 141 | +MinIO is a free, open-source object storage server that's compatible with Amazon S3. It's designed for large-scale data storage and can run on-premises or in the cloud. |
| 142 | + |
| 143 | +### Accessing MinIO - (Production Environments) |
| 144 | + |
| 145 | +1. Open your preferred browser and navigate to: |
| 146 | + ```bash |
| 147 | + http://127.0.0.1:9001/ |
| 148 | + ``` |
| 149 | +2. Log in to the MinIO UI using the following credentials(these credentials can be modified in the env files by changing the `MINIO_ROOT_USER` and `MINIO_ROOT_PASSWORD` variables): |
| 150 | + - Username: `talawa` |
| 151 | + - Password: `password` |
| 152 | +3. You should now see the MinIO UI. Click on the `Login` button to access the MinIO dashboard. |
| 153 | +4. You can now view the available buckets and objects in the MinIO dashboard. |
| 154 | + |
| 155 | +### Accessing MinIO - (Development Environments) |
| 156 | + |
| 157 | +1. Open your preferred browser and navigate to: |
| 158 | + ```bash |
| 159 | + http://127.0.0.1:9003/ |
| 160 | + ``` |
| 161 | +2. Log in to the MinIO UI using the following credentials(these credentials can be modified in the `.env.devcontainer` file by changing the `MINIO_ROOT_USER` and `MINIO_ROOT_PASSWORD` variables): |
| 162 | + - Username: `talawa` |
| 163 | + - Password: `password` |
| 164 | +3. You should now see the MinIO UI. Click on the `Login` button to access the MinIO dashboard. |
| 165 | +4. You can now view the available buckets and objects in the MinIO dashboard. |
| 166 | + |
| 167 | +## Testing The API |
| 168 | + |
| 169 | +Use the `API_BASE_URL` URL configured in the `.env` file |
| 170 | + |
| 171 | +### Sign-in |
| 172 | + |
| 173 | +This endpoint is used to sign in a user. |
| 174 | + |
| 175 | +**Request:** |
| 176 | + |
| 177 | +```bash |
| 178 | + |
| 179 | +curl -X POST -H "Content-Type: application/json" -k <API_BASE_URL> -d '{ |
| 180 | + "query": "query signIn($input: QuerySignInInput!) { signIn(input: $input) { authenticationToken user { emailAddress id name } } }", |
| 181 | + "variables": { |
| 182 | + "input": { |
| 183 | + "emailAddress": "[email protected]", |
| 184 | + "password": "password" |
| 185 | + } |
| 186 | + } |
| 187 | +}' |
| 188 | + |
| 189 | +``` |
| 190 | + |
| 191 | +**Request Headers:** |
| 192 | + |
| 193 | +- `Content-Type: application/json` |
| 194 | + |
| 195 | +**Request Body:** |
| 196 | + |
| 197 | +```json |
| 198 | +{ |
| 199 | + "query": "query signIn($input: QuerySignInInput!) { signIn(input: $input) { authenticationToken user { emailAddress id name } } }", |
| 200 | + "variables": { |
| 201 | + "input": { |
| 202 | + "emailAddress": "[email protected]", |
| 203 | + "password": "password" |
| 204 | + } |
| 205 | + } |
| 206 | +} |
| 207 | +``` |
| 208 | + |
| 209 | +**Response:** |
| 210 | + |
| 211 | +- Returns the authentication token and user details (email address, id, and name). |
| 212 | + |
| 213 | +### Organization Creation |
| 214 | + |
| 215 | +This endpoint is used to create a new organization. |
| 216 | + |
| 217 | +**Request:** |
| 218 | + |
| 219 | +```bash |
| 220 | +curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <your_token>" -k <API_BASE_URL> -d '{ |
| 221 | + "query": "mutation Mutation_createOrganization($input: MutationCreateOrganizationInput!) { createOrganization(input: $input) { id name } }", |
| 222 | + "variables": { |
| 223 | + "input": { |
| 224 | + "name": "name0" |
| 225 | + } |
| 226 | + } |
| 227 | +}' |
| 228 | +``` |
| 229 | + |
| 230 | +**Request Headers:** |
| 231 | + |
| 232 | +- `Content-Type: application/json` |
| 233 | +- `Authorization: Bearer <your_token>` |
| 234 | + |
| 235 | +**Request Body:** |
| 236 | + |
| 237 | +```json |
| 238 | +{ |
| 239 | + "query": "mutation Mutation_createOrganization($input: MutationCreateOrganizationInput!) { createOrganization(input: $input) { id name } }", |
| 240 | + "variables": { |
| 241 | + "input": { |
| 242 | + "name": "name0" |
| 243 | + } |
| 244 | + } |
| 245 | +} |
| 246 | +``` |
| 247 | + |
| 248 | +**Response:** |
| 249 | + |
| 250 | +- Returns the newly created organization's ID and name. |
0 commit comments