diff --git a/server/graphql_schemas/tests/utils/test_helpers.py b/server/graphql_schemas/tests/utils/test_helpers.py index 6e7cb3da..70bc56f1 100644 --- a/server/graphql_schemas/tests/utils/test_helpers.py +++ b/server/graphql_schemas/tests/utils/test_helpers.py @@ -1,6 +1,12 @@ """Module that tests helper methods""" from unittest.mock import patch -from graphql_schemas.utils.helpers import update_event_status_on_calendar, remove_event_from_all_calendars +import datetime + +from graphql_schemas.utils.helpers import ( + update_event_status_on_calendar, + remove_event_from_all_calendars, + normalize_dates +) from api.tests.base_test_setup import BaseSetup @@ -65,3 +71,29 @@ def test_remove_event_from_all_calendar(self): self.assertEqual(mock_build.return_value.events.return_value.delete.called, True) self.assertEqual(mock_build.call_count, 1) mock_build_patcher.stop() + + def test_normalize_dates_function_success(self): + """ + Test that dates have to be in the present for them to be accepted + """ + start_date = datetime.date.today() + end_date = start_date + datetime.timedelta(days=1) + + result = normalize_dates(end_date, start_date, datetime.date.today()) + + self.assertEqual( + result, {'status': True, 'message': 'Validation successful'}) + + def test_normalize_dates_function_if_end_date_invalid(self): + """ + Test that the event must end in the future, after the event start date + """ + start_date = datetime.date.today() + datetime.timedelta(days=2) + end_date = datetime.date.today() + + result = normalize_dates(end_date, start_date, datetime.date.today()) + + self.assertEqual( + result, { + 'status': False, + 'message': 'Sorry, end date must be after start date'})