"""This module holds the test cases for the managers of the ``accounts`` app"""

from mtp.apps.common.tests.test_cases import MTPTestCase

from ..constants import POTENTIAL_DUPLICATE_REASONS
from ..factories import MTPUserFactory
from ..models import MTPUser


class MTPUserManagerTestCase(MTPTestCase):
    """Test case for the ``MTPUserManager``"""

    def test_get_potential_duplicates_should_work(self):
        """Test that the ``get_potential_duplicates`` method is working"""

        # First, create some user to test the method against...

        # User with the same first_name and last_name as the our trainee
        duplicated_trainee_1 = MTPUserFactory(
            first_name=self.trainee.first_name,
            last_name=self.trainee.last_name,
        )

        # User with the same first_name and _last_name but capitalized
        duplicated_trainee_2 = MTPUserFactory(
            first_name=self.trainee.first_name.upper(),
            last_name=self.trainee.last_name.upper(),
        )

        # User matched with a conflicted username during the sync
        duplicated_trainee_3 = MTPUserFactory(
            old_username=self.trainee.username
        )

        self.assertEqual(
            MTPUser.objects.get_potential_duplicates(self.trainee),
            {
                duplicated_trainee_1: POTENTIAL_DUPLICATE_REASONS.SAME_LAST_AND_FIRST_NAME,
                duplicated_trainee_2: POTENTIAL_DUPLICATE_REASONS.SAME_LAST_AND_FIRST_NAME,
                duplicated_trainee_3: POTENTIAL_DUPLICATE_REASONS.USERNAME_CONFLICT
            }
        )


