diff --git a/tests_unit/test__init__.py b/tests_unit/test__init__.py index 67bed83..5bc8e1d 100644 --- a/tests_unit/test__init__.py +++ b/tests_unit/test__init__.py @@ -1,3 +1,5 @@ +import asyncio +import typing from unittest import IsolatedAsyncioTestCase from unittest.mock import Mock, AsyncMock, patch, call @@ -79,6 +81,22 @@ async def test_should_call_route_when_adding_callback_endpoint(self): ) self.decorator.assert_called_once() + async def test_hook_to_callback_should_be_async_and_typed(self): + bd = BarterDude() + bd.add_endpoint = Mock() + bd._call_callback_endpoint = Mock() + + hook = Mock() + bd.add_callback_endpoint( + ['/my_route'], + hook, + [(Mock(), 'service')] + ) + + internal_hook = bd.add_endpoint.call_args_list[0][1].get('hook') + assert asyncio.iscoroutinefunction(internal_hook) is True + assert 'req' in typing.get_type_hints(internal_hook) + async def test_should_hook_call_on_callback_endpoint(self): async def mock_hook(message, barterdude): barterdude['service'].method_one()