This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Receive user name for new Terms of Service UI #1094
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a2d8e6a
feat: Receive user name instead of customer intent for new terms UI
calvin-codecov 6288d02
fix: Fix wrong variable and modify tests
calvin-codecov 3dedc56
fix: Fix save terms agreement mutation tests
calvin-codecov b707d0a
chore: typing
calvin-codecov d5fdec6
fix: Fix types
calvin-codecov 9528562
fix: Fix types
calvin-codecov f8322d4
fix: Remove print statement
calvin-codecov c913003
fix: Revert changes that need to be rolled out later in phase
calvin-codecov dbaad07
chore: Lint
calvin-codecov 7bc85a9
chore: Lint again
calvin-codecov d045615
fix: Remove tos input defaults and separate out more new vs deprecated
calvin-codecov 7f83bd5
Merge branch 'main' into cy/accept_name_tos
calvin-codecov 9df3098
Merge branch 'main' into cy/accept_name_tos
calvin-codecov 89729df
Merge branch 'main' into cy/accept_name_tos
calvin-codecov 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 |
|---|---|---|
|
|
@@ -32,8 +32,10 @@ def execute(self, current_user, input=None): | |
| input=real_input, | ||
| ) | ||
|
|
||
| #### Start of older tests | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_user_when_agreement_is_false(self): | ||
| def test_deprecated_update_user_when_agreement_is_false(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={"terms_agreement": False, "customer_intent": "Business"}, | ||
|
|
@@ -47,7 +49,7 @@ def test_update_user_when_agreement_is_false(self): | |
| assert self.current_user.email == before_refresh_business_email | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_user_when_agreement_is_true(self): | ||
| def test_deprecated_update_user_when_agreement_is_true(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={"terms_agreement": True, "customer_intent": "Business"}, | ||
|
|
@@ -61,7 +63,7 @@ def test_update_user_when_agreement_is_true(self): | |
| assert self.current_user.email == before_refresh_business_email | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_owner_and_user_when_email_is_not_empty(self): | ||
| def test_deprecated_update_owner_and_user_when_email_is_not_empty(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
|
|
@@ -77,14 +79,14 @@ def test_update_owner_and_user_when_email_is_not_empty(self): | |
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email == "[email protected]" | ||
|
|
||
| def test_validation_error_when_customer_intent_invalid(self): | ||
| def test_deprecated_validation_error_when_customer_intent_invalid(self): | ||
| with pytest.raises(ValidationError): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={"terms_agreement": None, "customer_intent": "invalid"}, | ||
| ) | ||
|
|
||
| def test_user_is_not_authenticated(self): | ||
| def test_deprecated_user_is_not_authenticated(self): | ||
| with pytest.raises(Unauthenticated): | ||
| self.execute( | ||
| current_user=AnonymousUser(), | ||
|
|
@@ -95,7 +97,7 @@ def test_user_is_not_authenticated(self): | |
| }, | ||
| ) | ||
|
|
||
| def test_email_opt_in_saved_in_db(self): | ||
| def test_deprecated_email_opt_in_saved_in_db(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
|
|
@@ -110,7 +112,9 @@ def test_email_opt_in_saved_in_db(self): | |
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo): | ||
| def test_deprecated_marketo_called_only_with_consent( | ||
| self, mock_send_data_to_marketo | ||
| ): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
|
|
@@ -125,7 +129,9 @@ def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo): | |
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo): | ||
| def test_deprecated_marketo_not_called_without_consent( | ||
| self, mock_send_data_to_marketo | ||
| ): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
|
|
@@ -136,3 +142,115 @@ def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo): | |
| ) | ||
|
|
||
| mock_send_data_to_marketo.assert_not_called() | ||
|
|
||
| #### End of older tests | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_user_when_agreement_is_false(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": False, | ||
| }, | ||
| ) | ||
| before_refresh_business_email = self.current_user.email | ||
|
|
||
| assert self.current_user.terms_agreement == False | ||
| assert self.current_user.terms_agreement_at == self.updated_at | ||
|
|
||
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email == before_refresh_business_email | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_user_when_agreement_is_true(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| }, | ||
| ) | ||
| before_refresh_business_email = self.current_user.email | ||
|
|
||
| assert self.current_user.terms_agreement == True | ||
| assert self.current_user.terms_agreement_at == self.updated_at | ||
|
|
||
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email == before_refresh_business_email | ||
|
|
||
| @freeze_time("2022-01-01T00:00:00") | ||
| def test_update_owner_and_user_when_email_and_name_are_not_empty(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| }, | ||
| ) | ||
|
|
||
| assert self.current_user.terms_agreement == True | ||
| assert self.current_user.terms_agreement_at == self.updated_at | ||
|
|
||
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email == "[email protected]" | ||
| assert self.current_user.name == "codecov-user" | ||
|
|
||
| def test_user_is_not_authenticated(self): | ||
| with pytest.raises(Unauthenticated): | ||
| self.execute( | ||
| current_user=AnonymousUser(), | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| }, | ||
| ) | ||
|
|
||
| def test_email_opt_in_saved_in_db(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| "marketing_consent": True, | ||
| }, | ||
| ) | ||
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email_opt_in == True | ||
|
|
||
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| "marketing_consent": True, | ||
| }, | ||
| ) | ||
|
|
||
| mock_send_data_to_marketo.assert_called_once() | ||
|
|
||
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "business_email": "[email protected]", | ||
| "name": "codecov-user", | ||
| "terms_agreement": True, | ||
| "marketing_consent": False, | ||
| }, | ||
| ) | ||
|
|
||
| mock_send_data_to_marketo.assert_not_called() | ||
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 |
|---|---|---|
|
|
@@ -18,22 +18,46 @@ | |
|
|
||
|
|
||
| class SaveTermsAgreementMutationTest(GraphQLTestHelper, TransactionTestCase): | ||
| def _request(self, owner=None): | ||
| def _request_deprecated(self, owner=None): | ||
| return self.gql_request( | ||
| query, | ||
| variables={"input": {"termsAgreement": True, "customerIntent": "Business"}}, | ||
| owner=owner, | ||
| ) | ||
|
|
||
| def _request_invalid_customer_intent(self, owner=None): | ||
| def _request_invalid_customer_intent_deprecated(self, owner=None): | ||
| return self.gql_request( | ||
| query, | ||
| variables={"input": {"termsAgreement": True, "customerIntent": "invalid"}}, | ||
| owner=owner, | ||
| ) | ||
|
|
||
| def test_unauthenticated(self): | ||
| assert self._request() == { | ||
| def _request(self, owner=None): | ||
| return self.gql_request( | ||
| query, | ||
| variables={ | ||
| "input": { | ||
| "termsAgreement": True, | ||
| "businessEmail": "[email protected]", | ||
| "name": "codecov-user", | ||
| } | ||
| }, | ||
| owner=owner, | ||
| ) | ||
|
|
||
| def test_invalid_customer_intent_deprecated(self): | ||
| owner = OwnerFactory() | ||
| assert self._request_invalid_customer_intent_deprecated(owner=owner) == { | ||
| "saveTermsAgreement": { | ||
| "error": { | ||
| "__typename": "ValidationError", | ||
| "message": "Invalid customer intent provided", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def test_unauthenticated_deprecated(self): | ||
| assert self._request_deprecated() == { | ||
| "saveTermsAgreement": { | ||
| "error": { | ||
| "__typename": "UnauthenticatedError", | ||
|
|
@@ -42,17 +66,20 @@ def test_unauthenticated(self): | |
| } | ||
| } | ||
|
|
||
| def test_authenticated(self): | ||
| def test_authenticated_deprecated(self): | ||
| owner = OwnerFactory() | ||
| assert self._request(owner=owner) == {"saveTermsAgreement": None} | ||
| assert self._request_deprecated(owner=owner) == {"saveTermsAgreement": None} | ||
|
|
||
| def test_invalid_customer_intent(self): | ||
| owner = OwnerFactory() | ||
| assert self._request_invalid_customer_intent(owner=owner) == { | ||
| def test_unauthenticated(self): | ||
| assert self._request() == { | ||
| "saveTermsAgreement": { | ||
| "error": { | ||
| "__typename": "ValidationError", | ||
| "message": "Invalid customer intent provided", | ||
| "__typename": "UnauthenticatedError", | ||
| "message": "You are not authenticated", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def test_authenticated(self): | ||
| owner = OwnerFactory() | ||
| assert self._request(owner=owner) == {"saveTermsAgreement": None} | ||
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.
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.