Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: API Tests

on:
push:
branches: [main, develop, beta_developer]
paths:
- 'apps/api/**'
- '.github/workflows/api-test.yml'
- 'pnpm-lock.yaml'
pull_request:
branches: [main, develop, beta_developer]
paths:
- 'apps/api/**'
- '.github/workflows/api-test.yml'
- 'pnpm-lock.yaml'

jobs:
test:
name: Run API Tests
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nginx_waf_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8.15.0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Setup test environment
working-directory: apps/api
run: |
cp .env.test .env
echo "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/nginx_waf_test?schema=public" >> .env

- name: Generate Prisma Client
working-directory: apps/api
run: pnpm prisma generate

- name: Run database migrations
working-directory: apps/api
run: pnpm prisma migrate deploy
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/nginx_waf_test?schema=public

- name: Run tests
working-directory: apps/api
run: pnpm test:coverage
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/nginx_waf_test?schema=public
NODE_ENV: test
JWT_ACCESS_SECRET: test-access-secret-key-12345
JWT_REFRESH_SECRET: test-refresh-secret-key-12345
JWT_ACCESS_EXPIRES_IN: 15m
JWT_REFRESH_EXPIRES_IN: 7d
SESSION_SECRET: test-session-secret-12345
CORS_ORIGIN: http://localhost:5173,http://localhost:3000
BCRYPT_ROUNDS: 4
TWO_FACTOR_APP_NAME: Nginx WAF Admin Test
BACKUP_DIR: ./test-backups
SSL_DIR: ./test-ssl
PORT: 3001

- name: 'Report Coverage'
# Set if: always() to also generate the report if tests are failing
# Only works if you set `reportOnFailure: true` in your vite config as specified above
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
working-directory: apps/api
30 changes: 30 additions & 0 deletions apps/api/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Test Environment Configuration
NODE_ENV=test

# Test Database (PostgreSQL in Docker)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/nginx_waf_test?schema=public"

# JWT Secrets (test values)
JWT_ACCESS_SECRET="test-access-secret-key-12345"
JWT_REFRESH_SECRET="test-refresh-secret-key-12345"
JWT_ACCESS_EXPIRES_IN="15m"
JWT_REFRESH_EXPIRES_IN="7d"

# Session
SESSION_SECRET="test-session-secret-12345"

# CORS
CORS_ORIGIN="http://localhost:5173,http://localhost:3000"

# BCrypt (lower rounds for faster tests)
BCRYPT_ROUNDS="4"

# 2FA
TWO_FACTOR_APP_NAME="Nginx WAF Admin Test"

# Paths (test paths)
BACKUP_DIR="./test-backups"
SSL_DIR="./test-ssl"

# Server
PORT=3001
1 change: 1 addition & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist/
coverage/
.vscode/
.idea/
!src/domains/logs/
21 changes: 18 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage",
"clean": "rm -rf dist node_modules",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev",
Expand All @@ -16,7 +20,12 @@
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"keywords": ["nginx", "waf", "modsecurity", "admin"],
"keywords": [
"nginx",
"waf",
"modsecurity",
"admin"
],
"author": "",
"license": "MIT",
"dependencies": {
Expand All @@ -32,8 +41,8 @@
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"nodemailer": "^6.9.14",
"speakeasy": "^2.0.0",
"qrcode": "^1.5.4",
"speakeasy": "^2.0.0",
"winston": "^3.13.1"
},
"devDependencies": {
Expand All @@ -47,9 +56,15 @@
"@types/nodemailer": "^6.4.15",
"@types/qrcode": "^1.5.5",
"@types/speakeasy": "^2.0.10",
"@types/supertest": "^6.0.3",
"@vitest/coverage-v8": "3.2.4",
"@vitest/ui": "^3.2.4",
"prisma": "^5.18.0",
"supertest": "^7.1.4",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.5.4"
"typescript": "^5.5.4",
"vitest": "^3.2.4",
"zod": "^4.1.11"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterEnum
ALTER TYPE "ActivityType" ADD VALUE 'system';

-- AlterTable
ALTER TABLE "activity_logs" ALTER COLUMN "userId" DROP NOT NULL;
6 changes: 3 additions & 3 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ model TwoFactorAuth {
}

model ActivityLog {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
id String @id @default(cuid())
userId String?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)

action String
type ActivityType
Expand Down
72 changes: 0 additions & 72 deletions apps/api/setup.sh

This file was deleted.

113 changes: 0 additions & 113 deletions apps/api/src/config/crs-rules.ts

This file was deleted.

Loading
Loading