Skip to content

Commit 4ff9d91

Browse files
Sample Data Loading and Test in GitHub Action (#3223)
* DB testing Workflow * workflow * fix data readibility * dynamic insertion * dynamic testing * prettier * Clean Code * finalizing * comment * graceful exit * pretty * pretty * Test case * pretty * basic testing * pretty * Empty commit * type check * pretty * coderabbit * Empty commit * changes * change * pretty * Final test * major changes * correction * docs * prettier * finalizing * test modifications * test modify * pretty * remove test * environment setup * changes * documentation updated * documentation * documentation * documentation * test * module * major testing improvement * test * pretty * xoldd, coderabbit ai implementation * changes * fix * improvements * improvements * code quality * removed unnecessary packages * fix * remove unwanted package (xoldd) * fix * test database * code-quality * manipulate db * fix * backward compatibility * fix * final * cleaning * corrected environment * host managment * fixed code quality * sample * removed unncessary dependencies * roll back to postgres env * pretty * pretty * fix * added tests * fix * vitest is sufficient * coderabbit * docker environment configuration * docs --------- Co-authored-by: JaiPannu-IITI <[email protected]>
1 parent 9198850 commit 4ff9d91

File tree

17 files changed

+1153
-697
lines changed

17 files changed

+1153
-697
lines changed

.github/workflows/pull-request.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,3 @@ jobs:
313313
run: |
314314
source venv/bin/activate
315315
python .github/workflows/scripts/check_docstrings.py --directories .github
316-
317-
318-
# Import-Sample-Data:
319-
# name: Import Sample Data
320-
# runs-on: ubuntu-latest
321-
# steps:
322-
# - name: Checkout this repository
323-
# uses: actions/[email protected]
324-
# - name: Create .env file for talawa api testing environment
325-
# run: cp ./envFiles/.env.ci ./.env
326-
# - name: Build talawa api non production environment docker image
327-
# run: docker compose build
328-
# - name: Run import:sample-data
329-
# uses: addnab/docker-run-action@v3
330-
# with:
331-
# image: talawa_api
332-
# options: --env-file ./envFiles/.env.ci
333-
# run: pnpm run import:sample-data

docker/api.Containerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ USER talawa
3737
RUN curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell \
3838
# Appends the fnm configuration to `/home/talawa/.bashrc` file.
3939
&& echo eval \"\$\(fnm env --corepack-enabled --resolve-engines --use-on-cd --version-file-strategy=recursive\)\" >> /home/talawa/.bashrc
40+
# Set the PATH for all shells
41+
ENV NODE_VERSION=23.7.0
42+
ENV PATH="/home/talawa/.local/share/fnm/node-versions/v${NODE_VERSION}/installation/bin:/home/talawa/.local/share/fnm/node-versions/v${NODE_VERSION}/installation/lib/node_modules/corepack/shims:${PATH}"
4043
ENV PATH=/home/talawa/.local/share/fnm:${PATH}
4144
WORKDIR /home/talawa/api
4245

docs/docs/docs/developer-resources/testing.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ This section covers important tests to validate the operation of the API.
1010
### Sample Database Login Credentials
1111

1212
If the API:
13+
1314
1. is running with an unmodified `.env` file copied from `envFiles/.env.devcontainer` and;
1415
2. the API sample database is loaded;
15-
then you can use these login credentials to access the API via various clients.
16+
then you can use these login credentials to access the API via various clients.
1617

1718
| Email | Password | User Type | Joined Organization |
1819
| -----------------------------------| -------- | ---------------| -------------------- |
@@ -186,6 +187,57 @@ CloudBeaver is a lightweight web application designed for comprehensive data man
186187
6. You should now see the `PostgreSql@postgres-test` connection in the list of available connections. Click on the connection to open the database.
187188
7. Navigate to `PostgreSql@postgres-test > Databases > talawa > Schemas > public > Tables` to view the available tables.
188189

190+
## Resetting Database (Interactive)
191+
192+
**NOTE:** This applies only to Talawa API developers.
193+
194+
Sometimes you may want to start all over again from scratch. These steps ensure all tables emptied and the default administrator account automatically restored.
195+
196+
### Using the CLI (Dev Containers)
197+
198+
This applies to users running Talawa API in dev containers.
199+
200+
1. Once the server is running, open a new terminal session.
201+
202+
2. Open a bash session inside the running container:
203+
204+
```bash
205+
docker exec -it talawa-api-1 /bin/bash
206+
```
207+
208+
3. **WARNING:** This command will **DELETE** all data from each table in your database, administrator roles will be restored. Use with extreme caution.
209+
210+
```bash
211+
pnpm run reset:db
212+
```
213+
214+
4. This command will add sample data to make it easier for developers to get an understanding of the application.
215+
216+
```bash
217+
pnpm run add:sample_data
218+
```
219+
220+
5. Then exit
221+
222+
```bash
223+
exit
224+
```
225+
226+
### Using VS Code Dev Container
227+
228+
This applies to users running Talawa API in dev containers and VSCode.
229+
230+
1. **WARNING:** This command will **DELETE** all data from each table in your database, administrator roles will be restored. Use with extreme caution.
231+
```bash
232+
pnpm run reset:db
233+
```
234+
2. This command will add sample data to make it easier for developers to get an understanding of the application.
235+
```bash
236+
pnpm run add:sample_data
237+
```
238+
239+
Now you can resume your development work.
240+
189241
## Object Storage Management
190242

191243
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.

docs/docs/docs/getting-started/installation.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,24 +387,31 @@ You can run the app after closing the terminal or restating the vscode using the
387387

388388
We have created sample data to make it easier for end users to get an understanding of the application.
389389

390-
### Importing Sample Data
390+
### Using the CLI (Dev Containers)
391391

392392
This applies to users running Talawa API in dev containers.
393393

394394
1. Once the server is running, open a new terminal session.
395-
2. Open a bash session inside the running container:
396-
```bash
397-
docker exec -it talawa-api-1 /bin/bash
398-
```
399-
3. Inside the container, run the following command to import sample data into the database:
395+
396+
2. Run the following command to import sample data into the database:
397+
400398
```bash
401-
pnpm run import:sample-data
399+
docker exec talawa-api-1 /bin/bash -c 'pnpm run add:sample_data && exit'
402400
```
403-
4. Then exit
401+
402+
Refer to the next section for login information.
403+
404+
### Using VS Code Dev Container
405+
406+
This applies to users running Talawa API in dev containers and VSCode.
407+
408+
1. Open a terminal inside the container.
409+
410+
2. Run the following command to import sample data into the database:
411+
404412
```bash
405-
exit
413+
pnpm run add:sample_data
406414
```
407-
Refer to the next section for login information.
408415

409416
### Sample Data Users
410417

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,17 @@
1717
"close-with-grace": "^2.2.0",
1818
"drizzle-orm": "^0.39.1",
1919
"drizzle-zod": "0.6.1",
20-
"dotenv": "^16.0.3",
2120
"env-schema": "^6.0.1",
2221
"fastify": "^5.2.1",
2322
"fastify-plugin": "^5.0.1",
2423
"graphql": "^16.10.0",
2524
"graphql-scalars": "^1.24.0",
2625
"graphql-upload-minimal": "^1.6.1",
27-
"inquirer": "^12.4.1",
2826
"mercurius": "^16.0.1",
2927
"mercurius-upload": "^8.0.0",
3028
"minio": "^8.0.4",
3129
"postgres": "^3.4.5",
3230
"ulidx": "^2.4.1",
33-
"uuid": "^11.0.5",
3431
"uuidv7": "^1.0.2",
3532
"zod": "^3.24.1"
3633
},
@@ -88,7 +85,8 @@
8885
"generate_drizzle_migrations": "drizzle-kit generate",
8986
"generate_graphql_sdl_file": "tsx ./scripts/generateGraphQLSDLFile.ts",
9087
"generate_gql_tada": "gql.tada generate-output && gql.tada turbo --fail-on-warn",
91-
"import:sample-data": "tsx ./src/utilities/loadSampleData.ts",
88+
"reset:db": "tsx ./scripts/dbManagement/resetDB.ts",
89+
"add:sample_data": "tsx ./scripts/dbManagement/addSampleData.ts",
9290
"push_drizzle_schema": "drizzle-kit push",
9391
"push_drizzle_test_schema": "drizzle-kit push --config=./test/drizzle.config.ts",
9492
"run_tests": "vitest --coverage",

0 commit comments

Comments
 (0)