Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit f28e35c

Browse files
fix: Revert changes that need to be rolled out later in phase
1 parent 6a8ac58 commit f28e35c

File tree

4 files changed

+174
-6
lines changed

4 files changed

+174
-6
lines changed

codecov_auth/commands/owner/interactors/save_terms_agreement.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Any
2+
from typing import Any, Optional
33

44
from django.utils import timezone
55

@@ -11,15 +11,26 @@
1111

1212
@dataclass
1313
class TermsAgreementInput:
14-
business_email: str
15-
name: str
14+
business_email: Optional[str] = None
15+
name: Optional[str] = None
1616
terms_agreement: bool = False
1717
marketing_consent: bool = False
18+
customer_intent: Optional[str] = None
1819

1920

2021
class SaveTermsAgreementInteractor(BaseInteractor):
2122
requires_service = False
2223

24+
def validate_deprecated(self, input: TermsAgreementInput) -> None:
25+
valid_customer_intents = ["Business", "BUSINESS", "Personal", "PERSONAL"]
26+
if (
27+
input.customer_intent
28+
and input.customer_intent not in valid_customer_intents
29+
):
30+
raise ValidationError("Invalid customer intent provided")
31+
if not self.current_user.is_authenticated:
32+
raise Unauthenticated()
33+
2334
def validate(self, input: TermsAgreementInput) -> None:
2435
if not input.business_email:
2536
raise ValidationError("Email is required")
@@ -54,7 +65,11 @@ def execute(self, input: Any) -> None:
5465
business_email=input.get("business_email", ""),
5566
terms_agreement=input.get("terms_agreement", False),
5667
marketing_consent=input.get("marketing_consent", False),
68+
customer_intent=input.get("customer_intent"),
5769
name=input.get("name", ""),
5870
)
59-
self.validate(typed_input)
71+
if input.get("customer_intent"):
72+
self.validate_deprecated(typed_input)
73+
else:
74+
self.validate(typed_input)
6075
return self.update_terms_agreement(typed_input)

codecov_auth/commands/owner/interactors/tests/test_save_terms_agreement.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,119 @@ def execute(self, current_user, input=None):
3232
input=real_input,
3333
)
3434

