Skip to content
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
15 changes: 0 additions & 15 deletions .buildkite/pipeline.yml

This file was deleted.

1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

29 changes: 15 additions & 14 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
NEXT_PUBLIC_BASE_URL=http://localhost:3000
PGHOST=
PGPORT=5432
PGUSER=
PGHOST=127.0.0.1
PGPORT=54322
PGUSER=postgres
PGDATABASE=postgres
PGPASSWORD=
PGPASSWORD=postgres
SENTRY_DSN=sentryDsn
SENTRY_ENV=sentryEnv
PUBLIC_S3_BASE_URL=https://test.example.com
S3_ENDPOINT=
S3_ENDPOINT=http://127.0.0.1:54321/storage/v1/s3
S3_REGION=local
S3_ACCESS_KEY_ID=accesskeyneedstobeexactly32chars
S3_ACCESS_KEY_SECRET=12345678
S3_MAPS_BUCKET=paradb-maps-test
MEILISEARCH_HOST=https://
MEILISEARCH_KEY=123
SEARCH_IMPLEMENTATION=postgres
MEILISEARCH_HOST=unused
MEILISEARCH_KEY=unused
FLAGS_IMPLEMENTATION=local
FLAGS_EDGE_CONFIG=
FLAGS_EDGE_CONFIG_KEY=
NEXT_PUBLIC_SUPABASE_URL=
FLAGS_EDGE_CONFIG=unused
FLAGS_EDGE_CONFIG_KEY=unused
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=
SUPABASE_SECRET_KEY=
AXIOM_API_TOKEN=
AXIOM_DATASET=
NEXT_PUBLIC_AXIOM_API_TOKEN=
NEXT_PUBLIC_AXIOM_DATASET=
AXIOM_API_TOKEN=unused
AXIOM_DATASET=unused
NEXT_PUBLIC_AXIOM_API_TOKEN=unused
NEXT_PUBLIC_AXIOM_DATASET=unused
61 changes: 61 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read

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

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Setup Supabase CLI
uses: supabase/setup-cli@v1
with:
version: latest

- name: Start Supabase
run: supabase start

- name: Write Supabase tokens into .env.test
run: |
supabase status -o env > /tmp/supabase_env
source /tmp/supabase_env
sed -i "s|^NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=.*|NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=$ANON_KEY|" .env.test
sed -i "s|^SUPABASE_SECRET_KEY=.*|SUPABASE_SECRET_KEY=$SERVICE_ROLE_KEY|" .env.test

- name: Typecheck and lint
run: bun check

- name: Start dev server
run: |
./node_modules/.bin/dotenv -e .env.test -- bun next dev &
# Wait for the server to be ready
for i in $(seq 1 30); do
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo "Server is ready"
break
fi
echo "Waiting for server to start... ($i/30)"
sleep 2
done

- name: Run tests
run: bun test

- name: Stop Supabase
if: always()
run: supabase stop
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Although you are taking on the persona of an intern developer, your skills are t

This is a website that allows users to host custom maps and songs for a rhythm drumming game called "Paradiddle".
Custom maps consist of a zip file, which contains a .rlrr metadata file along with the audio tracks for the song. The audio tracks can either be the song itself, or the audio stems of the song that can allow the game to play the song without any drum track (as the player will be drumming along themselves).
The codebase uses Docker to run third-party services locally (Meilisearch for search, Minio for a local S3 instance), the local Supabase CLI for running the Supabase database locally, and the standad Next.js dev mode to run the backend and frontend locally.
The codebase uses the local Supabase CLI for running the Supabase database locally (which includes Postgres and Auth), and the standard Next.js dev mode to run the backend and frontend locally. S3 is used for blob storage (locally provided by Supabase Storage's S3-compatible API).

# Tech stack

Expand Down Expand Up @@ -36,9 +36,9 @@ The codebase uses Docker to run third-party services locally (Meilisearch for se

# Commands

- `bun dev` will start local services on Docker
- `bun dev:local` will start Next.js in dev mode with local env
- `bun supabase start` will start Supabase locally
- `bun next dev` will run Next.js in dev mode
- `bun test` will run the test suite
- `bun format` will format the codebase with Prettier
- `bun check` will typecheck and lint

Expand Down
14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions Dockerfile.dev

This file was deleted.

25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ git clone https://github.com/bitnimble/paradb.git
cd paradb
bun install

# Install and start postgres
sudo apt install postgresql
sudo service postgresql start
# Start local Supabase (requires Supabase CLI)
bun supabase start

# Create postgres user for yourself
sudo -u postgres createuser --interactive --pwprompt
# Copy the example env file and fill in any missing values
cp .env.test .env.localdev

# Edit .env to fill out your username and password!
# Start the dev server
bun dev:local
```

## Running tests

# Create db and instantiate schema
createdb paradb
db/init.sh
```
# Ensure local Supabase is running
bun supabase start

# Start server
bun dev
# Run tests
bun test
```
47 changes: 0 additions & 47 deletions docker/docker-compose.dev.yml

This file was deleted.

17 changes: 0 additions & 17 deletions docker/docker-compose.test.yml

This file was deleted.

35 changes: 0 additions & 35 deletions docker/docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const createJestConfig = nextJest({ dir: './' });

const config = {
testMatch: ['**/tests/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
globalSetup: '<rootDir>/src/services/jest_global_setup.ts',
setupFilesAfterEnv: ['<rootDir>/src/services/jest_setup.ts'],
modulePaths: ['<rootDir>/src'],
};
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
"dev:local": "dotenv -e .env.localdev -- bun next dev",
"dev:dev": "dotenv -e .env.dev -- bun next dev",
"dev:prod": "dotenv -e .env.prod -- bun next dev",
"build": "sudo docker compose -f docker/docker-compose.yml --env-file .env build",
"start": "sudo docker compose -f docker/docker-compose.yml --env-file .env up --build",
"check": "bun tsc && bun eslint .",
"lint": "eslint .",
"format": "prettier . --write",
"schema": "tools/update_schema.sh",
"test": "sudo docker compose -f docker/docker-compose.test.yml --env-file .env.test up --build --abort-on-container-exit"
"test": "dotenv -e .env.test -- bun jest --runInBand"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.958.0",
Expand Down
32 changes: 32 additions & 0 deletions src/services/jest_global_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { loadEnvConfig } from '@next/env';
import { Pool } from 'pg';

const projectDir = process.cwd();
loadEnvConfig(projectDir);

/**
* Ensures the database is in a clean state before the test suite runs.
* Truncates all app tables and auth users, then seeds with test data.
*
* Tables are expected to already exist via `supabase start` (which applies
* migrations and schemas). This avoids using `supabase db reset` which
* would clobber non-test local state.
*/
export default async function globalSetup() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this function isn't actually deleting anything, and is still looking at the 'public' schema instead of a separate test one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7fe04ee. Tests now use a separate paradb_test Postgres schema instead of public:

  • globalSetup creates the paradb_test schema, drops+recreates tables from the DDL files, seeds test data, and deletes leftover auth users
  • .env.test sets PGOPTIONS=-c search_path=paradb_test,public so all DB queries (both Jest and the dev server) route to the test schema
  • beforeEach truncates paradb_test.* tables specifically

Dev data in the public schema is untouched.

const pool = new Pool();

// Verify tables exist (they should from supabase start + migrations)
const expectedTables = ['maps', 'users', 'favorites', 'difficulties'];
const result = await pool.query(`
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = ANY($1)
`, [expectedTables]);
if (result.rows.length < expectedTables.length) {
throw new Error(
'Expected database tables not found. Make sure `supabase start` has been run ' +
'and migrations have been applied.'
);
}

await pool.end();
}
Loading
Loading