"""This module holds serializer tests for ``likes`` app."""

from mtp.apps.common.tests.test_cases import MTPTestCase
from mtp.apps.likes.tests.likeable_testapp.models import Proposition
from mtp.apps.likes.tests.likeable_testapp.serializers import PropositionSerializer


class LikeableSerializerTestCase(MTPTestCase):
    """Test the ``LikeableSerializer`` serializer."""

    @classmethod
    def setUpTestData(cls):
        """Create a proposition."""
        super().setUpTestData()

        cls.proposition = Proposition.objects.create(text='fake_proposition')

    def test_likes_field(self):
        """Test the ``likes`` field is correctly formatted."""

        self.trainee.like(self.proposition)
        data = PropositionSerializer(self.proposition).data

        self.assertIn('likes', data)
        self.assertEqual(data['likes'], [{
            'author': self.trainee.id,
            'weight': 1,
        }])

