# tests/unit/api/test_storefront_auth.py """ Unit tests for storefront auth cookie handling. Tests that customer_token cookie is set with path='/' so it works across all URL patterns (dev mode with /platforms/ prefix, prod mode with subdomains). """ import pytest @pytest.mark.unit class TestCustomerTokenCookiePath: """Verify cookie path is set correctly for cross-routing compatibility.""" def test_login_sets_cookie_with_root_path(self): """ The customer_token cookie must use path='/' to work with all URL patterns. Previously the cookie path was calculated as '/storefront/{subdomain}/storefront' which didn't match the actual page URLs (/platforms/{code}/storefront/{store_code}/...). """ import inspect from app.modules.customers.routes.api.storefront import customer_login source = inspect.getsource(customer_login) # Verify the cookie is set with path="/" assert 'path="/"' in source or "path='/'" in source, ( "customer_login must set cookie with path='/'. " "Other paths like '/storefront' or '/storefront/{subdomain}/storefront' " "don't match dev mode URLs (/platforms/{code}/storefront/{store_code}/...)" ) def test_logout_deletes_cookie_with_root_path(self): """The customer_token cookie must be deleted with path='/' to match the set path.""" import inspect from app.modules.customers.routes.api.storefront import customer_logout source = inspect.getsource(customer_logout) assert 'path="/"' in source or "path='/'" in source, ( "customer_logout must delete cookie with path='/' to match how it was set" )