from __future__ import annotations

import unittest

from govoplan_core.mail.config import normalize_split_transport_credentials


class MailConfigTests(unittest.TestCase):
    def test_normalize_split_transport_credentials_moves_legacy_auth_fields(self) -> None:
        payload = normalize_split_transport_credentials(
            {
                "smtp": {"host": "smtp.example.test", "username": "smtp-user", "password": "smtp-secret"},
                "imap": {"host": "imap.example.test", "enabled": True, "username": "imap-user"},
                "credentials": {"smtp": {"username": "existing"}},
            }
        )

        self.assertEqual(
            {
                "smtp": {"host": "smtp.example.test"},
                "imap": {"host": "imap.example.test"},
                "credentials": {
                    "smtp": {"username": "existing", "password": "smtp-secret"},
                    "imap": {"username": "imap-user"},
                },
            },
            payload,
        )


if __name__ == "__main__":
    unittest.main()
