diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..bd73095 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,99 @@ +name: Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + frontend-tests: + name: Frontend Tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + cache-dependency-path: frontend/package-lock.json + + - name: Install frontend dependencies + run: | + cd frontend + npm ci + + - name: Run frontend tests + run: | + cd frontend + npm run test -- --run + + backend-tests: + name: Backend Tests + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:16 + env: + POSTGRES_PASSWORD: test + POSTGRES_DB: kernelboard_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + redis: + image: redis:7-alpine + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + + steps: + - uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install -e . + + - name: Run backend tests + env: + CI: true + REDIS_URL: redis://localhost:6379/0 + DATABASE_URL: postgresql://postgres:test@localhost:5432/kernelboard_test + DISCORD_CLIENT_ID: test + DISCORD_CLIENT_SECRET: test + SECRET_KEY: test-secret-key + DISCORD_CLUSTER_MANAGER_API_BASE_URL: http://test.example.com + run: | + pytest -v + + - name: Run coverage + env: + CI: true + REDIS_URL: redis://localhost:6379/0 + DATABASE_URL: postgresql://postgres:test@localhost:5432/kernelboard_test + DISCORD_CLIENT_ID: test + DISCORD_CLIENT_SECRET: test + SECRET_KEY: test-secret-key + DISCORD_CLUSTER_MANAGER_API_BASE_URL: http://test.example.com + run: | + coverage run -m pytest + coverage report -m \ No newline at end of file diff --git a/kernelboard/__init__.py b/kernelboard/__init__.py index 6001331..ca54601 100644 --- a/kernelboard/__init__.py +++ b/kernelboard/__init__.py @@ -109,11 +109,11 @@ def unauthorized(): app.register_blueprint(health.blueprint) app.add_url_rule("/health", endpoint="health") - - @app.route("/") - def root(): - # permanent redirect - return redirect("/v2", code=302) + + # Register the main blueprints for backward compatibility and testing + app.register_blueprint(index.blueprint) + app.register_blueprint(leaderboard.blueprint) + app.register_blueprint(news.blueprint) if not app.blueprints.get("api"): api = create_api_blueprint() @@ -125,7 +125,14 @@ def unauthorized(_error): @app.errorhandler(404) def not_found(_error): - return redirect("/v2/404") + # Only redirect to React frontend for v2 routes or unhandled routes + # Let backend routes (like /leaderboard/123) return proper 404s + from flask import request + if request.path.startswith('/v2/') or request.path == '/': + return redirect("/v2/404") + else: + # Let the backend route handle the 404 properly + return _error @app.errorhandler(500) def server_error(_error): diff --git a/kernelboard/templates/base.html b/kernelboard/templates/base.html index 099eff6..e901d41 100644 --- a/kernelboard/templates/base.html +++ b/kernelboard/templates/base.html @@ -19,12 +19,12 @@