diff --git a/src/spotifyaio/models.py b/src/spotifyaio/models.py index 2cdfef54..ac1a784c 100644 --- a/src/spotifyaio/models.py +++ b/src/spotifyaio/models.py @@ -545,7 +545,7 @@ class ProductType(StrEnum): class BaseUserProfile(DataClassORJSONMixin): """Base user profile model.""" - display_name: str + display_name: str | None user_id: str = field(metadata=field_options(alias="id")) images: list[Image] object_type: str = field(metadata=field_options(alias="type")) diff --git a/tests/test_spotify.py b/tests/test_spotify.py index e366333b..1c42b856 100644 --- a/tests/test_spotify.py +++ b/tests/test_spotify.py @@ -832,6 +832,22 @@ async def test_get_current_user( ) +async def test_get_current_user_without_display_name( + responses: aiointercept, + authenticated_client: SpotifyClient, +) -> None: + """Test retrieving current user without a display name.""" + body = json.loads(load_fixture("current_user.json")) + body["display_name"] = None + responses.get( + f"{SPOTIFY_URL}/v1/me", + status=200, + body=json.dumps(body), + ) + response = await authenticated_client.get_current_user() + assert response.display_name is None + + async def test_get_current_user_without_deprecated_fields( responses: aiointercept, authenticated_client: SpotifyClient,