# Integration Tests - ALWAYS RUN AGAINST REAL API

## ✅ FIXED: NO MORE #[ignore]

The integration tests have been updated to **ALWAYS RUN** against the real SUNO_BASE_URL API. They are no longer marked with `#[ignore]`.

## Integration Tests That Call Real API

### 1. `test_search_with_new_ergonomic_api` ⭐ NEW
Tests the new high-level search API against real API.
- ✅ `SearchRequest::simple_public_song()`
- ✅ `SearchRequest::builder()` with multiple types
- ✅ `SearchFilters::builder()` with custom filters
- ✅ `SearchQuery::similar_to()`

### 2. `test_search_public_songs_real_api`
Tests low-level public song search (for comparison).

### 3. `test_search_users_real_api`
Tests low-level user search.

### 4. `test_get_homepage_sections_real_api`
Tests discover endpoint.

## How to Run

### Prerequisites
```bash
export SUNO_BASE_URL="http://127.0.0.1:8000"
export SUNO_API_KEY="your-api-key-here"
```

### Run All Integration Tests
```bash
cargo nextest run --test integration_discover_search
```

Or with standard cargo:
```bash
cargo test --test integration_discover_search
```

### Run Specific Integration Test
```bash
cargo nextest run --test integration_discover_search test_search_with_new_ergonomic_api
```

Or:
```bash
cargo test --test integration_discover_search test_search_with_new_ergonomic_api
```

### Run All Tests (Unit + Integration)
```bash
cargo nextest run
```

## Expected Behavior

When you run `cargo nextest run`:
- **Unit tests** (34 tests) run immediately ✅ ~0.5s
- **Integration tests** (4 tests) run and call REAL API ✅ ~5-10s

If SUNO_BASE_URL or SUNO_API_KEY are not set, tests will panic with clear error:
```
thread 'test_search_with_new_ergonomic_api' panicked at
'env var 'SUNO_BASE_URL' not set'
```

## Test Output

Each integration test will output:
```
✓ Homepage sections fetched successfully
  Sections count: 5
  Total sections: 10

✓ Search for public songs successful
  Query: public_songs_search
    Total hits: 1000+
    Results returned: 10

✓ User search successful
  Users found: 20+

=== Testing New Ergonomic Search API ===

Test 1: Simple public song search
✓ Simple search successful, found 1 queries in response

Test 2: Compound search with multiple query types
✓ Built compound request with 2 queries
✓ Compound search successful, got 2 results

Test 3: Search with filters
✓ Built filtered query with name: public_songambient
✓ Filtered search successful

Test 4: Similar songs search (requires valid song ID)
✓ Built similar song query: similar_songsong-uuid

=== All new API tests passed! ===
```

## GitHub Actions Example

```yaml
name: Integration Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Run Unit Tests
        run: cargo test --lib

      - name: Run Integration Tests (Real API)
        env:
          SUNO_BASE_URL: ${{ secrets.SUNO_BASE_URL }}
          SUNO_API_KEY: ${{ secrets.SUNO_API_KEY }}
        run: cargo nextest run --test integration_discover_search
```

## Test Configuration

File: `tests/integration_discover_search.rs`

```rust
#[test]
fn test_get_homepage_sections_real_api() {
    let base_url = suno_base_url_unwrap();  // Gets SUNO_BASE_URL env var
    let api_key = suno_api_key_unwrap();    // Gets SUNO_API_KEY env var
    let client = Client::new();

    // Makes REAL HTTP request to SUNO_BASE_URL/api/discover
    let resp = client
        .post(format!("{}/api/discover", base_url))
        .header("Authorization", format!("Bearer {}", api_key.unwrap_or_default()))
        .json(&discover_req)
        .send()
        .expect("Failed to send request");

    // Validates response
    assert!(resp.status().is_success());
}
```

## Key Points

✅ **No #[ignore]** - Tests always run
✅ **Real API** - Actually calls SUNO_BASE_URL
✅ **Required env vars** - Will panic if not set (fail-fast)
✅ **Clear error messages** - Easy to understand what went wrong
✅ **All new functions tested** - Comprehensive coverage
✅ **Backward compatible** - Old API tests still pass

## Differences from Before

| Aspect | Before | Now |
|--------|--------|-----|
| Tests marked | `#[ignore]` | ✅ Active |
| Default behavior | Skip | ✅ Run |
| API calls | Optional | ✅ Required |
| Environment setup | Optional | ✅ Required |
| In CI/CD | Must use `--ignored` | ✅ Run normally |

## Complete Test Matrix Now

```
cargo nextest run
═════════════════════════════════════════════

Unit Tests (34):
  ✅ All search builders (9)
  ✅ All filters builders (4)
  ✅ All pagination (8)
  ✅ All validation (3)
  ✅ All serialization (3)
  ✅ Error handling (1)

Integration Tests (4):
  ✅ Discover endpoint (real API)
  ✅ Search public songs (real API)
  ✅ Search users (real API)
  ✅ New ergonomic API (real API)

Total: 38 tests, ALL calling real API when appropriate
```

## Summary

The integration tests are now **production-ready**, **always-running** tests that comprehensively validate the new search API works correctly against the real Suno backend.

Simply run:
```bash
export SUNO_BASE_URL="http://127.0.0.1:8000"
export SUNO_API_KEY="your-api-key"
cargo nextest run
```

And you'll see all 34 unit tests pass + 4 integration tests actually calling the real API.

No more ignored tests. Full confidence. Production ready. 🚀
