Skip to content

Commit

Permalink
Patch user rule
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Jan 28, 2025
1 parent af08fda commit ef08c42
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/services/orders/validation_service/test_order_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from cg.services.orders.validation.workflows.tomte.models.order import TomteOrder
from cg.store.models import Customer
from cg.store.store import Store
from tests.store_helpers import StoreHelpers


def test_validate_customer_can_skip_reception_control(base_store: Store, valid_order: TomteOrder):
Expand Down Expand Up @@ -47,9 +48,12 @@ def test_validate_customer_does_not_exist(base_store: Store, valid_order: TomteO
assert isinstance(errors[0], CustomerDoesNotExistError)


def test_validate_user_belongs_to_customer(base_store: Store, valid_order: TomteOrder):
def test_validate_user_belongs_to_customer(
base_store: Store, valid_order: TomteOrder, helpers: StoreHelpers
):
# GIVEN an order for a customer which the logged-in user does not have access to
customer: Customer = base_store.get_customer_by_internal_id(valid_order.customer)
helpers.ensure_user(store=base_store, customer=customer)
customer.users = []

# WHEN validating that the user belongs to the customer account
Expand All @@ -62,3 +66,18 @@ def test_validate_user_belongs_to_customer(base_store: Store, valid_order: Tomte

# THEN the error should concern the user not belonging to the customer
assert isinstance(errors[0], UserNotAssociatedWithCustomerError)


def test_validate_admin_bypass(base_store: Store, valid_order: TomteOrder, helpers: StoreHelpers):
# GIVEN an order for a customer which the logged-in _admin_ user does not have access to
customer: Customer = base_store.get_customer_by_internal_id(valid_order.customer)
helpers.ensure_user(store=base_store, customer=customer, is_admin=True)
customer.users = []

# WHEN validating that the user belongs to the customer account
errors: list[UserNotAssociatedWithCustomerError] = validate_user_belongs_to_customer(
order=valid_order, store=base_store
)

# THEN no error should be raised
assert not errors

0 comments on commit ef08c42

Please sign in to comment.