|
| 1 | +from unittest import mock |
| 2 | + |
| 3 | + |
| 4 | +@mock.patch("routes.v1.contact.utils.get_contact_by_email") |
| 5 | +def test_get_contact_by_email(mock_get_contact_by_email, client): |
| 6 | + mock_get_contact_by_email.return_value = { |
| 7 | + "id": "1234", |
| 8 | + |
| 9 | + "firstname": "test", |
| 10 | + "lastname": "user", |
| 11 | + } |
| 12 | + response = client. get( "/api/v1/contact/[email protected]") |
| 13 | + assert response.status_code == 200 |
| 14 | + assert response.json() == { |
| 15 | + "id": "1234", |
| 16 | + |
| 17 | + "firstname": "test", |
| 18 | + "lastname": "user", |
| 19 | + } |
| 20 | + |
| 21 | + |
| 22 | +@mock.patch("routes.v1.contact.utils.create_contact") |
| 23 | +@mock.patch("routes.v1.contact._contact.create_contact") |
| 24 | +def test_create_contact( |
| 25 | + mock_db_create_contact, mock_hubspot_create_contact, organization, client |
| 26 | +): |
| 27 | + mock_db_create_contact.return_value = { |
| 28 | + "first_name": "raaj", |
| 29 | + "last_name": "das", |
| 30 | + |
| 31 | + "phone": "+254720323309", |
| 32 | + } |
| 33 | + mock_hubspot_create_contact.return_value = {"contact_id": 12356} |
| 34 | + response = client.post( |
| 35 | + "/api/v1/contacts/", |
| 36 | + json={ |
| 37 | + "first_name": "raaj", |
| 38 | + "last_name": "das", |
| 39 | + |
| 40 | + "phone": "+255720323309", |
| 41 | + "company_name": "Test org", |
| 42 | + }, |
| 43 | + ) |
| 44 | + assert response.status_code == 200 |
| 45 | + assert response.json() == {"contact_id": 12356} |
0 commit comments