"""Test for store logic.""" from typing import Any from unittest.mock import Mock from store.logic import store as store_logic from store.models import store as store_model def test_get_stores(mocker: Mock, dummy_stores: list[dict[str, Any]]) -> None: """Test that stores are returned with correct formatting.""" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores() mock_get_stores.assert_called_with( supports_timed_release=None, classification_id=None, statuses=None, order_by=None, order_dir=None, ) assert result == dummy_stores def test_get_stores_filter_timed_release( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that stores supporting timed release are returned with correct formatting.""" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(supports_timed_release=True) mock_get_stores.assert_called_with( supports_timed_release=True, classification_id=None, statuses=None, order_by=None, order_dir=None, ) assert result == dummy_stores def test_get_stores_filter_no_timed_release( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that stores not supporting timed release are returned with correct formatting.""" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(supports_timed_release=False) mock_get_stores.assert_called_with( supports_timed_release=False, classification_id=None, statuses=None, order_by=None, order_dir=None, ) assert result == dummy_stores def test_get_stores_with_classification_id( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives classification id and logic returns result.""" classification_id = 14 mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(classification_id=classification_id) mock_get_stores.assert_called_with( supports_timed_release=None, classification_id=classification_id, statuses=None, order_by=None, order_dir=None, ) assert result == dummy_stores def test_get_stores_with_order_by( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives order_by and logic returns result.""" order_by = "customer_name" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(order_by=order_by) mock_get_stores.assert_called_with( supports_timed_release=None, classification_id=None, statuses=None, order_by=order_by, order_dir=None, ) assert result == dummy_stores def test_get_stores_with_order_dir( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives order_by and logic returns result.""" order_dir = "asc" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(order_dir=order_dir) mock_get_stores.assert_called_with( supports_timed_release=None, classification_id=None, statuses=None, order_by=None, order_dir=order_dir, ) assert result == dummy_stores def test_get_stores_with_statuses( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives classification id and logic returns result.""" status = "active" mock_get_stores = mocker.patch.object( store_model, "get_stores", return_value=dummy_stores ) result = store_logic.get_stores(statuses=[status]) mock_get_stores.assert_called_with( supports_timed_release=None, classification_id=None, statuses=[status], order_by=None, order_dir=None, ) assert result == dummy_stores def test_get_stores_by_store_ids( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives stores ids and logic returns result.""" mock_get_stores_by_ids = mocker.patch.object( store_model, "get_stores_by_ids", return_value=dummy_stores ) store_ids = [s["id"] for s in dummy_stores] result = store_logic.get_stores_by_ids(store_ids) mock_get_stores_by_ids.assert_called_with(store_ids) assert result == dummy_stores def test_get_store_classifications_by_store_ids( mocker: Mock, dummy_stores: list[dict[str, Any]] ) -> None: """Test that model layer receives stores ids and logic returns result.""" mock_get_store_classifications_by_store_ids = mocker.patch.object( store_model, "get_store_classifications_by_store_ids", return_value=dummy_stores ) store_ids = [s["id"] for s in dummy_stores] result = store_logic.get_store_classifications_by_store_ids(store_ids) mock_get_store_classifications_by_store_ids.assert_called_with(store_ids) assert result == dummy_stores