# Backend API Tests

## Setup

1. Install dependencies:
```bash
pip install pytest pytest-asyncio httpx
```

2. Ensure backend server is running (or use test database):
```bash
# In backend directory
python server.py
```

## Running Tests

### Run all tests:
```bash
pytest
```

### Run specific test file:
```bash
pytest tests/test_auth.py
pytest tests/test_memos.py
pytest tests/test_comments.py
```

### Run with verbose output:
```bash
pytest -v
```

### Run specific test:
```bash
pytest tests/test_auth.py::TestSignUp::test_signup_with_valid_data
```

### Run with coverage:
```bash
pytest --cov=memos_core --cov=api tests/
```

## Test Structure

- `conftest.py` - Pytest fixtures (test client, auth tokens, test data)
- `test_auth.py` - Authentication API tests
- `test_memos.py` - Memo CRUD API tests
- `test_comments.py` - Comment creation and listing tests

## Test Data

Tests use test user credentials:
- Email: `test@example.com`
- Password: `testpassword123`

Make sure this user exists or tests will create it during signup.

## Notes

- Tests use FastAPI TestClient for synchronous testing
- For async endpoints, use AsyncClient fixture
- Tests clean up after themselves (or use test database)
- Authentication tokens are cached in fixtures for performance

