Skip to content

chore: refactor promo activation, update lint rules, and expand test coverage #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 26, 2025

Conversation

RandomProgramm3r
Copy link
Owner

chore: refactor promo activation, update lint rules, and expand test coverage

This commit consolidates four major improvements:

  1. Refactor PromoActivationService

    • Simplify promo activation logic by removing redundant user_age is None checks.
    • Streamline promo code acquisition and eliminate unreachable PromoActivationError.
  2. Update Ruff linting configuration

    • Extend ruff.toml ruleset by adding FIX and INT to the select list for broader code-quality checks.
  3. Enhance test coverage for the user application

    • Authentication: Add tests for CustomJWTAuthentication, covering token handling, version mismatches, and missing user IDs.
    • Models: Verify __str__ methods on User, UserManager, PromoLike, PromoComment, and PromoActivationHistory.
    • Services: Cover edge cases in PromoActivationService, including race conditions and missing targeting logic.
    • Anti-Fraud: Test AntiFraudService behavior when cache timeouts are absent.
    • Profile Operations: Validate partial PATCH updates of email and other fields, including duplicate-email checks.
  4. Expand test suite for the business application

    • Authentication: Add negative tests for company registration and login with invalid or missing emails.
    • Models: Confirm __str__ outputs for Company, Promo, and PromoCode.
    • Promo Creation: Enforce that promo_common is required for COMMON promos and promo_unique for UNIQUE promos.

 This commit refactors the `PromoActivationService` to simplify its logic and improve readability.

Key changes include:
- Removed redundant `user_age is None` checks in the age targeting validation, assuming `user_age` is always present.
- Streamlined the promo code acquisition process by removing unnecessary conditional branches and `PromoUnavailableError` exceptions.
- Eliminated an unreachable `PromoActivationError`, making the code path for activating a promotion more direct.
This commit updates the `ruff.toml` configuration to expand the set of linting rules. The new rules `FIX` and `INT` have been added to the `select` list to improve code quality and catch a broader range of potential issues.
This commit introduces a comprehensive set of tests for the `user` application, significantly improving its test coverage and  ensuring the reliability of its components.

 Key additions include:
- **Authentication:** Added tests for `CustomJWTAuthentication` to validate token handling, user type verification, and error  scenarios like mismatched token versions or missing user IDs.
 - **Models:** Created new tests for `UserManager` and `User` model behaviors, including `__str__` representations and superuser  creation. Added tests for related models like `PromoLike`, `PromoComment`, and `PromoActivationHistory`.
- **Services:** Implemented tests for `PromoActivationService` to cover edge cases in targeting logic and race conditions where a promo might be deleted during activation.
- **Anti-Fraud:** Added a test to ensure `AntiFraudService` correctly handles missing cache timeout values.
 - **Profile Operations:** Expanded tests for the user profile endpoint to cover partial updates (`PATCH`) of email and the `other` data field, including validation against existing emails.
This commit expands the test suite for the `business` application, improving validation and model testing.

Key additions include:
- **Authentication:** Added tests to `InvalidCompanyRegistrationTestCase` and `InvalidCompanyAuthenticationTestCase` to handle cases like missing email on  creation and sign-in with an invalid email.
- **Models:** Created `promo_code/business/tests/promocodes/test_models.py`  to verify the `__str__` representations for the `Company`, `Promo`, and
     `PromoCode` models.
- **Promo Creation:** Added validation tests in `TestPromoCreate` to ensure that `promo_common` is provided for 'COMMON' promos and `promo_unique` is
     provided for 'UNIQUE' promos.
@RandomProgramm3r RandomProgramm3r merged commit f196005 into main Jul 26, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant