|
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 |
12 |
| - |
| 11 | +from openarchiefbeheer.zaken.utils import delete_zaak_and_related_objects, format_zaaktype_choices |
13 | 12 |
|
14 | 13 | class DeletingZakenWithErrorsTests(TestCase):
|
15 | 14 | @classmethod
|
@@ -143,3 +142,105 @@ def test_failure_on_deleting_zaak_relation_is_handled(self, m):
|
143 | 142 |
|
144 | 143 | with self.assertRaises(ConnectTimeout):
|
145 | 144 | delete_zaak_and_related_objects(destruction_list_item.zaak, result_store)
|
| 145 | + |
| 146 | +class FormatZaaktypeChoicesTests(TestCase): |
| 147 | + def test_format_zaaktype_choices_with_multiple_versions(self): |
| 148 | + # Test that the function picks the latest version of each zaaktype based on versiedatum |
| 149 | + zaaktypen = [ |
| 150 | + { |
| 151 | + "identificatie": "ZKT-001", |
| 152 | + "url": "http://localhost:8000/api/v1/zaaktypen/1", |
| 153 | + "omschrijving": "Zaaktype 1", |
| 154 | + "versiedatum": "2023-01-01", |
| 155 | + }, |
| 156 | + { |
| 157 | + "identificatie": "ZKT-001", |
| 158 | + "url": "http://localhost:8000/api/v1/zaaktypen/2", |
| 159 | + "omschrijving": "Zaaktype 1 Updated", |
| 160 | + "versiedatum": "2023-06-01", |
| 161 | + }, |
| 162 | + { |
| 163 | + "identificatie": "ZKT-002", |
| 164 | + "url": "http://localhost:8000/api/v1/zaaktypen/3", |
| 165 | + "omschrijving": "Zaaktype 2", |
| 166 | + "versiedatum": "2022-12-01", |
| 167 | + }, |
| 168 | + ] |
| 169 | + |
| 170 | + # Expecting the most recent version for each zaaktype, with URLs aggregated |
| 171 | + expected_result = [ |
| 172 | + { |
| 173 | + "label": "Zaaktype 1 Updated (ZKT-001)", |
| 174 | + "value": "http://localhost:8000/api/v1/zaaktypen/1,http://localhost:8000/api/v1/zaaktypen/2", |
| 175 | + }, |
| 176 | + { |
| 177 | + "label": "Zaaktype 2 (ZKT-002)", |
| 178 | + "value": "http://localhost:8000/api/v1/zaaktypen/3", |
| 179 | + }, |
| 180 | + ] |
| 181 | + |
| 182 | + result = format_zaaktype_choices(zaaktypen) |
| 183 | + self.assertEqual(result, expected_result) |
| 184 | + |
| 185 | + def test_format_zaaktype_choices_with_no_identificatie(self): |
| 186 | + # Test how the function handles zaaktypen with no identificatie |
| 187 | + zaaktypen = [ |
| 188 | + { |
| 189 | + "identificatie": None, |
| 190 | + "url": "http://localhost:8000/api/v1/zaaktypen/1", |
| 191 | + "omschrijving": "Zaaktype without ID", |
| 192 | + "versiedatum": "2023-01-01", |
| 193 | + } |
| 194 | + ] |
| 195 | + |
| 196 | + # Should fall back to using "no identificatie" in the label |
| 197 | + expected_result = [ |
| 198 | + { |
| 199 | + "label": "Zaaktype without ID (no identificatie)", |
| 200 | + "value": "http://localhost:8000/api/v1/zaaktypen/1", |
| 201 | + } |
| 202 | + ] |
| 203 | + |
| 204 | + result = format_zaaktype_choices(zaaktypen) |
| 205 | + self.assertEqual(result, expected_result) |
| 206 | + |
| 207 | + def test_format_zaaktype_choices_with_empty_input(self): |
| 208 | + # Test the behavior with an empty input list |
| 209 | + zaaktypen = [] |
| 210 | + expected_result = [] |
| 211 | + |
| 212 | + # Should return an empty list |
| 213 | + result = format_zaaktype_choices(zaaktypen) |
| 214 | + self.assertEqual(result, expected_result) |
| 215 | + |
| 216 | + def test_format_zaaktype_choices_sorted_output(self): |
| 217 | + # Test that the output is sorted by label |
| 218 | + zaaktypen = [ |
| 219 | + { |
| 220 | + "identificatie": "ZKT-002", |
| 221 | + "url": "http://localhost:8000/api/v1/zaaktypen/2", |
| 222 | + "omschrijving": "Zaaktype B", |
| 223 | + "versiedatum": "2023-01-01", |
| 224 | + }, |
| 225 | + { |
| 226 | + "identificatie": "ZKT-001", |
| 227 | + "url": "http://localhost:8000/api/v1/zaaktypen/1", |
| 228 | + "omschrijving": "Zaaktype A", |
| 229 | + "versiedatum": "2023-01-01", |
| 230 | + }, |
| 231 | + ] |
| 232 | + |
| 233 | + # Expecting the results to be sorted alphabetically by label |
| 234 | + expected_result = [ |
| 235 | + { |
| 236 | + "label": "Zaaktype A (ZKT-001)", |
| 237 | + "value": "http://localhost:8000/api/v1/zaaktypen/1", |
| 238 | + }, |
| 239 | + { |
| 240 | + "label": "Zaaktype B (ZKT-002)", |
| 241 | + "value": "http://localhost:8000/api/v1/zaaktypen/2", |
| 242 | + }, |
| 243 | + ] |
| 244 | + |
| 245 | + result = format_zaaktype_choices(zaaktypen) |
| 246 | + self.assertEqual(result, expected_result) |
0 commit comments