flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/modules/cart/fake_payment_selection_validator.go (about)

     1  package cart
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"net/http"
     7  
     8  	"flamingo.me/flamingo/v3/framework/web"
     9  
    10  	"flamingo.me/flamingo-commerce/v3/cart/domain/cart"
    11  	"flamingo.me/flamingo-commerce/v3/cart/domain/decorator"
    12  )
    13  
    14  // FakePaymentSelectionValidatorCookie name to control behaviour
    15  const FakePaymentSelectionValidatorCookie = "X-FakePaymentSelectionValidator"
    16  
    17  type (
    18  	// FakePaymentSelectionValidator returns an error if the Cookie FakePaymentSelectionValidatorCookie is set
    19  	FakePaymentSelectionValidator struct{}
    20  )
    21  
    22  // Validate is only a fake implementation which is controlled by the Cookie FakePaymentSelectionValidatorCookie.
    23  // Always returns an error if the cookie is set
    24  func (f FakePaymentSelectionValidator) Validate(ctx context.Context, _ *decorator.DecoratedCart, _ cart.PaymentSelection) error {
    25  	r := web.RequestFromContext(ctx)
    26  	_, err := r.Request().Cookie(FakePaymentSelectionValidatorCookie)
    27  	if errors.Is(err, http.ErrNoCookie) {
    28  		return nil
    29  	}
    30  
    31  	return errors.New("fake payment selection validator error")
    32  }