import unittest

from codec import upgrade_payload


class CodecTests(unittest.TestCase):
    def test_legacy_alias_is_upgraded(self):
        self.assertEqual(upgrade_payload({"userId": "u", "x": 1}), {"user_id": "u", "x": 1})

    def test_conflicting_aliases_are_rejected(self):
        with self.assertRaises(ValueError):
            upgrade_payload({"userId": "old", "user_id": "new"})

    def test_nested_input_does_not_alias(self):
        source = {"user_id": "u", "metadata": {"safe": True}}
        output = upgrade_payload(source)
        output["metadata"]["safe"] = False
        self.assertTrue(source["metadata"]["safe"])


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