35+
#### Start of older tests
36+
37+
@freeze_time("2022-01-01T00:00:00")
38+
def test_deprecated_update_user_when_agreement_is_false(self):
39+
self.execute(
40+
current_user=self.current_user,
41+
input={"terms_agreement": False, "customer_intent": "Business"},
42+
)
43+
before_refresh_business_email = self.current_user.email
44+
45+
assert self.current_user.terms_agreement == False
46+
assert self.current_user.terms_agreement_at == self.updated_at
47+
48+
self.current_user.refresh_from_db()
49+
assert self.current_user.email == before_refresh_business_email
50+
51+
@freeze_time("2022-01-01T00:00:00")
52+
def test_deprecated_update_user_when_agreement_is_true(self):
53+
self.execute(
54+
current_user=self.current_user,
55+
input={"terms_agreement": True, "customer_intent": "Business"},
56+
)
57+
before_refresh_business_email = self.current_user.email
58+
59+
assert self.current_user.terms_agreement == True
60+
assert self.current_user.terms_agreement_at == self.updated_at
61+
62+
self.current_user.refresh_from_db()
63+
assert self.current_user.email == before_refresh_business_email
64+
65+
@freeze_time("2022-01-01T00:00:00")
66+
def test_deprecated_update_owner_and_user_when_email_is_not_empty(self):
67+
self.execute(
68+
current_user=self.current_user,
69+
input={
70+
"business_email": "[email protected]",
71+
"terms_agreement": True,
72+
"customer_intent": "Business",
73+
},
74+
)
75+
76+
assert self.current_user.terms_agreement == True
77+
assert self.current_user.terms_agreement_at == self.updated_at
78+
79+
self.current_user.refresh_from_db()
80+
assert self.current_user.email == "[email protected]"
81+
82+
def test_deprecated_validation_error_when_customer_intent_invalid(self):
83+
with pytest.raises(ValidationError):
84+
self.execute(
85+
current_user=self.current_user,
86+
input={"terms_agreement": None, "customer_intent": "invalid"},
87+
)
88+
89+
def test_deprecated_user_is_not_authenticated(self):
90+
with pytest.raises(Unauthenticated):
91+
self.execute(
92+
current_user=AnonymousUser(),
93+
input={
94+
"business_email": "[email protected]",
95+
"terms_agreement": True,
96+
"customer_intent": "Business",
97+
},
98+
)
99+
100+
def test_deprecated_email_opt_in_saved_in_db(self):
101+
self.execute(
102+
current_user=self.current_user,
103+
input={
104+
"terms_agreement": True,
105+
"marketing_consent": True,
106+
"customer_intent": "Business",
107+
},
108+
)
109+
self.current_user.refresh_from_db()
110+
assert self.current_user.email_opt_in == True
111+
112+
@patch(
113+
"codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
114+
)
115+
def test_deprecated_marketo_called_only_with_consent(
116+
self, mock_send_data_to_marketo
117+
):
118+
self.execute(
119+
current_user=self.current_user,
120+
input={
121+
"terms_agreement": True,
122+
"marketing_consent": True,
123+
"customer_intent": "Business",
124+
},
125+
)
126+
127+
mock_send_data_to_marketo.assert_called_once()
128+
129+
@patch(
130+
"codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
131+
)
132+
def test_deprecated_marketo_not_called_without_consent(
133+
self, mock_send_data_to_marketo
134+
):
135+
self.execute(
136+
current_user=self.current_user,
137+
input={
138+
"terms_agreement": True,
139+
"marketing_consent": False,
140+
"customer_intent": "Business",
141+
},
142+
)
143+
144+
mock_send_data_to_marketo.assert_not_called()
145+
146+
#### End of older tests
147+
35148
@freeze_time("2022-01-01T00:00:00")
36149
def test_update_user_when_agreement_is_false(self):
37150
self.execute(

graphql_api/tests/mutation/test_save_terms_agreement.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818

1919

2020
class SaveTermsAgreementMutationTest(GraphQLTestHelper, TransactionTestCase):
21+
def _request_deprecated(self, owner=None):
22+
return self.gql_request(
23+
query,
24+
variables={"input": {"termsAgreement": True, "customerIntent": "Business"}},
25+
owner=owner,
26+
)
27+
28+
def _request_invalid_customer_intent_deprecated(self, owner=None):
29+
return self.gql_request(
30+
query,
31+
variables={"input": {"termsAgreement": True, "customerIntent": "invalid"}},
32+
owner=owner,
33+
)
34+
2135
def _request(self, owner=None):
2236
return self.gql_request(
2337
query,
@@ -31,6 +45,31 @@ def _request(self, owner=None):
3145
owner=owner,
3246
)
3347

48+
def test_invalid_customer_intent_deprecated(self):
49+
owner = OwnerFactory()
50+
assert self._request_invalid_customer_intent_deprecated(owner=owner) == {
51+
"saveTermsAgreement": {
52+
"error": {
53+
"__typename": "ValidationError",
54+
"message": "Invalid customer intent provided",
55+
}
56+
}
57+
}
58+
59+
def test_unauthenticated_deprecated(self):
60+
assert self._request_deprecated() == {
61+
"saveTermsAgreement": {
62+
"error": {
63+
"__typename": "UnauthenticatedError",
64+
"message": "You are not authenticated",
65+
}
66+
}
67+
}
68+
69+
def test_authenticated_deprecated(self):
70+
owner = OwnerFactory()
71+
assert self._request_deprecated(owner=owner) == {"saveTermsAgreement": None}
72+
3473
def test_unauthenticated(self):
3574
assert self._request() == {
3675
"saveTermsAgreement": {

graphql_api/types/mutation/save_terms_agreement/save_terms_agreement.graphql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ type SaveTermsAgreementPayload {
55
}
66

77
input SaveTermsAgreementInput {
8-
businessEmail: String!
8+
businessEmail: String
99
termsAgreement: Boolean!
1010
marketingConsent: Boolean
11-
name: String!
11+
name: String
12+
customerIntent: String
1213
}

0 commit comments

Comments
 (0)