-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Fix Testimonial Auto-Share Sequence During Creation (#1179)
* ✨ fix(api): ensure testimonial save and publish sequence correctly Refactored testimonial save logic to ensure proper sequence. Fixed bug where 'published_at' and community additions occurred before save, potentially causing issues. Benefits: - Ensures required fields are set before saving - Avoids premature community addition 🚀 * added tests for auto share setting utility function * Refactor get_auto_shared_with_list function to handle missing testimonial or community
- Loading branch information
1 parent
408c74f
commit 194d0a8
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from django.test import TestCase | ||
from api.store.testimonial import get_auto_shared_with_list | ||
from api.tests.common import make_tag, makeCommunity, makeLocation, makeTestimonial | ||
from database.models import TestimonialAutoShareSettings, LocationType | ||
|
||
class TestGetAutoSharedWithList(TestCase): | ||
|
||
def setUp(self): | ||
loc1 = makeLocation(state="MA", zipcode="02112", city="Boston") | ||
loc4 = makeLocation(state="NY", zipcode="02115", city="City") | ||
|
||
self.c1 = makeCommunity(name="Community - test 1", locations=[loc1.id] ) | ||
self.c2 = makeCommunity(name="Community - test 2",locations=[loc4.id]) | ||
self.c3 = makeCommunity(name="Community - test 3",) | ||
self.c4 = makeCommunity(name="Community - test 4", ) | ||
|
||
self.testimonial = makeTestimonial(title="SHareable Testimonial") | ||
|
||
|
||
self.tag1 = make_tag(name="Solar") | ||
self.tag2 = make_tag(name="Waste") | ||
|
||
def test_get_auto_shared_with_list_no_testimonial(self): | ||
result = get_auto_shared_with_list(None) | ||
self.assertEqual(result, []) | ||
|
||
|
||
def test_get_auto_shared_with_list_no_community(self): | ||
testimonial = makeTestimonial(title="SHareable Testimonial 2223") | ||
result = get_auto_shared_with_list(testimonial) | ||
self.assertEqual(result, []) | ||
|
||
def test_get_auto_shared_with_list_no_auto_share_settings(self): | ||
self.testimonial.community = makeCommunity(name="Community - test Within") | ||
result = get_auto_shared_with_list(self.testimonial) | ||
self.assertEqual(result.first(), None) | ||
|
||
def test_get_auto_shared_with_list_geographical_range(self): | ||
self.testimonial.community = self.c1 | ||
self.testimonial.save() | ||
TestimonialAutoShareSettings.objects.create( | ||
community=self.c3, | ||
share_from_location_type=LocationType.STATE.value[0], | ||
share_from_location_value='MA' | ||
) | ||
result = get_auto_shared_with_list(self.testimonial) | ||
self.assertIn(self.c3, list(result)) | ||
|
||
def test_get_auto_shared_with_list_tags(self): | ||
self.testimonial.community = self.c1 | ||
self.testimonial.tags.add(self.tag1) | ||
self.testimonial.save() | ||
auto_share_settings = TestimonialAutoShareSettings.objects.create( | ||
community=self.c4, | ||
) | ||
auto_share_settings.excluded_tags.add(self.tag1) | ||
result = get_auto_shared_with_list(self.testimonial) | ||
self.assertIn(self.c4, list(result)) | ||
|
||
def test_get_auto_shared_with_list_communities(self): | ||
self.testimonial.community = self.c1 | ||
self.testimonial.save() | ||
auto_share_settings = TestimonialAutoShareSettings.objects.create( | ||
community=self.c2, | ||
) | ||
auto_share_settings.share_from_communities.set([self.c1]) | ||
result = get_auto_shared_with_list(self.testimonial) | ||
self.assertIn(self.c2, list(result)) |