docs
This commit is contained in:
@@ -101,6 +101,121 @@ npm run dev # Development server
|
||||
|
||||
SabreDAV is bundled with PHP‑FPM and Composer. The Docker image installs dependencies automatically during the container start‑up.
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
### Test Infrastructure
|
||||
|
||||
Crussell has a comprehensive Go testing infrastructure located in `backend/testutils/`:
|
||||
|
||||
| Component | File | Description |
|
||||
|-----------|------|-------------|
|
||||
| **Database** | `testutils/testdb/testdb.go` | PostgreSQL test pool, migrations, table truncation |
|
||||
| **HTTP Helpers** | `testutils/helpers.go` | Request builders, auth helpers, assertions |
|
||||
| **JWT** | `testutils/jwt/jwt.go` | Test token generation for users/admins |
|
||||
| **HTTP Client** | `testutils/httptest/client.go` | REST client wrapper with auth support |
|
||||
| **Fixtures** | `testutils/fixtures/fixtures.go` | Factory functions for test data |
|
||||
| **Validators** | `internal/validators/validators.go` | ID validation utilities |
|
||||
|
||||
### Test Files
|
||||
|
||||
The project includes 16 test files covering all major handlers:
|
||||
|
||||
```
|
||||
backend/
|
||||
├── bookings.test # Main booking integration tests
|
||||
├── portfolio.test # Portfolio system tests
|
||||
├── handlers/
|
||||
│ ├── admin/
|
||||
│ │ ├── bookings_test.go # Admin booking management
|
||||
│ │ ├── today_test.go # Today's view
|
||||
│ │ ├── users_test.go # User management
|
||||
│ │ └── services_test.go # Service CRUD
|
||||
│ ├── auth/
|
||||
│ │ └── auth_test.go # Authentication
|
||||
│ ├── bookings/
|
||||
│ │ └── bookings_test.go # User booking flow
|
||||
│ ├── portfolio/
|
||||
│ │ └── images_test.go # Image upload/management
|
||||
│ ├── scheduling/
|
||||
│ │ └── scheduling_test.go # Availability logic
|
||||
│ ├── services/
|
||||
│ │ └── services_test.go # Service eligibility
|
||||
│ ├── user/
|
||||
│ │ └── profile_test.go # User profile
|
||||
│ └── handlers_test.go # Common handler tests
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
|
||||
# Run all tests
|
||||
go test ./...
|
||||
|
||||
# Run with verbose output
|
||||
go test -v ./...
|
||||
|
||||
# Run specific test file
|
||||
go test -v ./handlers/bookings
|
||||
|
||||
# Run tests matching pattern
|
||||
go test -v -run "TestBooking" ./...
|
||||
```
|
||||
|
||||
### Test Database Setup
|
||||
|
||||
Tests use a dedicated PostgreSQL database. Set the connection string via:
|
||||
|
||||
```bash
|
||||
export TEST_DB_DSN="postgres://user:pass@localhost:5432/crussell_test?sslmode=disable"
|
||||
go test ./...
|
||||
```
|
||||
|
||||
Default DSN: `postgres://myuser:mypassword@localhost:5432/crussell_test?sslmode=disable`
|
||||
|
||||
### Test Utilities Usage
|
||||
|
||||
```go
|
||||
import (
|
||||
"crussell/testutils"
|
||||
"crussell/testutils/testdb"
|
||||
"crussell/testutils/fixtures"
|
||||
"crussell/testutils/jwt"
|
||||
)
|
||||
|
||||
func TestMyHandler(t *testing.T) {
|
||||
// Setup test database
|
||||
cleanup := testutils.SetupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
// Create test data
|
||||
adminID, _ := fixtures.CreateTestAdminUser(db.DB)
|
||||
userID, _ := fixtures.CreateTestUser(db.DB)
|
||||
serviceID, _ := fixtures.CreateTestService(db.DB)
|
||||
|
||||
// Generate tokens
|
||||
adminToken := jwt.GenerateAdminToken()
|
||||
userToken := jwt.GenerateUserToken(userID)
|
||||
|
||||
// Make authenticated requests
|
||||
w := testutils.MakeAdminRequest(router, "GET", "/api/admin/bookings", nil, adminID)
|
||||
w := testutils.MakeUserRequest(router, "GET", "/api/bookings", nil, userID)
|
||||
|
||||
// Assert results
|
||||
testutils.AssertStatusCode(t, w, http.StatusOK)
|
||||
testutils.AssertJSONResponse(t, w, &response)
|
||||
}
|
||||
```
|
||||
|
||||
### Test Conventions
|
||||
|
||||
- All test files use `//go:build test` build tag
|
||||
- Database is migrated fresh per test run via `testdb.Migrate()`
|
||||
- Tables are truncated between tests via `testdb.TruncateTables()`
|
||||
- Test tokens use a fixed secret: `test-secret-key-for-testing-only`
|
||||
- Fixtures auto-generate unique emails to avoid conflicts
|
||||
|
||||
## 📂 Environment Variables
|
||||
|
||||
| Variable | Purpose | Example |
|
||||
@@ -176,8 +291,11 @@ docker compose exec backend sh
|
||||
| Image Metadata Stripping | ✅ | ❌ | EXIF/GPS stripped on upload via `imaging` library |
|
||||
| Profile Pictures | ✅ | ✅ | Upload to separate bucket, cropper, circular display, CalDAV sync |
|
||||
| Auto-Booking Status | ✅ | ✅ | Auto-transition: confirmed → in_progress → completed based on time |
|
||||
| Simplified Deposits | ✅ | ❌ | `deposits_required` INT on users table (3 default), reduces on payment |
|
||||
| Simplified Deposits | ✅ | ⚠️ | `deposits_required` INT on users table (3 default), 48h notice, reduces on payment |
|
||||
| Contact Page | ✅ | ✅ | Dynamic data from first admin user via `/api/contact` endpoint |
|
||||
| Email Verification | ✅ | ❌ | Verification codes, generate/check endpoints |
|
||||
| Calendar Export | ✅ | ⚠️ | ICS download endpoint, Add to Calendar button (backend complete) |
|
||||
| Loyalty Stamps | ✅ | ✅ | Backend complete, displayed in account page |
|
||||
|
||||
### ⚠️ Partially Complete
|
||||
|
||||
@@ -352,17 +470,18 @@ grep -rn "console\.log" frontend/src/ --include="*.svelte" --include="*.ts"
|
||||
|------|--------|
|
||||
| `account_role` | `user`, `admin` |
|
||||
| `account_type` | `standard`, `vip`, `guest` |
|
||||
| `booking_status` | `pending`, `confirmed`, `in_progress`, `completed`, `cancelled`, `no_show` |
|
||||
| `booking_status` | `pending`, `confirmed`, `in_progress`, `completed`, `client_cancelled`, `we_cancelled`, `re-schedule`, `no_show`, `no_deposit` |
|
||||
| `payment_type` | `deposit`, `full`, `refund` |
|
||||
| `payment_method` | `cash`, `card`, `bank_transfer`, `square` |
|
||||
| `payment_status` | `pending`, `completed`, `failed`, `refunded` |
|
||||
| `admin_notification_reason` | `pending_booking`, `cancelled_booking`, `rescheduled_booking`, `1_week_no_pay`, `1_month_no_pay`, `affiliate_claim` |
|
||||
| `admin_notification_reason` | `pending_booking`, `cancelled_booking`, `rescheduled_booking`, `1_week_no_pay`, `1_month_no_pay`, `affiliate_claim`, `late_cancellation`, `no_deposit`, `deposit_paid` |
|
||||
|
||||
### Key Tables
|
||||
|
||||
| Table | Purpose |
|
||||
|-------|---------|
|
||||
|-------|--------|
|
||||
| `users` | Customer and admin accounts |
|
||||
| `verification_codes` | Email verification and password reset codes |
|
||||
| `services` | Salon service catalog |
|
||||
| `bookings` | Appointment records |
|
||||
| `booking_services` | Services per booking (many-to-many) |
|
||||
|
||||
Reference in New Issue
Block a user