feat: selecao individual de leads antes de salvar, dark mode global e extracao 100% real do Google Maps
This commit is contained in:
+60
-31
@@ -1,37 +1,75 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
def test_search_maps_endpoint(client, user_headers):
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo:
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100',
|
||||
'logradouro': 'Avenida Paulista',
|
||||
'bairro': 'Bela Vista',
|
||||
'cidade': 'São Paulo',
|
||||
'uf': 'SP',
|
||||
'formatted_cep': '01310-100'
|
||||
}
|
||||
def test_scrape_preview_endpoint(client, user_headers):
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo, \
|
||||
patch('app.services.scraper_service.ScraperService.scrape_google_maps') as mock_scrape:
|
||||
|
||||
response = client.post('/api/v1/leads/search-maps', headers=user_headers, json={
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100', 'logradouro': 'Avenida Paulista', 'bairro': 'Bela Vista',
|
||||
'cidade': 'São Paulo', 'uf': 'SP', 'formatted_cep': '01310-100'
|
||||
}
|
||||
mock_scrape.return_value = [
|
||||
{
|
||||
'nome_empresa': 'Padaria Paulista Real',
|
||||
'telefone': '(11) 98888-7777',
|
||||
'endereco': 'Av. Paulista, 1000',
|
||||
'google_rating': 4.7,
|
||||
'total_avaliacoes': 120,
|
||||
'google_maps_url': 'https://maps.google.com'
|
||||
}
|
||||
]
|
||||
|
||||
response = client.post('/api/v1/leads/scrape-preview', headers=user_headers, json={
|
||||
'cep': '01310-100',
|
||||
'ramo': 'Padaria',
|
||||
'max_results': 5
|
||||
})
|
||||
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()
|
||||
assert 'summary' in data
|
||||
assert data['summary']['created_count'] >= 1
|
||||
assert data['count'] == 1
|
||||
assert data['results'][0]['nome_empresa'] == 'Padaria Paulista Real'
|
||||
|
||||
def test_import_selected_leads_endpoint(client, user_headers):
|
||||
selected_items = [
|
||||
{
|
||||
'nome_empresa': 'Padaria Paulista Real',
|
||||
'telefone': '(11) 98888-7777',
|
||||
'endereco': 'Av. Paulista, 1000',
|
||||
'google_rating': 4.7,
|
||||
'total_avaliacoes': 120,
|
||||
'google_maps_url': 'https://maps.google.com'
|
||||
}
|
||||
]
|
||||
|
||||
def test_update_lead_status_and_interaction(client, user_headers):
|
||||
# Primeiro dispara busca para criar lead
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo:
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100', 'logradouro': 'Avenida Paulista', 'bairro': 'Bela Vista',
|
||||
'cidade': 'São Paulo', 'uf': 'SP', 'formatted_cep': '01310-100'
|
||||
}
|
||||
client.post('/api/v1/leads/search-maps', headers=user_headers, json={'cep': '01310-100', 'ramo': 'Padaria'})
|
||||
|
||||
response = client.post('/api/v1/leads/import-selected', headers=user_headers, json={
|
||||
'cep': '01310-100',
|
||||
'ramo': 'Padaria',
|
||||
'selected_leads': selected_items
|
||||
})
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()
|
||||
assert data['summary']['created_count'] == 1
|
||||
|
||||
def test_update_lead_status_and_interaction(client, user_headers):
|
||||
# Criar lead via import-selected
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo:
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100', 'logradouro': 'Avenida Paulista', 'bairro': 'Bela Vista',
|
||||
'cidade': 'São Paulo', 'uf': 'SP', 'formatted_cep': '01310-100'
|
||||
}
|
||||
client.post('/api/v1/leads/import-selected', headers=user_headers, json={
|
||||
'cep': '01310-100', 'ramo': 'Padaria',
|
||||
'selected_leads': [{'nome_empresa': 'Padaria Teste', 'telefone': '(11) 98888-7777'}]
|
||||
})
|
||||
|
||||
# Listar leads
|
||||
list_res = client.get('/api/v1/leads', headers=user_headers)
|
||||
assert list_res.status_code == 200
|
||||
leads = list_res.get_json()['leads']
|
||||
@@ -46,38 +84,29 @@ def test_update_lead_status_and_interaction(client, user_headers):
|
||||
assert update_res.status_code == 200
|
||||
assert update_res.get_json()['status_funil'] == 'contatado'
|
||||
|
||||
# Verificar historico de interacoes
|
||||
detail_res = client.get(f'/api/v1/leads/{lead_id}', headers=user_headers)
|
||||
assert detail_res.status_code == 200
|
||||
detail = detail_res.get_json()
|
||||
assert len(detail['interacoes']) >= 2
|
||||
types = [i['tipo'] for i in detail['interacoes']]
|
||||
assert 'status_change' in types
|
||||
|
||||
def test_opt_out_lgpd(client, user_headers):
|
||||
# Criar lead
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo:
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100', 'logradouro': 'Rua Teste', 'bairro': 'Centro',
|
||||
'cidade': 'São Paulo', 'uf': 'SP', 'formatted_cep': '01310-100'
|
||||
}
|
||||
client.post('/api/v1/leads/search-maps', headers=user_headers, json={'cep': '01310-100', 'ramo': 'Farmácia'})
|
||||
client.post('/api/v1/leads/import-selected', headers=user_headers, json={
|
||||
'cep': '01310-100', 'ramo': 'Farmácia',
|
||||
'selected_leads': [{'nome_empresa': 'Farmácia Teste', 'telefone': '(11) 97777-6666'}]
|
||||
})
|
||||
|
||||
list_res = client.get('/api/v1/leads', headers=user_headers)
|
||||
lead_id = list_res.get_json()['leads'][0]['id']
|
||||
|
||||
# Opt-out
|
||||
opt_res = client.post(f'/api/v1/leads/{lead_id}/opt-out', headers=user_headers)
|
||||
assert opt_res.status_code == 200
|
||||
assert opt_res.get_json()['lead']['status_funil'] == 'opt_out'
|
||||
|
||||
def test_export_leads(client, user_headers):
|
||||
# Exportar CSV
|
||||
csv_res = client.get('/api/v1/leads/export?format=csv', headers=user_headers)
|
||||
assert csv_res.status_code == 200
|
||||
assert 'text/csv' in csv_res.content_type
|
||||
|
||||
# Exportar JSON
|
||||
json_res = client.get('/api/v1/leads/export?format=json', headers=user_headers)
|
||||
assert json_res.status_code == 200
|
||||
assert isinstance(json_res.get_json(), list)
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
def test_n8n_webhook_flow(client, user_headers):
|
||||
# Criar lead
|
||||
# Criar lead via import-selected
|
||||
with patch('app.services.geocoding_service.GeocodingService.get_location_by_cep') as mock_geo:
|
||||
mock_geo.return_value = {
|
||||
'cep': '01310100', 'logradouro': 'Rua Teste', 'bairro': 'Centro',
|
||||
'cidade': 'São Paulo', 'uf': 'SP', 'formatted_cep': '01310-100'
|
||||
}
|
||||
client.post('/api/v1/leads/search-maps', headers=user_headers, json={'cep': '01310-100', 'ramo': 'Supermercado'})
|
||||
client.post('/api/v1/leads/import-selected', headers=user_headers, json={
|
||||
'cep': '01310-100', 'ramo': 'Supermercado',
|
||||
'selected_leads': [{'nome_empresa': 'Supermercado Teste', 'telefone': '(11) 99999-0000'}]
|
||||
})
|
||||
|
||||
leads = client.get('/api/v1/leads', headers=user_headers).get_json()['leads']
|
||||
assert len(leads) > 0
|
||||
lead_id = leads[0]['id']
|
||||
|
||||
# Disparar webhook n8n
|
||||
|
||||
Reference in New Issue
Block a user