Skip to content

Commit 0342016

Browse files
fix(episodes-post): turn comments field to optional
1 parent 1b362ad commit 0342016

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tmh_registry/registry/api/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ class EpisodeWriteSerializer(ModelSerializer):
303303
write_only=True, many=True, queryset=MedicalPersonnel.objects.all()
304304
)
305305
episode_type = CharField()
306+
comments = CharField(required=False)
306307
cepod = CharField()
307308
side = CharField()
308309
occurence = CharField()
@@ -362,7 +363,7 @@ def create(self, validated_data):
362363
Episode.EpisodeChoices.choices,
363364
validated_data["episode_type"],
364365
),
365-
comments=validated_data["comments"],
366+
comments=validated_data.get("comments", ""),
366367
cepod=get_text_choice_value_from_label(
367368
Episode.CepodChoices.choices, validated_data["cepod"]
368369
),

tmh_registry/registry/tests/api/viewsets/test_episodes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,14 @@ def test_create_episode_successful(self):
176176
Episode.AnaestheticChoices.choices, data["anaesthetic_type"]
177177
),
178178
)
179+
180+
def test_create_successful_without_optional_fields(self):
181+
data = self.get_episode_test_data()
182+
data.pop("comments")
183+
response = self.client.post(
184+
"/api/v1/episodes/", data=data, format="json"
185+
)
186+
187+
self.assertEqual(HTTP_201_CREATED, response.status_code)
188+
189+
self.assertEqual(response.data["comments"], "")

0 commit comments

Comments
 (0)