import pytest from fastapi.testclient import TestClient from pytest_mock import MockerFixture from syrupy.assertion import SnapshotAssertion from delivery_metadata.api.app import app from delivery_metadata.clients.graphql import ( get_product, ) from delivery_metadata.clients.graphql.product import _PRODUCT_QUERY, GraphQlProduct @pytest.mark.asyncio async def test_get_product( graphql_product_mock: GraphQlProduct, test_client: TestClient, mocker: MockerFixture, snapshot: SnapshotAssertion, ) -> None: mocker.patch.object( app.state.graphql_connector, "make_request", return_value={"product": graphql_product_mock.model_dump()}, ) result = await get_product(123) app.state.graphql_connector.make_request.assert_called_once_with( query=_PRODUCT_QUERY, params={"productId": "123"}, ) assert result == snapshot @pytest.mark.asyncio async def test_get_product_with_filter( graphql_product_mock: GraphQlProduct, test_client: TestClient, mocker: MockerFixture, snapshot: SnapshotAssertion, ) -> None: graphql_response = graphql_product_mock.model_dump() graphql_response["participations"].append( { "participated_as": "remixer", "participant": { "uuid": "6789d440-f448-4cae-a96e-b04e5376b794", "name": "", "appleMusicId": None, "spotifyId": None, "globalParticipant": None, }, } ) graphql_response["tracks"][0]["participations"].append( { "participated_as": "track_writer", "participant": { "uuid": "36afd047-b68d-49a5-b6dc-0940a04b905f", "name": "", "appleMusicId": None, "spotifyId": None, "globalParticipant": None, }, } ) mocker.patch.object( app.state.graphql_connector, "make_request", return_value={"product": graphql_response}, ) result = await get_product(123) app.state.graphql_connector.make_request.assert_called_once_with( query=_PRODUCT_QUERY, params={"productId": "123"}, ) assert result == snapshot