You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #60 from RandomProgramm3r/develop
refactor(likes): make like/unlike operations atomic and enhance like action tests
Wrap the like and unlike logic in `django.db.transaction.atomic()` to ensure that the creation/deletion of `Like` records and the corresponding update of the promo’s `like_count` occur as a single, indivisible operation. This prevents race conditions and data inconsistencies. After updating `like_count` using `F()`, call `promo.refresh_from_db()` to reflect the latest database state in the model instance.
Refactor the `TestUserPromoLikeActions` test suite for clarity and maintainability:
- Introduce helper methods (`_create_user_and_get_token`, `_create_promo`, `_auth`, `_get_user_promo`, `_get_business_promo`, `_like`, `_unlike`) to eliminate duplication.
- Consolidate granular tests into comprehensive cases (`test_initial_promo_state`, `test_like_action`, `test_like_idempotency`, etc.).
- Remove reliance on ordered execution by cleaning up test data in `tearDown()`, ensuring test isolation and robustness.
0 commit comments