|
15 | 15 | from openarchiefbeheer.destruction.tests.factories import (
|
16 | 16 | DestructionListFactory,
|
17 | 17 | DestructionListItemFactory,
|
| 18 | + DestructionListItemReviewFactory, |
| 19 | + DestructionListReviewFactory, |
18 | 20 | )
|
19 | 21 |
|
20 | 22 | from ..tasks import retrieve_and_cache_zaken_from_openzaak
|
@@ -300,6 +302,64 @@ def test_not_cached_if_query_param_chages(self, m):
|
300 | 302 | self.assertEqual(response.status_code, status.HTTP_200_OK)
|
301 | 303 | self.assertEqual(len(response.json()), 3)
|
302 | 304 |
|
| 305 | + def test_retrieve_zaaktypen_choices_for_review(self): |
| 306 | + user = UserFactory.create(role__can_start_destruction=True) |
| 307 | + |
| 308 | + review = DestructionListReviewFactory.create() |
| 309 | + # The zaaktypen of these items should be returned, |
| 310 | + # because they are in the review |
| 311 | + review_items = DestructionListItemReviewFactory.create_batch( |
| 312 | + 3, |
| 313 | + destruction_list_item__with_zaak=True, |
| 314 | + destruction_list_item__zaak__with_expand=True, |
| 315 | + destruction_list=review.destruction_list, |
| 316 | + review=review, |
| 317 | + ) |
| 318 | + # We simulate 2 items having different versions of the same zaaktype |
| 319 | + review_items[0].destruction_list_item.zaak._expand["zaaktype"][ |
| 320 | + "identificatie" |
| 321 | + ] = "ZAAKTYPE-1" |
| 322 | + review_items[0].destruction_list_item.zaak.save() |
| 323 | + review_items[1].destruction_list_item.zaak._expand["zaaktype"][ |
| 324 | + "identificatie" |
| 325 | + ] = "ZAAKTYPE-1" |
| 326 | + review_items[1].destruction_list_item.zaak.save() |
| 327 | + review_items[2].destruction_list_item.zaak._expand["zaaktype"][ |
| 328 | + "identificatie" |
| 329 | + ] = "ZAAKTYPE-2" |
| 330 | + review_items[2].destruction_list_item.zaak.save() |
| 331 | + |
| 332 | + # These zaaktypen should NOT be returned because they are not in the review |
| 333 | + DestructionListItemReviewFactory.create_batch( |
| 334 | + 3, |
| 335 | + destruction_list_item__with_zaak=True, |
| 336 | + destruction_list_item__zaak__with_expand=True, |
| 337 | + ) |
| 338 | + |
| 339 | + self.client.force_authenticate(user=user) |
| 340 | + endpoint = furl(reverse("api:retrieve-zaaktypen-choices")) |
| 341 | + endpoint.args["review"] = review.pk |
| 342 | + |
| 343 | + response = self.client.get(endpoint.url) |
| 344 | + |
| 345 | + self.assertEqual(response.status_code, status.HTTP_200_OK) |
| 346 | + |
| 347 | + choices = sorted(response.json(), key=lambda choice: choice["label"]) |
| 348 | + |
| 349 | + self.assertEqual(len(choices), 2) |
| 350 | + self.assertEqual(choices[0]["label"], "ZAAKTYPE-1") |
| 351 | + self.assertEqual(choices[1]["label"], "ZAAKTYPE-2") |
| 352 | + |
| 353 | + values = choices[0]["value"].split(",") |
| 354 | + |
| 355 | + self.assertEqual(len(values), 2) |
| 356 | + self.assertIn(review_items[0].destruction_list_item.zaak.zaaktype, values) |
| 357 | + self.assertIn(review_items[1].destruction_list_item.zaak.zaaktype, values) |
| 358 | + |
| 359 | + self.assertEqual( |
| 360 | + choices[1]["value"], review_items[2].destruction_list_item.zaak.zaaktype |
| 361 | + ) |
| 362 | + |
303 | 363 |
|
304 | 364 | class SelectielijstklasseChoicesViewTests(APITestCase):
|
305 | 365 | def setUp(self):
|
|
0 commit comments