diff --git a/test/test_client_contact.py b/test/test_client_contact.py new file mode 100644 index 0000000..ad360c7 --- /dev/null +++ b/test/test_client_contact.py @@ -0,0 +1,52 @@ +import pytest # type: ignore +from unittest.mock import patch +from superfaktura.client_contacts import ( + ClientContactModel, + ClientContact, + ClientException, +) + + +@pytest.fixture +def client_contact(): + with patch("superfaktura.client_contacts.ClientContact", return_value=None): + return ClientContact() + + +def test_add_contact_success(client_contact): + client = ClientContactModel( + name="John Doe", + ) + + with patch("superfaktura.superfaktura_api.SuperFakturaAPI.post") as mock_post: + mock_post.return_value = {"error_message": "Client created"} + assert client_contact.add_contact(contact=client) + + +def test_add_contact_failed(client_contact): + client = ClientContactModel( + name="John Doe", + ) + + with patch("superfaktura.superfaktura_api.SuperFakturaAPI.post") as mock_post: + mock_post.return_value = {"error_message": "Client creation failed"} + assert not client_contact.add_contact(contact=client) + + +def test_list(client_contact): + with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: + mock_get.return_value = {"data": "test"} + assert client_contact.list() == {"data": "test"} + + +def test_get_client_exists(client_contact): + with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: + mock_get.return_value = {"Client": {"name": "John Doe", "id": 1}} + assert client_contact.get_client(client_id=1).name == "John Doe" + + +def test_get_client_not_exists(client_contact): + with patch("superfaktura.superfaktura_api.SuperFakturaAPI.get") as mock_get: + mock_get.return_value = {} + with pytest.raises(ClientException): + client_contact.get_client(client_id=1)