diff --git a/care/facility/tests/test_bed_api.py b/care/facility/tests/test_bed_api.py index 973db41a96..3a3e000272 100644 --- a/care/facility/tests/test_bed_api.py +++ b/care/facility/tests/test_bed_api.py @@ -2,6 +2,8 @@ from rest_framework.test import APITestCase from care.facility.models import Bed +from care.facility.models.bed import AssetBed +from care.utils.assetintegration.asset_classes import AssetClasses from care.utils.tests.test_utils import TestUtils @@ -36,3 +38,28 @@ def test_list_beds(self): with self.assertNumQueries(5): response = self.client.get("/api/v1/bed/") self.assertEqual(response.status_code, status.HTTP_200_OK) + + def test_list_non_occupied_beds(self): + linked_bed = Bed.objects.create( + name="linked_bed", + location=self.asset_location, + facility=self.facility, + ) + asset = self.create_asset( + self.asset_location, asset_class=AssetClasses.HL7MONITOR.name + ) + AssetBed.objects.create(bed=linked_bed, asset=asset) + + # 4 beds 1 linked with HL7MONITOR and 3 created in setup + + response = self.client.get("/api/v1/bed/") + + # Assert list returns 4 beds + self.assertEqual(response.json()["count"], 4) + + response_with_not_occupied_bed = self.client.get( + "/api/v1/bed/?not_occupied_by_asset_type=HL7MONITOR" + ) + + # Assert count of unoccupied beds is 3 + self.assertEqual(response_with_not_occupied_bed.json()["count"], 3)