Skip to content

Commit 296eed1

Browse files
committed
chore: add unittest project and setup
1 parent a511dfb commit 296eed1

32 files changed

+8082
-0
lines changed

tests/Taskfile.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
tasks:
3+
start_app:
4+
desc: "Start the application server for testing"
5+
cmds:
6+
- "cd application && pnpm migrate:local && pnpm install && pnpm start"

tests/application/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.db.sqlite

tests/application/.env.local

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ADMINFORTH_SECRET=123
2+
NODE_ENV=development
3+
SQLITE_URL=sqlite://migrations/prisma/sqlite/.db.sqlite
4+
SQLITE_FILE_URL=file:.db.sqlite
5+
6+
CH_MIGRATIONS_HOME=./migrations/clickhouse_migrations
7+
CH_MIGRATIONS_HOST=localhost:28124/demo
8+
CH_MIGRATIONS_USER=demo
9+
CH_MIGRATIONS_PASSWORD=demo
10+
11+
AWS_REGION=eu-central-1
12+
AWS_BUCKET_NAME=tmpbucket-adminforth
13+
AWS_ACCESS_KEY_ID=your_access_key_id
14+
AWS_SECRET_ACCESS_KEY=your_secret_access_key

tests/application/.env.prod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ENV=production
2+
DATABASE_URL=sqlite:////code/db/.db.sqlite
3+
PRISMA_DATABASE_URL=file:/code/db/.db.sqlite

tests/application/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Dependency directories
2+
node_modules/
3+
4+
# dotenv environment variable files
5+
.env
6+
7+
.db.sqlite
8+
db

tests/application/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
FROM devforth/node20-pnpm:latest
3+
WORKDIR /code/
4+
ADD package.json pnpm-lock.yaml pnpm-workspace.yaml /code/
5+
RUN pnpm i
6+
ADD . /code/
7+
RUN pnpm exec adminforth bundle
8+
CMD ["sh", "-c", "pnpm migrate:prod && pnpm prod"]

tests/application/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Starting the application
2+
3+
Install dependencies:
4+
5+
```bash
6+
pnpm i
7+
```
8+
9+
Migrate the database:
10+
11+
```bash
12+
pnpm migrate:local
13+
```
14+
15+
Start the server:
16+
17+
```bash
18+
pnpm dev
19+
```
20+
21+
## Changing schema
22+
23+
Open `schema.prisma` and change schema as needed: add new tables, columns, etc (See [Prisma schema reference](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema)).
24+
25+
Run the following command to generate a new migration and apply it instantly in local database:
26+
27+
```bash
28+
pnpm makemigration --name <name_of_changes>
29+
```
30+
31+
Your colleagues will need to pull the changes and run `pnpm migrate:local` to apply the migration in their local database.
32+
33+
## Deployment tips
34+
35+
You have Dockerfile ready for production deployment. You can test the build with:
36+
37+
```bash
38+
docker build -t application-image .
39+
docker run -p 3500:3500 -e ADMINFORTH_SECRET=123 -v $(pwd)/db:/code/db application-image
40+
```
41+
42+
To set non-sensitive environment variables in production, use `.env.prod` file.
43+
For sensitive variables, use direct docker environment variables or secrets from your vault.
44+
45+
## Documentation
46+
47+
- [Customizing AdminForth Branding](https://adminforth.dev/docs/tutorial/Customization/branding/)
48+
- [Custom Field Rendering](https://adminforth.dev/docs/tutorial/Customization/customFieldRendering/)
49+
- [Hooks](https://adminforth.dev/docs/tutorial/Customization/hooks/)
50+
- [Custom Pages](https://adminforth.dev/docs/tutorial/Customization/customPages/)

tests/application/api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Express, Request, Response } from "express";
2+
import { IAdminForth } from "adminforth";
3+
export function initApi(app: Express, admin: IAdminForth) {
4+
app.get(`${admin.config.baseUrl}/api/hello/`,
5+
async (req: Request, res: Response) => {
6+
const allUsers = await admin.resource("adminuser").list([]);
7+
res.json({
8+
message: "Hello from AdminForth API!",
9+
users: allUsers,
10+
});
11+
}
12+
);
13+
}

0 commit comments

Comments
 (0)