-
Notifications
You must be signed in to change notification settings - Fork 5
SONIC-704: Add CT discount availed check for outline tab #303
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
NoyanAziz
merged 12 commits into
main
from
naziz1/SONIC-704/add-ct-discount-check-for-outline-tab
Jan 2, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8de2d2c
chore: added CT discount eligibility check for outline tab
e4f2f55
fix: quality checks
2f4e823
fix: unit tests
37ee470
Merge branch 'main' into naziz1/SONIC-704/add-ct-discount-check-for-o…
f653ed8
refactor: use settings value for discounts list
959a1cf
fix: coverage
184427c
refactor: docstrings
b56f77e
chore: first time discount check based on lms
f60b48c
Merge branch 'main' into naziz1/SONIC-704/add-ct-discount-check-for-o…
c8a1720
fix: tests
043872d
chore: removed pipeline from the flow and converted get call to post
2814558
Merge branch 'main' into naziz1/SONIC-704/add-ct-discount-check-for-o…
NoyanAziz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -883,6 +883,89 @@ def test_update_customer_with_anonymized_fields_exception(self): | |
|
||
log_mock.assert_called_once_with(expected_message) | ||
|
||
def test_is_first_time_discount_eligible_success(self): | ||
base_url = self.client_set.get_base_url_from_client() | ||
email = '[email protected]' | ||
code = 'discount-code' | ||
|
||
mock_orders = { | ||
"total": 1, | ||
"results": [ | ||
{ | ||
"discountCodes": [ | ||
{ | ||
"discountCode": { | ||
"obj": { | ||
"code": 'another-code' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
NoyanAziz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(email, code) | ||
self.assertTrue(result) | ||
|
||
def test_is_first_time_discount_not_eligible(self): | ||
base_url = self.client_set.get_base_url_from_client() | ||
email = '[email protected]' | ||
code = 'discount-code' | ||
|
||
mock_orders = { | ||
"total": 1, | ||
"results": [ | ||
{ | ||
"discountCodes": [ | ||
{ | ||
"discountCode": { | ||
"obj": { | ||
"code": code | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(email, code) | ||
self.assertFalse(result) | ||
|
||
def test_is_first_time_discount_eligible_invalid_email(self): | ||
invalid_email = "[email protected]" | ||
code = 'discount-code' | ||
base_url = self.client_set.get_base_url_from_client() | ||
|
||
mock_orders = { | ||
"total": 0 | ||
} | ||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(invalid_email, code) | ||
self.assertTrue(result) | ||
|
||
|
||
class PaginatedResultsTest(TestCase): | ||
"""Tests for the simple logic in our Paginated Results Class""" | ||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -382,3 +382,88 @@ def test_post_with_unexpected_exception_fails(self, mock_filter): | |
response = self.client.post(self.url, self.valid_payload, format='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) | ||
|
||
|
||
@ddt.ddt | ||
class FirstTimeDiscountEligibleViewTests(APITestCase): | ||
""" | ||
Tests for the FirstTimeDiscountEligibleView to check if a user is eligible for a first-time discount. | ||
""" | ||
|
||
test_user_username = 'test' | ||
test_user_email = '[email protected]' | ||
test_user_password = 'secret' | ||
test_discount = 'first_time_discount' | ||
|
||
valid_payload = { | ||
'email': test_user_email, | ||
'code': test_discount, | ||
} | ||
|
||
invalid_payload = { | ||
'email': None, | ||
'code': 'any_discount', | ||
} | ||
|
||
url = reverse('lms:first_time_discount_eligible') | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.user = User.objects.create_user( | ||
self.test_user_username, | ||
self.test_user_email, | ||
self.test_user_password, | ||
is_staff=True, | ||
) | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.client.logout() | ||
|
||
def authenticate_user(self): | ||
self.client.login(username=self.test_user_username, password=self.test_user_password) | ||
self.client.force_authenticate(user=self.user) | ||
|
||
@patch( | ||
'commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient' | ||
'.is_first_time_discount_eligible' | ||
) | ||
def test_get_with_valid_email_eligibility_true(self, mock_is_first_time_discount_eligible): | ||
""" | ||
Test case where the user is eligible for a first-time discount. | ||
""" | ||
self.authenticate_user() | ||
mock_is_first_time_discount_eligible.return_value = True | ||
|
||
response = self.client.post(self.url, self.valid_payload, format='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {"is_eligible": True}) | ||
mock_is_first_time_discount_eligible.assert_called_once_with(self.test_user_email, self.test_discount) | ||
|
||
@patch( | ||
'commerce_coordinator.apps.commercetools.clients.CommercetoolsAPIClient' | ||
'.is_first_time_discount_eligible' | ||
) | ||
def test_get_with_valid_email_eligibility_false(self, mock_is_first_time_discount_eligible): | ||
""" | ||
Test case where the user is not eligible for a first-time discount. | ||
""" | ||
self.authenticate_user() | ||
mock_is_first_time_discount_eligible.return_value = False | ||
|
||
response = self.client.post(self.url, self.valid_payload, format='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {"is_eligible": False}) | ||
mock_is_first_time_discount_eligible.assert_called_once_with(self.test_user_email, self.test_discount) | ||
|
||
def test_get_with_missing_email_fails(self): | ||
""" | ||
Test case where the email is not provided in the request query params. | ||
""" | ||
self.authenticate_user() | ||
|
||
response = self.client.post(self.url, self.invalid_payload, format='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.