diff --git a/care/facility/tests/test_patient_daily_rounds_api.py b/care/facility/tests/test_patient_daily_rounds_api.py index 22733cfadb..8291d0ce6d 100644 --- a/care/facility/tests/test_patient_daily_rounds_api.py +++ b/care/facility/tests/test_patient_daily_rounds_api.py @@ -1,9 +1,16 @@ +import datetime + from rest_framework import status +from care.facility.models import PatientRegistration from care.utils.tests.test_base import TestBase -class TestDailyRoundApi(TestBase): +class TestDailyRound(TestBase): + def setUp(self) -> None: + super().setUp() + self.consultation = self.create_consultation() + def get_url(self, external_consultation_id=None): return f"/api/v1/consultation/{external_consultation_id}/daily_rounds/analyse/" @@ -11,3 +18,26 @@ def test_external_consultation_does_not_exists_returns_404(self): sample_uuid = "e4a3d84a-d678-4992-9287-114f029046d8" response = self.client.get(self.get_url(sample_uuid)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + + def test_action_in_log_update( + self, + ): + log_update = { + "clone_last": False, + "rounds_type": "NORMAL", + "patient_category": "Comfort", + "action": "DISCHARGE_RECOMMENDED", + "taken_at": datetime.datetime.now().isoformat(), + } + response = self.client.post( + f"/api/v1/consultation/{self.consultation.external_id}/daily_rounds/", + data=log_update, + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.data["patient_category"], "Comfort Care") + self.assertEqual(response.data["rounds_type"], "NORMAL") + patient = PatientRegistration.objects.get(id=self.consultation.patient_id) + self.assertEqual( + patient.action, PatientRegistration.ActionEnum.DISCHARGE_RECOMMENDED.value + ) diff --git a/care/utils/tests/test_base.py b/care/utils/tests/test_base.py index 25427225e3..3fa6efb7f6 100644 --- a/care/utils/tests/test_base.py +++ b/care/utils/tests/test_base.py @@ -97,9 +97,10 @@ def create_facility( "created_by": user, } data.update(kwargs) - f = Facility(**data) - f.save() - return f + facility = Facility.objects.create(**data) + facility.users.add(user) + User.objects.filter(id=user.id).update(home_facility=facility) + return facility @classmethod def create_patient(cls, facility=None, **kwargs):