test(repositories): lock in UserRepository JSON column decoding

Covers the columns UserRepository._to_model decodes so a narrower or wider
column set fails instead of silently changing what callers read back.
This commit is contained in:
mateo-berri 2026-07-31 19:26:04 +00:00
parent c0cab45350
commit 2258dc08aa
No known key found for this signature in database

View file

@ -1905,6 +1905,28 @@ class TestUserRepositoryExtended:
)
assert updated.user_email == "new@example.com"
@pytest.mark.asyncio
async def test_find_by_id_decodes_only_the_json_encoded_columns(self, repo):
repo._prisma_client.db.litellm_usertable._records["user-json"] = {
"user_id": "user-json",
"user_email": "json@example.com",
"user_role": '{"not": "json"}',
"teams": [],
"models": [],
"metadata": '{"department": "engineering"}',
"model_spend": '{"gpt-4": 10.5}',
"model_max_budget": '{"gpt-4": 100.0}',
}
user = await repo.find_by_id("user-json")
assert user is not None
assert user.metadata == {"department": "engineering"}
assert user.model_spend == {"gpt-4": 10.5}
assert user.model_max_budget == {"gpt-4": 100.0}
assert user.user_email == "json@example.com"
assert user.user_role == '{"not": "json"}'
class TestProjectRepositoryExtended:
@pytest.fixture