Skip to content

Commit fa14e34

Browse files
committed
✅ [#234] Test filtering on review
1 parent ee3dc9e commit fa14e34

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

backend/src/openarchiefbeheer/zaken/tests/test_views.py

+60
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from openarchiefbeheer.destruction.tests.factories import (
1616
DestructionListFactory,
1717
DestructionListItemFactory,
18+
DestructionListItemReviewFactory,
19+
DestructionListReviewFactory,
1820
)
1921

2022
from ..tasks import retrieve_and_cache_zaken_from_openzaak
@@ -300,6 +302,64 @@ def test_not_cached_if_query_param_chages(self, m):
300302
self.assertEqual(response.status_code, status.HTTP_200_OK)
301303
self.assertEqual(len(response.json()), 3)
302304

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+
303363

304364
class SelectielijstklasseChoicesViewTests(APITestCase):
305365
def setUp(self):

0 commit comments

Comments
 (0)