Skip to content

Commit f90a48d

Browse files
committed
fixes tests
1 parent 895c830 commit f90a48d

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_users.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ async def get_billing_details(
324324
product_name: str,
325325
user_id: int,
326326
) -> Any | None:
327+
"""Returns billing details for the specified user and product.
328+
329+
- If the user is registered without a product, returns details for that registration.
330+
- Returns None if no billing details are found.
331+
"""
327332
async with pass_or_acquire_connection(self._engine, connection) as conn:
328333
result = await conn.execute(
329334
sa.select(
@@ -345,7 +350,10 @@ async def get_billing_details(
345350
)
346351
.where(
347352
(users.c.id == user_id)
348-
& (users_pre_registration_details.c.product_name == product_name)
353+
& (
354+
(users_pre_registration_details.c.product_name == product_name)
355+
| (users_pre_registration_details.c.product_name.is_(None))
356+
)
349357
)
350358
.order_by(users_pre_registration_details.c.created.desc())
351359
.limit(1)

packages/postgres-database/tests/test_users_details.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ async def test_create_and_link_user_from_pre_registration(
288288
async def test_get_billing_details_from_pre_registration(
289289
asyncpg_engine: AsyncEngine,
290290
pre_registered_user: tuple[str, dict[str, Any]],
291+
product: dict[str, Any],
291292
):
292293
"""Test that billing details can be retrieved from pre-registration data."""
293294
pre_email, fake_pre_registration_data = pre_registered_user
@@ -309,7 +310,9 @@ async def test_get_billing_details_from_pre_registration(
309310
)
310311

311312
# Get billing details
312-
invoice_data = await repo.get_billing_details(user_id=new_user.id)
313+
invoice_data = await repo.get_billing_details(
314+
user_id=new_user.id, product_name=product["name"]
315+
)
313316
assert invoice_data is not None
314317

315318
# Test UserAddress model conversion

services/web/server/src/simcore_service_webserver/users/_users_repository.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ async def get_user_billing_details(
373373
product_name: ProductName,
374374
) -> UserBillingDetails:
375375
"""
376+
Returns UserBillingDetails for the given user when registered in a product or None
376377
Raises:
377378
BillingDetailsNotFoundError
378379
"""

services/web/server/tests/unit/with_dbs/04/wallets/payments/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ def setup_user_pre_registration_details_db(
342342
country=faker.random_element([c.name for c in pycountry.countries]),
343343
postal_code=faker.postcode(),
344344
created_by=None,
345+
# NOTE: here product is not specified (i.e. product_name=None) on purspose to check
346+
# backwards compatibility
345347
)
346348
.returning(sa.literal_column("*"))
347349
)

0 commit comments

Comments
 (0)