Skip to content

Commit 558e1d8

Browse files
committed
adding e2e testing, most of them pass :D
1 parent 2165f8a commit 558e1d8

26 files changed

Lines changed: 2470 additions & 58 deletions

docker-compose.test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
postgres_test:
3+
image: postgres:16-alpine
4+
container_name: tiny_racing_test_db
5+
restart: unless-stopped
6+
environment:
7+
POSTGRES_DB: tiny_racing_test
8+
POSTGRES_USER: tiny_racing_test
9+
POSTGRES_PASSWORD: test_password
10+
ports:
11+
- "5433:5432"
12+
volumes:
13+
- tiny_racing_test_data:/var/lib/postgresql/data
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U tiny_racing_test"]
16+
interval: 2s
17+
timeout: 3s
18+
retries: 10
19+
networks:
20+
- tiny_racing_test_network
21+
22+
networks:
23+
tiny_racing_test_network:
24+
driver: bridge
25+
26+
volumes:
27+
tiny_racing_test_data:
28+

server/examples/seed_db.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ async fn seed_random_cars_and_drivers(
575575
let mut rng = rand::rng();
576576

577577
// Get the maximum car number to start from
578-
let existing_cars = list_cars(db.pool()).await?;
578+
let existing_cars = list_cars(db.pool(), 10000, 0).await?;
579579
let max_car_number = existing_cars.iter().map(|c| c.number).max().unwrap_or(0);
580580
let mut next_car_number = max_car_number + 1;
581581

@@ -684,6 +684,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
684684
println!("Connecting to database...");
685685
let db = Database::new(&database_url).await?;
686686

687+
println!("Running migrations...");
688+
db.migrate().await?;
689+
println!("Migrations completed!");
690+
687691
// Seed players
688692
println!("\n=== Seeding Players ===");
689693
for player_data in PLAYERS {
@@ -875,13 +879,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
875879

876880
// Print summary
877881
println!("\n=== Seeding Summary ===");
878-
let teams = list_teams(db.pool()).await?;
879-
let cars = list_cars(db.pool()).await?;
880-
let drivers = list_drivers(db.pool()).await?;
881-
let tracks = list_tracks(db.pool()).await?;
882+
let teams = list_teams(db.pool(), 10000, 0).await?;
883+
let cars = list_cars(db.pool(), 10000, 0).await?;
884+
let drivers = list_drivers(db.pool(), 10000, 0).await?;
885+
let tracks = list_tracks(db.pool(), 10000, 0).await?;
882886

883-
let unassigned_cars = list_unassigned_cars(db.pool()).await?;
884-
let unassigned_drivers = list_unassigned_drivers(db.pool()).await?;
887+
let unassigned_cars = list_unassigned_cars(db.pool(), 10000, 0).await?;
888+
let unassigned_drivers = list_unassigned_drivers(db.pool(), 10000, 0).await?;
885889

886890
println!("Total teams in database: {}", teams.len());
887891
println!(

server/examples/seed_db_test.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Test-specific seed script that creates a test user
2+
// This is based on seed_db.rs but ensures testuser exists with known credentials
3+
// Run with: cargo run --example seed_db_test
4+
5+
use tiny_racing::database::*;
6+
7+
const TEST_PLAYER: &str = "testuser";
8+
const TEST_PASSWORD: &str = "testpass123";
9+
const TEST_EMAIL: &str = "testuser@test.com";
10+
11+
#[tokio::main]
12+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
13+
// Get database URL from environment or use test default
14+
let database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| {
15+
"postgresql://tiny_racing_test:test_password@localhost:5433/tiny_racing_test".to_string()
16+
});
17+
18+
println!("Connecting to test database...");
19+
let db = Database::new(&database_url).await?;
20+
21+
println!("Running migrations...");
22+
db.migrate().await?;
23+
println!("Migrations completed!");
24+
25+
// Ensure test user exists
26+
println!("\n=== Ensuring Test User Exists ===");
27+
let test_player = match get_player_by_username(db.pool(), TEST_PLAYER).await? {
28+
Some(player) => {
29+
println!("Test user '{}' already exists (ID: {})", player.username, player.id);
30+
player
31+
}
32+
None => {
33+
println!("Creating test user '{}'...", TEST_PLAYER);
34+
let player = create_player(
35+
db.pool(),
36+
CreatePlayerRequest {
37+
username: TEST_PLAYER.to_string(),
38+
password: TEST_PASSWORD.to_string(),
39+
email: Some(TEST_EMAIL.to_string()),
40+
},
41+
)
42+
.await?;
43+
println!("Created test user: {} (ID: {})", player.username, player.id);
44+
player
45+
}
46+
};
47+
48+
// Assign team #1 to test user if not already assigned
49+
println!("\n=== Assigning Team to Test User ===");
50+
let team = get_team_by_number(db.pool(), 1).await?;
51+
if let Some(team) = team {
52+
if team.player_id.is_none() {
53+
// Update team to assign to test user
54+
// Note: You may need to add an update_team function to the database module
55+
println!("Team #1 ({}) is not assigned to any player", team.name);
56+
println!("Note: Team assignment may need to be done via API or database update");
57+
} else if team.player_id == Some(test_player.id) {
58+
println!("Team #1 ({}) is already assigned to test user", team.name);
59+
} else {
60+
println!("Team #1 ({}) is assigned to a different player", team.name);
61+
}
62+
} else {
63+
println!("Team #1 not found - seed_db.rs should be run first");
64+
}
65+
66+
println!("\nTest database setup complete!");
67+
println!("Test user credentials:");
68+
println!(" Username: {}", TEST_PLAYER);
69+
println!(" Password: {}", TEST_PASSWORD);
70+
71+
Ok(())
72+
}
73+

tiny-racing-vue/.gitignore

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
pnpm-debug.log*
8-
lerna-debug.log*
1+
# Dependencies
2+
node_modules/
93

10-
node_modules
11-
.DS_Store
12-
dist
13-
dist-ssr
14-
coverage
15-
*.local
16-
17-
/cypress/videos/
18-
/cypress/screenshots/
19-
20-
# Editor directories and files
21-
.vscode/*
22-
!.vscode/extensions.json
23-
.idea
24-
*.suo
25-
*.ntvs*
26-
*.njsproj
27-
*.sln
28-
*.sw?
29-
30-
*.tsbuildinfo
31-
32-
test-results/
33-
playwright-report/
4+
# Playwright
5+
/test-results/
6+
/playwright-report/
7+
/playwright/.cache/

tiny-racing-vue/e2e/ARCH_SETUP.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Arch Linux Setup for Playwright
2+
3+
On Arch Linux, it's recommended to use system browsers instead of Playwright's bundled browsers for better compatibility and performance.
4+
5+
## Setup Steps
6+
7+
### 1. Install System Browsers
8+
9+
```bash
10+
sudo pacman -S chromium firefox
11+
```
12+
13+
### 2. Skip Browser Download (Optional but Recommended)
14+
15+
Add this to your `~/.bashrc` or `~/.zshrc`:
16+
17+
```bash
18+
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
19+
```
20+
21+
Then reload your shell:
22+
```bash
23+
source ~/.bashrc # or source ~/.zshrc
24+
```
25+
26+
### 3. Use System Browsers in Tests
27+
28+
Set the environment variable before running tests:
29+
30+
```bash
31+
PLAYWRIGHT_USE_SYSTEM_BROWSERS=1 npm run test:e2e
32+
```
33+
34+
Or add it to your shell config:
35+
36+
```bash
37+
export PLAYWRIGHT_USE_SYSTEM_BROWSERS=1
38+
```
39+
40+
## Benefits
41+
42+
- ✅ Native Arch builds
43+
- ✅ Zero compatibility hacks
44+
- ✅ Much faster security updates
45+
- ✅ No broken ICU/libffi dependencies
46+
- ✅ Smaller disk footprint
47+
48+
## Notes
49+
50+
- WebKit is not available as a system package on Arch, so webkit tests will be skipped when using system browsers
51+
- If you don't set `PLAYWRIGHT_USE_SYSTEM_BROWSERS=1`, Playwright will use its bundled browsers (which may have dependency issues on Arch)
52+

0 commit comments

Comments
 (0)