Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pythonpro/domain/checkout_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pythonpro/domain/tests/test_checkout/test_boleto_generation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock

import pytest
import responses
from django.urls import reverse
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pythonpro/domain/tests/test_checkout/test_credit_card_payment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock

import pytest
import responses
from django.urls import reverse
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pythonpro/domain/user_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down