Merge pull request #129 from christianlouis/copilot/improve-test-coverage-admin-file
Add 87 unit tests for admin endpoints (24% → 100% coverage)
This commit is contained in:
@@ -36,12 +36,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- **Admin endpoint test coverage**: Added 87 unit tests for `admin.py` covering all 17 endpoints (stats, user CRUD, plan CRUD, notification config CRUD, notification testing, processing runs/logs with GDPR masking and pagination). Coverage improved from 24% to 100%.
|
||||||
- **Domain-based logo fallback for mail accounts**: `ProviderLogoBanner` now shows provider logos even for accounts that have no `provider_name` set, by extracting the domain from the email address and matching it against a new `DOMAIN_ICON_MAP`. Covers Gmail, GMX, WEB.DE, Yahoo Mail, AOL, T-Online, Outlook/Hotmail, IONOS, Freenet, iCloud, Posteo, and Proton Mail.
|
- **Domain-based logo fallback for mail accounts**: `ProviderLogoBanner` now shows provider logos even for accounts that have no `provider_name` set, by extracting the domain from the email address and matching it against a new `DOMAIN_ICON_MAP`. Covers Gmail, GMX, WEB.DE, Yahoo Mail, AOL, T-Online, Outlook/Hotmail, IONOS, Freenet, iCloud, Posteo, and Proton Mail.
|
||||||
- **Frontend test coverage**: Added 113 new tests across 7 new test suites covering all components, utility functions, and API interceptors. Installed `@testing-library/react`, `@testing-library/jest-dom`, and `@testing-library/user-event`. New suites: `date-utils.test.ts` (30 tests), `api.test.ts` (9 tests), `AuthGuard.test.tsx` (6 tests), `QueryProvider.test.tsx` (2 tests), `DashboardLayout.test.tsx` (14 tests), `NotificationWizard.test.tsx` (32 tests), `ProviderWizard.test.tsx` (20 tests). Total frontend: 119 tests across 8 suites.
|
- **Frontend test coverage**: Added 113 new tests across 7 new test suites covering all components, utility functions, and API interceptors. Installed `@testing-library/react`, `@testing-library/jest-dom`, and `@testing-library/user-event`. New suites: `date-utils.test.ts` (30 tests), `api.test.ts` (9 tests), `AuthGuard.test.tsx` (6 tests), `QueryProvider.test.tsx` (2 tests), `DashboardLayout.test.tsx` (14 tests), `NotificationWizard.test.tsx` (32 tests), `ProviderWizard.test.tsx` (20 tests). Total frontend: 119 tests across 8 suites.
|
||||||
- **Improved `mail_processor.py` test coverage**: Added 46 unit tests for POP3 connection testing, POP3 email fetching, IMAP edge cases (stale UID store failure, delete failure, MailFetchError re-raise, star-prefix line filtering), email forwarding (STARTTLS/SSL/multipart), and routing methods. Statement coverage increased from ~42% to 98%.
|
- **Improved `mail_processor.py` test coverage**: Added 46 unit tests for POP3 connection testing, POP3 email fetching, IMAP edge cases (stale UID store failure, delete failure, MailFetchError re-raise, star-prefix line filtering), email forwarding (STARTTLS/SSL/multipart), and routing methods. Statement coverage increased from ~42% to 98%.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- **Test fixtures**: Fixed `conftest.py` admin user fixture using non-existent `is_admin`/`is_verified` fields (should be `is_superuser`), and JWT `sub` claim using email instead of user ID.
|
||||||
- Convert `frontend/jest.config.js` to `jest.config.mjs` using ES module `import`/`export` syntax to resolve ESLint `@typescript-eslint/no-require-imports` error.
|
- Convert `frontend/jest.config.js` to `jest.config.mjs` using ES module `import`/`export` syntax to resolve ESLint `@typescript-eslint/no-require-imports` error.
|
||||||
- Suppress noisy `ignored untagged response` INFO log lines from `aioimaplib` in Celery workers by setting the `aioimaplib` logger to WARNING level in `celery_app.py`.
|
- Suppress noisy `ignored untagged response` INFO log lines from `aioimaplib` in Celery workers by setting the `aioimaplib` logger to WARNING level in `celery_app.py`.
|
||||||
- Eliminate `file_cache is only supported with oauth2client<4.0.0` warnings by passing `cache_discovery=False` to `googleapiclient.discovery.build()` in `gmail_service.py`.
|
- Eliminate `file_cache is only supported with oauth2client<4.0.0` warnings by passing `cache_discovery=False` to `googleapiclient.discovery.build()` in `gmail_service.py`.
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ async def test_user(db_session: AsyncSession) -> User:
|
|||||||
email="test@example.com",
|
email="test@example.com",
|
||||||
hashed_password=get_password_hash("testpassword123"),
|
hashed_password=get_password_hash("testpassword123"),
|
||||||
is_active=True,
|
is_active=True,
|
||||||
is_verified=True,
|
|
||||||
)
|
)
|
||||||
db_session.add(user)
|
db_session.add(user)
|
||||||
await db_session.commit()
|
await db_session.commit()
|
||||||
@@ -97,8 +96,7 @@ async def test_admin_user(db_session: AsyncSession) -> User:
|
|||||||
email="admin@example.com",
|
email="admin@example.com",
|
||||||
hashed_password=get_password_hash("adminpassword123"),
|
hashed_password=get_password_hash("adminpassword123"),
|
||||||
is_active=True,
|
is_active=True,
|
||||||
is_verified=True,
|
is_superuser=True,
|
||||||
is_admin=True,
|
|
||||||
)
|
)
|
||||||
db_session.add(user)
|
db_session.add(user)
|
||||||
await db_session.commit()
|
await db_session.commit()
|
||||||
@@ -109,14 +107,14 @@ async def test_admin_user(db_session: AsyncSession) -> User:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def auth_headers(test_user: User) -> dict:
|
def auth_headers(test_user: User) -> dict:
|
||||||
"""Generate authentication headers for test user"""
|
"""Generate authentication headers for test user"""
|
||||||
access_token = create_access_token(data={"sub": test_user.email})
|
access_token = create_access_token(data={"sub": str(test_user.id)})
|
||||||
return {"Authorization": f"Bearer {access_token}"}
|
return {"Authorization": f"Bearer {access_token}"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def admin_auth_headers(test_admin_user: User) -> dict:
|
def admin_auth_headers(test_admin_user: User) -> dict:
|
||||||
"""Generate authentication headers for admin user"""
|
"""Generate authentication headers for admin user"""
|
||||||
access_token = create_access_token(data={"sub": test_admin_user.email})
|
access_token = create_access_token(data={"sub": str(test_admin_user.id)})
|
||||||
return {"Authorization": f"Bearer {access_token}"}
|
return {"Authorization": f"Bearer {access_token}"}
|
||||||
|
|
||||||
|
|
||||||
@@ -131,8 +129,7 @@ def user_factory(db_session: AsyncSession):
|
|||||||
email: str = None,
|
email: str = None,
|
||||||
password: str = "testpassword123",
|
password: str = "testpassword123",
|
||||||
is_active: bool = True,
|
is_active: bool = True,
|
||||||
is_verified: bool = True,
|
is_superuser: bool = False,
|
||||||
is_admin: bool = False,
|
|
||||||
) -> User:
|
) -> User:
|
||||||
if email is None:
|
if email is None:
|
||||||
import uuid
|
import uuid
|
||||||
@@ -143,8 +140,7 @@ def user_factory(db_session: AsyncSession):
|
|||||||
email=email,
|
email=email,
|
||||||
hashed_password=get_password_hash(password),
|
hashed_password=get_password_hash(password),
|
||||||
is_active=is_active,
|
is_active=is_active,
|
||||||
is_verified=is_verified,
|
is_superuser=is_superuser,
|
||||||
is_admin=is_admin,
|
|
||||||
)
|
)
|
||||||
db_session.add(user)
|
db_session.add(user)
|
||||||
await db_session.commit()
|
await db_session.commit()
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -117,6 +117,7 @@ Comprehensive task breakdown for repository improvements and production readines
|
|||||||
- [x] Write unit tests for schemas and validation
|
- [x] Write unit tests for schemas and validation
|
||||||
- [x] Write unit tests for application factory and core endpoints
|
- [x] Write unit tests for application factory and core endpoints
|
||||||
- [x] Reach 50%+ test coverage (currently 59%)
|
- [x] Reach 50%+ test coverage (currently 59%)
|
||||||
|
- [x] Write unit tests for admin endpoints (87 tests, 100% coverage on admin.py)
|
||||||
- [x] **Frontend test coverage**: Added 113 new tests across 7 new test suites covering all components and utility functions. Installed `@testing-library/react`, `@testing-library/jest-dom`, `@testing-library/user-event`. New suites: `date-utils` (30 tests), API interceptors (9 tests), `AuthGuard` (6 tests), `QueryProvider` (2 tests), `DashboardLayout` (14 tests), `NotificationWizard` (32 tests), `ProviderWizard` (20 tests). Total frontend: 119 tests across 8 suites.
|
- [x] **Frontend test coverage**: Added 113 new tests across 7 new test suites covering all components and utility functions. Installed `@testing-library/react`, `@testing-library/jest-dom`, `@testing-library/user-event`. New suites: `date-utils` (30 tests), API interceptors (9 tests), `AuthGuard` (6 tests), `QueryProvider` (2 tests), `DashboardLayout` (14 tests), `NotificationWizard` (32 tests), `ProviderWizard` (20 tests). Total frontend: 119 tests across 8 suites.
|
||||||
|
|
||||||
### In Progress 🔨
|
### In Progress 🔨
|
||||||
|
|||||||
Reference in New Issue
Block a user