Skip to content

Commit

Permalink
fix: Remove tos input defaults and separate out more new vs deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Jan 16, 2025
1 parent 7bc85a9 commit d045615
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
49 changes: 33 additions & 16 deletions codecov_auth/commands/owner/interactors/save_terms_agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,28 @@ def validate_deprecated(self, input: TermsAgreementInput) -> None:
raise Unauthenticated()

def validate(self, input: TermsAgreementInput) -> None:
if not input.business_email:
raise ValidationError("Email is required")
if not input.name:
raise ValidationError("Name is required")
if not self.current_user.is_authenticated:
raise Unauthenticated()

def update_terms_agreement(self, input: TermsAgreementInput) -> None:
def update_terms_agreement_deprecated(self, input: TermsAgreementInput) -> None:
self.current_user.terms_agreement = input.terms_agreement
self.current_user.terms_agreement_at = timezone.now()
self.current_user.customer_intent = input.customer_intent
self.current_user.email_opt_in = input.marketing_consent
self.current_user.save()

if input.business_email and input.business_email != "":
self.current_user.email = input.business_email
self.current_user.save()

if input.marketing_consent:
self.send_data_to_marketo()

def update_terms_agreement(self, input: TermsAgreementInput) -> None:
self.current_user.terms_agreement = input.terms_agreement
self.current_user.terms_agreement_at = timezone.now()
self.current_user.name = input.name
self.current_user.email_opt_in = input.marketing_consent
self.current_user.save()

if input.business_email and input.business_email != "":
Expand All @@ -61,15 +71,22 @@ def send_data_to_marketo(self) -> None:

@sync_to_async
def execute(self, input: Any) -> None:
typed_input = TermsAgreementInput(
business_email=input.get("business_email", ""),
terms_agreement=input.get("terms_agreement", False),
marketing_consent=input.get("marketing_consent", False),
customer_intent=input.get("customer_intent"),
name=input.get("name", ""),
)
if input.get("customer_intent"):
self.validate_deprecated(typed_input)
else:
if input.get("name"):
typed_input = TermsAgreementInput(
business_email=input.get("business_email"),
terms_agreement=input.get("terms_agreement"),
marketing_consent=input.get("marketing_consent"),
name=input.get("name"),
)
self.validate(typed_input)
return self.update_terms_agreement(typed_input)
self.update_terms_agreement(typed_input)
# this handles the deprecated inputs
else:
typed_input = TermsAgreementInput(
business_email=input.get("business_email"),
terms_agreement=input.get("terms_agreement"),
marketing_consent=input.get("marketing_consent"),
customer_intent=input.get("customer_intent"),
)
self.validate_deprecated(typed_input)
self.update_terms_agreement_deprecated(typed_input)
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,6 @@ def test_update_owner_and_user_when_email_and_name_are_not_empty(self):
assert self.current_user.email == "[email protected]"
assert self.current_user.name == "codecov-user"

def test_validation_error_when_email_invalid(self):
with pytest.raises(ValidationError):
self.execute(
current_user=self.current_user,
input={"name": "codecov-user", "terms_agreement": True},
)

def test_validation_error_when_name_invalid(self):
with pytest.raises(ValidationError):
self.execute(
current_user=self.current_user,
input={
"business_email": "[email protected]",
"terms_agreement": True,
},
)

def test_user_is_not_authenticated(self):
with pytest.raises(Unauthenticated):
self.execute(
Expand Down

0 comments on commit d045615

Please sign in to comment.