diff --git a/pythonpro/domain/checkout_domain.py b/pythonpro/domain/checkout_domain.py index 232d96cd..94241495 100644 --- a/pythonpro/domain/checkout_domain.py +++ b/pythonpro/domain/checkout_domain.py @@ -39,7 +39,8 @@ def user_factory(pagarme_transaction): customer = pagarme_transaction['customer'] customer_email = customer['email'].lower() customer_first_name = customer['name'].split()[0] - return user_domain.force_register_lead(customer_first_name, customer_email) + customer_phone = customer['phone_numbers'][0] + return user_domain.force_register_lead(customer_first_name, customer_email, customer_phone) django_pagarme_facade.set_user_factory(user_factory) diff --git a/pythonpro/domain/tests/test_checkout/test_boleto_generation.py b/pythonpro/domain/tests/test_checkout/test_boleto_generation.py index 672dd321..6b61b290 100644 --- a/pythonpro/domain/tests/test_checkout/test_boleto_generation.py +++ b/pythonpro/domain/tests/test_checkout/test_boleto_generation.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest import responses from django.urls import reverse @@ -101,6 +103,15 @@ def test_created_user_tagged_with_boleto(resp, django_user_model, tag_as_mock, a tag_as_mock.assert_called_once_with(user.email, user.id, f'{active_product_item.slug}-boleto') +def test_phone_in_the_parameters(resp, create_or_update_lead_mock): + create_or_update_lead_mock.assert_called_once_with( + 'Foo', + 'foo@email.com', + id=mock.ANY, + phone='+5512999999999' + ) + + # Tests user logged @pytest.fixture diff --git a/pythonpro/domain/tests/test_checkout/test_credit_card_payment.py b/pythonpro/domain/tests/test_checkout/test_credit_card_payment.py index d5022574..e87de1cb 100644 --- a/pythonpro/domain/tests/test_checkout/test_credit_card_payment.py +++ b/pythonpro/domain/tests/test_checkout/test_credit_card_payment.py @@ -1,3 +1,5 @@ +from unittest import mock + import pytest import responses from django.urls import reverse @@ -174,6 +176,15 @@ def test_payment_linked_with_created_user(resp, django_user_model): assert user == payment.user +def test_phone_in_the_parameters(resp, create_or_update_lead_mock): + create_or_update_lead_mock.assert_called_once_with( + 'Agora', + 'captura@gmail.com', + id=mock.ANY, + phone='+5512997411854' + ) + + # Tests user logged @pytest.fixture diff --git a/pythonpro/domain/user_domain.py b/pythonpro/domain/user_domain.py index b5a0b8d8..6d3f62f4 100644 --- a/pythonpro/domain/user_domain.py +++ b/pythonpro/domain/user_domain.py @@ -48,18 +48,19 @@ def register_lead(first_name: str, email: str, source: str = 'unknown', tags: li return lead -def force_register_lead(first_name: str, email: str, source: str = 'unknown') -> _User: +def force_register_lead(first_name: str, email: str, phone: str, source: str = 'unknown') -> _User: """ Create a new user on the system generation a random password. An Welcome email is sent to the user informing his password with the link to change it. User is also registered on Email Marketing. But she will be registered even if api call fails :param first_name: User's first name :param email: User's email + :param phone: User's phone :param source: source of User traffic :return: User """ user = _core_facade.register_lead(first_name, email, source) - _email_marketing_facade.create_or_update_lead.delay(first_name, email, id=user.id) + _email_marketing_facade.create_or_update_lead.delay(first_name, email, id=user.id, phone=phone) return user