Skip to content

Commit

Permalink
cart: adjust response type of update delivery shipping options mutati…
Browse files Browse the repository at this point in the history
…on (#318)
  • Loading branch information
Stanislav authored May 26, 2021
1 parent c0894fd commit 4e78182
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 80 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Add new type `Commerce_Cart_CustomAttributes` with method for getting key/value pairs
* **Breaking**: Make naming convention consistent in graphql schema `Commerce_Cart_*`
* **Breaking**: Remove the fields `getAdditionalData, additionalDataKeys, additionalDeliveryInfoKeys` from the `Commerce_CartDeliveryInfo` type
* **Breaking**: `Commerce_Cart_UpdateDeliveryShippingOptions` mutation responded with slice of `Commerce_Cart_DeliveryAddressForm` which was incorrect as we don't process any form data within the mutation. It responds now rightly only with `processed` state.

**checkout**
* Introducing Flamingo events on final states of the place order process
Expand Down
9 changes: 6 additions & 3 deletions cart/interfaces/graphql/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ type (

// SelectedPaymentResult represents the selected payment
SelectedPaymentResult struct {
//Processed
Processed bool
//ValidationInfo
Processed bool
ValidationInfo ValidationInfo
}

// UpdateShippingOptionsResult definition
UpdateShippingOptionsResult struct {
Processed bool
}
)
23 changes: 3 additions & 20 deletions cart/interfaces/graphql/mutationresolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,32 +199,17 @@ func (r *CommerceCartMutationResolver) CommerceCartUpdateDeliveryAddresses(ctx c
}

// CommerceCartUpdateDeliveryShippingOptions updates the method/carrier of one or multiple existing deliveries
func (r *CommerceCartMutationResolver) CommerceCartUpdateDeliveryShippingOptions(ctx context.Context, shippingOptions []*dto.DeliveryShippingOption) ([]*dto.DeliveryAddressForm, error) {
result := make([]*dto.DeliveryAddressForm, 0, len(shippingOptions))

func (r *CommerceCartMutationResolver) CommerceCartUpdateDeliveryShippingOptions(ctx context.Context, shippingOptions []*dto.DeliveryShippingOption) (*dto.UpdateShippingOptionsResult, error) {
session := web.SessionFromContext(ctx)
cart, err := r.cartReceiverService.ViewCart(ctx, session)
if err != nil {
return nil, err
}

for _, shippingOption := range shippingOptions {
formResult := dto.DeliveryAddressForm{
Processed: false,
DeliveryCode: shippingOption.DeliveryCode,
Method: shippingOption.Method,
Carrier: shippingOption.Carrier,
}

delivery, found := cart.GetDeliveryByCode(shippingOption.DeliveryCode)
if !found {
formResult.ValidationInfo.GeneralErrors = []domain.Error{
{
MessageKey: "delivery_not_found",
},
}
result = append(result, &formResult)
continue
return nil, cartDomain.ErrDeliveryCodeNotFound
}

deliveryInfo := delivery.DeliveryInfo
Expand All @@ -235,11 +220,9 @@ func (r *CommerceCartMutationResolver) CommerceCartUpdateDeliveryShippingOptions
if err != nil {
return nil, err
}
formResult.Processed = true
result = append(result, &formResult)
}

return result, nil
return &dto.UpdateShippingOptionsResult{Processed: true}, nil
}

// CartClean clears users cart
Expand Down
2 changes: 1 addition & 1 deletion cart/interfaces/graphql/schema.go

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion cart/interfaces/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ type Commerce_Cart_DeliveryAddressForm {
processed: Boolean
}

type Commerce_Cart_UpdateDeliveryShippingOptions_Result {
"Shows if the request was successfully processed"
processed: Boolean
}

input Commerce_Cart_DeliveryShippingOptionInput {
"Unique delivery code to identify an **existing** delivery"
deliveryCode: String!
Expand Down Expand Up @@ -475,7 +480,7 @@ extend type Mutation {
"Adds/Updates one/multiple Delivery Addresses"
Commerce_Cart_UpdateDeliveryAddresses(deliveryAdresses: [Commerce_Cart_DeliveryAddressInput!]): [Commerce_Cart_DeliveryAddressForm]!
"Adds/Updates one/multiple Delivery Addresses"
Commerce_Cart_UpdateDeliveryShippingOptions(shippingOptions: [Commerce_Cart_DeliveryShippingOptionInput!]): [Commerce_Cart_DeliveryAddressForm]!
Commerce_Cart_UpdateDeliveryShippingOptions(shippingOptions: [Commerce_Cart_DeliveryShippingOptionInput!]): Commerce_Cart_UpdateDeliveryShippingOptions_Result!
"Cleans current cart"
Commerce_Cart_Clean: Boolean!
"Adds/Updates additional data for the cart"
Expand Down
2 changes: 2 additions & 0 deletions cart/interfaces/graphql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func (*Service) Types(types *graphql.Types) {
types.Resolve("Commerce_Cart_DefaultPaymentSelection", "cartSplit", CommerceCartQueryResolver{}, "CartSplit")
types.Map("Commerce_Cart_DeliveryAddressForm", dto.DeliveryAddressForm{})
types.Map("Commerce_Cart_DeliveryAddressInput", forms.DeliveryForm{})
types.Map("Commerce_Cart_UpdateDeliveryShippingOptions_Result", dto.UpdateShippingOptionsResult{})

types.GoField("Commerce_Cart_DeliveryAddressInput", "deliveryCode", "LocationCode")
types.GoField("Commerce_Cart_DeliveryAddressInput", "carrier", "ShippingCarrier")
types.GoField("Commerce_Cart_DeliveryAddressInput", "method", "ShippingMethod")
Expand Down
90 changes: 86 additions & 4 deletions test/integrationtest/projecttest/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/integrationtest/projecttest/graphql/resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ type Commerce_Cart_DeliveryAddressForm {
processed: Boolean
}

type Commerce_Cart_UpdateDeliveryShippingOptions_Result {
"Shows if the request was successfully processed"
processed: Boolean
}

input Commerce_Cart_DeliveryShippingOptionInput {
"Unique delivery code to identify an **existing** delivery"
deliveryCode: String!
Expand Down Expand Up @@ -475,7 +480,7 @@ extend type Mutation {
"Adds/Updates one/multiple Delivery Addresses"
Commerce_Cart_UpdateDeliveryAddresses(deliveryAdresses: [Commerce_Cart_DeliveryAddressInput!]): [Commerce_Cart_DeliveryAddressForm]!
"Adds/Updates one/multiple Delivery Addresses"
Commerce_Cart_UpdateDeliveryShippingOptions(shippingOptions: [Commerce_Cart_DeliveryShippingOptionInput!]): [Commerce_Cart_DeliveryAddressForm]!
Commerce_Cart_UpdateDeliveryShippingOptions(shippingOptions: [Commerce_Cart_DeliveryShippingOptionInput!]): Commerce_Cart_UpdateDeliveryShippingOptions_Result!
"Cleans current cart"
Commerce_Cart_Clean: Boolean!
"Adds/Updates additional data for the cart"
Expand Down
30 changes: 1 addition & 29 deletions test/integrationtest/projecttest/tests/graphql/cart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,7 @@ func Test_CommerceCartUpdateDeliveryShippingOptions(t *testing.T) {
// update shipping options
response = helper.GraphQlRequest(t, e, loadGraphQL(t, "update_delivery_shipping_options", nil)).Expect()
response.Status(http.StatusOK)
forms = getArray(response, "Commerce_Cart_UpdateDeliveryShippingOptions")
forms.Length().Equal(3)

address := forms.Element(0).Object()
address.Value("deliveryCode").String().Equal("foo")
address.Value("carrier").String().Equal("foo-carrier")
address.Value("method").String().Equal("foo-method")
address.Value("processed").Boolean().Equal(true)
validation := address.Value("validationInfo").Object()
validation.Value("generalErrors").Null()
validation.Value("fieldErrors").Null()

address = forms.Element(1).Object()
address.Value("deliveryCode").Equal("bar")
address.Value("carrier").String().Equal("bar-carrier")
address.Value("method").String().Equal("bar-method")
address.Value("processed").Boolean().Equal(true)
validation = address.Value("validationInfo").Object()
validation.Value("generalErrors").Null()
validation.Value("fieldErrors").Null()

address = forms.Element(2).Object()
address.Value("deliveryCode").Equal("non-existing")
address.Value("carrier").String().Equal("bar")
address.Value("method").String().Equal("foo")
address.Value("processed").Boolean().Equal(false)
validation = address.Value("validationInfo").Object()
validation.Value("generalErrors").NotNull()
validation.Value("fieldErrors").Null()
getValue(response, "Commerce_Cart_UpdateDeliveryShippingOptions", "processed").Boolean().Equal(true)

// check cart
response = helper.GraphQlRequest(t, e, loadGraphQL(t, "cart_decorated_cart", nil)).Expect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,8 @@ mutation {
method: "bar-method"
carrier: "bar-carrier"
}
{
deliveryCode: "non-existing"
method: "foo"
carrier: "bar"
}
]
) {
deliveryCode
carrier
method
processed
validationInfo {
fieldErrors {
messageKey
defaultLabel
fieldName
}
generalErrors {
messageKey
defaultLabel
}
}
}
}

0 comments on commit 4e78182

Please sign in to comment.