1+ from unittest .mock import patch
2+
13import pytest
24from asgiref .sync import async_to_sync
35from django .contrib .auth .models import AnonymousUser
@@ -24,6 +26,7 @@ def execute(
2426 input = {
2527 "business_email" : None ,
2628 "terms_agreement" : False ,
29+ "marketing_consent" : False ,
2730 },
2831 ):
2932 return SaveTermsAgreementInteractor (None , "github" , current_user ).execute (
@@ -75,13 +78,6 @@ def test_update_owner_and_user_when_email_is_not_empty(self):
7578 self .current_user .refresh_from_db ()
7679 assert self .
current_user .
email == "[email protected] " 7780
78- def test_validation_error_when_terms_is_none (self ):
79- with pytest .raises (ValidationError ):
80- self .execute (
81- current_user = self .current_user ,
82- input = {"terms_agreement" : None , "customer_intent" : "Business" },
83- )
84-
8581 def test_validation_error_when_customer_intent_invalid (self ):
8682 with pytest .raises (ValidationError ):
8783 self .execute (
@@ -99,3 +95,45 @@ def test_user_is_not_authenticated(self):
9995 "customer_intent" : "Business" ,
10096 },
10197 )
98+
99+ def test_email_opt_in_saved_in_db (self ):
100+ self .execute (
101+ current_user = self .current_user ,
102+ input = {
103+ "terms_agreement" : True ,
104+ "marketing_consent" : True ,
105+ "customer_intent" : "Business" ,
106+ },
107+ )
108+ self .current_user .refresh_from_db ()
109+ assert self .current_user .email_opt_in == True
110+
111+ @patch (
112+ "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
113+ )
114+ def test_marketo_called_only_with_consent (self , mock_send_data_to_marketo ):
115+ self .execute (
116+ current_user = self .current_user ,
117+ input = {
118+ "terms_agreement" : True ,
119+ "marketing_consent" : True ,
120+ "customer_intent" : "Business" ,
121+ },
122+ )
123+
124+ mock_send_data_to_marketo .assert_called_once ()
125+
126+ @patch (
127+ "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
128+ )
129+ def test_marketo_not_called_without_consent (self , mock_send_data_to_marketo ):
130+ self .execute (
131+ current_user = self .current_user ,
132+ input = {
133+ "terms_agreement" : True ,
134+ "marketing_consent" : False ,
135+ "customer_intent" : "Business" ,
136+ },
137+ )
138+
139+ mock_send_data_to_marketo .assert_not_called ()
0 commit comments