|
8 | 8 |
|
9 | 9 | from openarchiefbeheer.destruction.tests.factories import DestructionListItemFactory
|
10 | 10 | from openarchiefbeheer.utils.results_store import ResultStore
|
11 |
| -from openarchiefbeheer.zaken.utils import delete_zaak_and_related_objects |
| 11 | +from openarchiefbeheer.zaken.utils import ( |
| 12 | + delete_zaak_and_related_objects, |
| 13 | + format_zaaktype_choices, |
| 14 | +) |
12 | 15 |
|
13 | 16 |
|
14 | 17 | class DeletingZakenWithErrorsTests(TestCase):
|
@@ -143,3 +146,75 @@ def test_failure_on_deleting_zaak_relation_is_handled(self, m):
|
143 | 146 |
|
144 | 147 | with self.assertRaises(ConnectTimeout):
|
145 | 148 | delete_zaak_and_related_objects(destruction_list_item.zaak, result_store)
|
| 149 | + |
| 150 | + |
| 151 | +class FormatZaaktypeChoicesTests(TestCase): |
| 152 | + def test_format_zaaktype_choices_with_multiple_versions(self): |
| 153 | + # Test that the function picks the latest version of each zaaktype based on versiedatum |
| 154 | + # And test that the output is sorted by label |
| 155 | + zaaktypen = [ |
| 156 | + { |
| 157 | + "identificatie": "ZKT-001", |
| 158 | + "url": "http://localhost:8000/api/v1/zaaktypen/1", |
| 159 | + "omschrijving": "Zaaktype 1", |
| 160 | + "versiedatum": "2023-01-01", |
| 161 | + }, |
| 162 | + { |
| 163 | + "identificatie": "ZKT-001", |
| 164 | + "url": "http://localhost:8000/api/v1/zaaktypen/2", |
| 165 | + "omschrijving": "Zaaktype 1 Updated", |
| 166 | + "versiedatum": "2023-06-01", |
| 167 | + }, |
| 168 | + { |
| 169 | + "identificatie": "ZKT-002", |
| 170 | + "url": "http://localhost:8000/api/v1/zaaktypen/3", |
| 171 | + "omschrijving": "Zaaktype 2", |
| 172 | + "versiedatum": "2022-12-01", |
| 173 | + }, |
| 174 | + ] |
| 175 | + |
| 176 | + # Expecting the most recent version for each zaaktype, with URLs aggregated |
| 177 | + expected_result = [ |
| 178 | + { |
| 179 | + "label": "Zaaktype 1 Updated (ZKT-001)", |
| 180 | + "value": "http://localhost:8000/api/v1/zaaktypen/1,http://localhost:8000/api/v1/zaaktypen/2", |
| 181 | + }, |
| 182 | + { |
| 183 | + "label": "Zaaktype 2 (ZKT-002)", |
| 184 | + "value": "http://localhost:8000/api/v1/zaaktypen/3", |
| 185 | + }, |
| 186 | + ] |
| 187 | + |
| 188 | + result = format_zaaktype_choices(zaaktypen) |
| 189 | + self.assertEqual(result, expected_result) |
| 190 | + |
| 191 | + def test_format_zaaktype_choices_with_no_identificatie(self): |
| 192 | + # Test how the function handles zaaktypen with no identificatie |
| 193 | + zaaktypen = [ |
| 194 | + { |
| 195 | + "identificatie": None, |
| 196 | + "url": "http://localhost:8000/api/v1/zaaktypen/1", |
| 197 | + "omschrijving": "Zaaktype without ID", |
| 198 | + "versiedatum": "2023-01-01", |
| 199 | + } |
| 200 | + ] |
| 201 | + |
| 202 | + # Should fall back to using "no identificatie" in the label |
| 203 | + expected_result = [ |
| 204 | + { |
| 205 | + "label": "Zaaktype without ID (no identificatie)", |
| 206 | + "value": "http://localhost:8000/api/v1/zaaktypen/1", |
| 207 | + } |
| 208 | + ] |
| 209 | + |
| 210 | + result = format_zaaktype_choices(zaaktypen) |
| 211 | + self.assertEqual(result, expected_result) |
| 212 | + |
| 213 | + def test_format_zaaktype_choices_with_empty_input(self): |
| 214 | + # Test the behavior with an empty input list |
| 215 | + zaaktypen = [] |
| 216 | + expected_result = [] |
| 217 | + |
| 218 | + # Should return an empty list |
| 219 | + result = format_zaaktype_choices(zaaktypen) |
| 220 | + self.assertEqual(result, expected_result) |
0 commit comments