diff --git a/server/polar/checkout/schemas.py b/server/polar/checkout/schemas.py index f5696a5904..66eecf8b9f 100644 --- a/server/polar/checkout/schemas.py +++ b/server/polar/checkout/schemas.py @@ -176,6 +176,9 @@ class CheckoutBase(IDSchema, TimestampedSchema): class Checkout(MetadataOutputMixin, CheckoutBase): """Checkout session data retrieved using an access token.""" + product: Product + product_price: ProductPrice + class CheckoutPublic(CheckoutBase): """Checkout session data retrieved using the client secret.""" diff --git a/server/tests/checkout/test_endpoints.py b/server/tests/checkout/test_endpoints.py index 153d934496..739a297bcf 100644 --- a/server/tests/checkout/test_endpoints.py +++ b/server/tests/checkout/test_endpoints.py @@ -1,3 +1,4 @@ +import uuid from types import SimpleNamespace from unittest.mock import AsyncMock, MagicMock @@ -41,6 +42,40 @@ async def checkout_open( return await create_checkout(save_fixture, price=product_one_time.prices[0]) +@pytest.mark.asyncio +@pytest.mark.skip_db_asserts +class TestGet: + async def test_anonymous( + self, client: AsyncClient, checkout_open: Checkout + ) -> None: + response = await client.get(f"{API_PREFIX}/{checkout_open.id}") + + assert response.status_code == 401 + + @pytest.mark.auth(AuthSubjectFixture(scopes={Scope.checkouts_read})) + async def test_not_existing(self, client: AsyncClient) -> None: + response = await client.get(f"{API_PREFIX}/{uuid.uuid4()}") + + assert response.status_code == 404 + + @pytest.mark.auth(AuthSubjectFixture(scopes={Scope.checkouts_read})) + async def test_valid( + self, + client: AsyncClient, + checkout_open: Checkout, + user_organization: UserOrganization, + ) -> None: + response = await client.get(f"{API_PREFIX}/{checkout_open.id}") + + assert response.status_code == 200 + + json = response.json() + assert json["id"] == str(checkout_open.id) + assert "metadata" in json + assert "product" in json + assert "product_price" in json + + @pytest.mark.asyncio @pytest.mark.skip_db_asserts class TestCreateCheckout: