diff --git a/src/open_inwoner/accounts/views/contactmoments.py b/src/open_inwoner/accounts/views/contactmoments.py index 949c749491..677e482787 100644 --- a/src/open_inwoner/accounts/views/contactmoments.py +++ b/src/open_inwoner/accounts/views/contactmoments.py @@ -99,10 +99,7 @@ def get_kcm_data( ), } - # replace e_suite_subject_code with OIP configured subject, if applicable - e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", None) - - data["onderwerp"] = self.get_kcm_subject(kcm, e_suite_subject_code) + data["onderwerp"] = self.get_kcm_subject(kcm) return data @@ -114,13 +111,14 @@ def get_context_data(self, **kwargs): def get_kcm_subject( self, kcm: KlantContactMoment, - e_suite_subject_code: str | None, ) -> str | None: """ - Try to determine the subject ('onderwerp') of a contactmoment + Determine the subject (`onderwerp`) of a `KlantContactMoment.contactmoment`: + 1. replace e-suite subject code with OIP configured subject or + 2. return e-suite subject code or + 3. return an empty string as fallback """ - if not e_suite_subject_code: - return None + e_suite_subject_code = getattr(kcm.contactmoment, "onderwerp", "") try: subject = ContactFormSubject.objects.get(subject_code=e_suite_subject_code) @@ -133,7 +131,7 @@ def get_kcm_subject( kcm.contactmoment.url, exc_info=exc, ) - return None + return e_suite_subject_code return subject.subject diff --git a/src/open_inwoner/openklant/tests/test_views.py b/src/open_inwoner/openklant/tests/test_views.py index 52eba20223..d41c677391 100644 --- a/src/open_inwoner/openklant/tests/test_views.py +++ b/src/open_inwoner/openklant/tests/test_views.py @@ -41,13 +41,12 @@ class ContactMomentViewsTestCase(ClearCachesMixin, DisableRequestLogMixin, WebTest): maxDiff = None - @classmethod - def setUpTestData(cls): - super().setUpTestData() + def setUp(self): + super().setUp() MockAPIReadData.setUpServices() # for testing replacement of e-suite "onderwerp" code with OIP configured subject - cls.contactformsubject = ContactFormSubject.objects.create( + self.contactformsubject = ContactFormSubject.objects.create( subject="oip_subject", subject_code="e_suite_subject_code", config=OpenKlantConfig.get_solo(), @@ -363,6 +362,38 @@ def test_show_detail_for_bsn_with_zaak_reformat_esuite_id( ), ) + def test_display_esuite_subject_code(self, m, mock_get_kcm_answer_mapping): + data = MockAPIReadData().install_mocks(m) + + ContactFormSubject.objects.first().delete() + + detail_url = reverse( + "cases:contactmoment_detail", + kwargs={"kcm_uuid": data.klant_contactmoment["uuid"]}, + ) + list_url = reverse("cases:contactmoment_list") + response = self.app.get(list_url, user=data.user) + + kcms = response.context["contactmomenten"] + cm_data = data.contactmoment + + self.assertEqual(len(kcms), 1) + self.assertEqual( + kcms[0], + { + "registered_date": datetime.fromisoformat(cm_data["registratiedatum"]), + "channel": cm_data["kanaal"].title(), + "text": cm_data["tekst"], + "onderwerp": "e_suite_subject_code", + "antwoord": cm_data["antwoord"], + "identificatie": cm_data["identificatie"], + "type": cm_data["type"], + "status": Status.afgehandeld.label, + "url": detail_url, + "new_answer_available": False, + }, + ) + def test_show_detail_for_kvk_or_rsin(self, m, mock_get_kcm_answer_mapping): for use_rsin_for_innNnpId_query_parameter in [True, False]: with self.subTest(