Skip to content

Commit

Permalink
✅ [#498] Test new serialiser field
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Nov 21, 2024
1 parent 28f1807 commit 65a6f76
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@

from openarchiefbeheer.accounts.tests.factories import UserFactory

from ...constants import InternalStatus, ListItemStatus
from ..factories import DestructionListFactory, DestructionListItemFactory
from ...constants import (
DestructionListItemAction,
InternalStatus,
ListItemStatus,
ListStatus,
)
from ..factories import (
DestructionListFactory,
DestructionListItemFactory,
DestructionListItemReviewFactory,
DestructionListReviewFactory,
ReviewItemResponseFactory,
)


class DestructionListItemsViewSetTest(APITestCase):
Expand Down Expand Up @@ -221,3 +232,49 @@ def test_item_with_extra_zaak_data(self):
data["results"][0]["extraZaakData"]["url"],
"http://localhost:8003/zaken/api/v1/zaken/eafc5f37-4524-43ce-872f-39ff3df11e1e",
)

def test_retrieve_items_with_review_responses(self):
record_manager = UserFactory.create(post__can_start_destruction=True)
review = DestructionListReviewFactory.create(
destruction_list__author=record_manager,
destruction_list__status=ListStatus.changes_requested,
)
item_reviews = DestructionListItemReviewFactory.create_batch(
3,
destruction_list_item__destruction_list=review.destruction_list,
review=review,
)
ReviewItemResponseFactory.create(
review_item=item_reviews[1],
review_item__review=review,
action_item=DestructionListItemAction.keep,
)
ReviewItemResponseFactory.create(
review_item=item_reviews[2],
review_item__review=review,
action_item=DestructionListItemAction.remove,
)

self.client.force_authenticate(user=record_manager)
endpoint = reverse("api:destruction-list-items-list")

response = self.client.get(
endpoint,
)

self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.json()

self.assertEqual(
data["results"][0]["pk"], item_reviews[1].destruction_list_item.pk
)
self.assertTrue(data["results"][0]["reviewAdviceIgnored"])
self.assertEqual(
data["results"][1]["pk"], item_reviews[2].destruction_list_item.pk
)
self.assertFalse(data["results"][1]["reviewAdviceIgnored"])
self.assertEqual(
data["results"][2]["pk"], item_reviews[0].destruction_list_item.pk
)
self.assertIsNone(data["results"][2]["reviewAdviceIgnored"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from django.test import TestCase

from openarchiefbeheer.accounts.tests.factories import UserFactory

from ...api.serializers import DestructionListItemReadSerializer
from ...constants import DestructionListItemAction, ListStatus
from ..factories import (
DestructionListItemReviewFactory,
DestructionListReviewFactory,
ReviewItemResponseFactory,
)


class TestDestructionListItemSerializer(TestCase):
def test_ignored_review_advice(self):
record_manager = UserFactory.create(post__can_start_destruction=True)
review = DestructionListReviewFactory.create(
destruction_list__author=record_manager,
destruction_list__status=ListStatus.changes_requested,
)
item_reviews = DestructionListItemReviewFactory.create_batch(
3,
destruction_list_item__destruction_list=review.destruction_list,
review=review,
)
ReviewItemResponseFactory.create(
review_item=item_reviews[1],
review_item__review=review,
action_item=DestructionListItemAction.keep,
)
ReviewItemResponseFactory.create(
review_item=item_reviews[2],
review_item__review=review,
action_item=DestructionListItemAction.remove,
)

with self.subTest("Accepted item"):
serialiser = DestructionListItemReadSerializer(
instance=item_reviews[0].destruction_list_item
)

self.assertIsNone(serialiser.data["review_advice_ignored"])

with self.subTest("Item with ignored feedback"):
serialiser = DestructionListItemReadSerializer(
instance=item_reviews[1].destruction_list_item
)

self.assertTrue(serialiser.data["review_advice_ignored"])

with self.subTest("Item with accepted feedback"):
serialiser = DestructionListItemReadSerializer(
instance=item_reviews[2].destruction_list_item
)

self.assertFalse(serialiser.data["review_advice_ignored"])

0 comments on commit 65a6f76

Please sign in to comment.