Skip to content

Commit ce01303

Browse files
committed
test: ✅ add unit tests #192
1 parent 31a198e commit ce01303

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ def time_entry_repository(app: Flask) -> TimeEntryCosmosDBRepository:
181181
return TimeEntryCosmosDBRepository()
182182

183183

184+
@pytest.fixture
185+
def time_entries_dao():
186+
from time_tracker_api.time_entries.time_entries_namespace import (
187+
time_entries_dao,
188+
)
189+
190+
return time_entries_dao
191+
192+
184193
@pytest.yield_fixture(scope="module")
185194
def running_time_entry(
186195
time_entry_repository: TimeEntryCosmosDBRepository,

tests/time_tracker_api/time_entries/time_entries_namespace_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,45 @@ def test_summary_is_called_with_date_range_from_worked_time_module(
639639
repository_find_all_mock.assert_called_once_with(
640640
ANY, conditions=conditions, date_range=date_range
641641
)
642+
643+
644+
def test_paginated_fails_with_no_params(
645+
client: FlaskClient, valid_header: dict,
646+
):
647+
response = client.get('/time-entries/paginated', headers=valid_header)
648+
assert HTTPStatus.BAD_REQUEST == response.status_code
649+
650+
651+
def test_paginated_succeeds_with_valid_params(
652+
client: FlaskClient, valid_header: dict,
653+
):
654+
response = client.get(
655+
'/time-entries/paginated?start=10&length=10', headers=valid_header
656+
)
657+
assert HTTPStatus.OK == response.status_code
658+
659+
660+
def test_paginated_response_contains_expected_props(
661+
client: FlaskClient, valid_header: dict,
662+
):
663+
response = client.get(
664+
'/time-entries/paginated?start=10&length=10', headers=valid_header
665+
)
666+
assert 'data' in json.loads(response.data)
667+
assert 'records_total' in json.loads(response.data)
668+
669+
670+
def test_paginated_sends_max_count_and_offset_on_call_to_repository(
671+
client: FlaskClient, valid_header: dict, time_entries_dao
672+
):
673+
time_entries_dao.repository.find_all = Mock(return_value=[])
674+
675+
response = client.get(
676+
'/time-entries/paginated?start=10&length=10', headers=valid_header
677+
)
678+
679+
time_entries_dao.repository.find_all.assert_called_once()
680+
681+
args, kwargs = time_entries_dao.repository.find_all.call_args
682+
assert 'max_count' in kwargs and kwargs['max_count'] is not None
683+
assert 'offset' in kwargs and kwargs['offset'] is not None

0 commit comments

Comments
 (0)