# Fansifter Authentication Tests

This Playwright test suite automates testing for the fansifter.sonymusic.com website with pre-authenticated sessions.

## Setup

1. Install dependencies:
   ```bash
   npm install
   ```

2. Install Playwright browsers:
   ```bash
   npx playwright install
   ```

## Authentication Setup (One-time)

Before running tests, you need to authenticate once:

```bash
npm run auth:setup
```

This will:
1. Open a browser window
2. Navigate to fansifter.sonymusic.com
3. Guide you through the login process
4. Save your authentication state for future tests

**Follow the prompts and complete the authentication manually when prompted.**

## Running Tests

### With Pre-Authentication
```bash
npm run test:auth         # Run authenticated tests (headless)
npm run test:auth:headed  # Run authenticated tests (with browser visible)
```

### All Tests
```bash
npm test                  # All tests (headless)
npm run test:headed       # All tests (with browser visible)
npm run test:ui           # Interactive UI mode
```

## Authentication Management

```bash
npm run auth:clean        # Remove saved authentication (forces re-auth)
npm run auth:setup        # Set up authentication again
```

## Test Files

- `fansiter-login.spec.js` - Manual login test (requires OAuth each time)
- `fansiter-authenticated.spec.js` - Uses pre-saved authentication state
- `auth.setup.js` - Authentication setup helper

## Benefits of Pre-Authentication

- **Faster test execution** - No OAuth delay
- **More reliable** - No manual intervention required
- **CI/CD friendly** - Can run unattended once auth is set up
- **Better debugging** - Focus on application logic, not auth flow

## Notes

- Authentication state is saved locally in `auth-state.json`
- Re-run `npm run auth:setup` if authentication expires
- The authenticated test skips the login flow entirely