flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/tests/restapi/placeorder_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package restapi_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"flamingo.me/flamingo-commerce/v3/checkout/application/placeorder"
    10  	"flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/states"
    11  	"flamingo.me/flamingo-commerce/v3/test/integrationtest"
    12  )
    13  
    14  func Test_Checkout_SimplePlaceOrderProcess(t *testing.T) {
    15  
    16  	e := integrationtest.NewHTTPExpect(t, "http://"+FlamingoURL)
    17  	// add something to the cart
    18  	response := e.POST("/api/v1/cart/delivery/delivery/item").WithQuery("deliveryCode", "delivery").WithQuery("marketplaceCode", "fake_simple").Expect()
    19  	response.Status(200).JSON().Object().Value("Success").Boolean().IsEqual(true)
    20  
    21  	// add billing
    22  	response = e.PUT("/api/v1/cart/billing").WithFormField("firstname", "Max").WithFormField("lastname", "Mustermann").WithFormField("email", "test@test.de").Expect()
    23  	response.Status(200).JSON().Object().Value("Success").Boolean().IsEqual(true)
    24  
    25  	// add shipping
    26  	response = e.PUT("/api/v1/cart/delivery/delivery/").WithFormField("deliveryAddress.firstname", "Max").WithFormField("deliveryAddress.lastname", "Mustermann").WithFormField("deliveryAddress.email", "test@test.de").Expect()
    27  	response.Status(200).JSON().Object().Value("Success").Boolean().IsEqual(true)
    28  
    29  	// add payment selection
    30  	response = e.PUT("/api/v1/cart/payment-selection").WithQuery("gateway", "fake_payment_gateway").WithQuery("method", "payment_waiting_for_customer").Expect()
    31  	response.Status(200).JSON().Object().Value("Success").Boolean().IsEqual(true)
    32  
    33  	// start place order
    34  	response = e.PUT("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    35  	response.Status(201).JSON().Object().Value("UUID").String().NotEmpty()
    36  	uuid := response.Status(201).JSON().Object().Value("UUID").String().Raw()
    37  
    38  	// get last place order context
    39  	response = e.GET("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    40  	response.Status(200).JSON().Object().Value("UUID").String().IsEqual(uuid)
    41  
    42  	// cancel place order
    43  	response = e.POST("/api/v1/checkout/placeorder/cancel").Expect()
    44  	response.Status(200).Body().IsEqual("true\n")
    45  
    46  	// get last place order context
    47  	response = e.GET("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    48  	response.Status(200).JSON().Object().Value("State").String().IsEqual("Failed")
    49  
    50  	// clear last place order context
    51  	response = e.DELETE("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    52  	response.Status(200).Body().IsEqual("true\n")
    53  
    54  	// get last place order context
    55  	response = e.GET("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    56  	response.Status(500).JSON().Object().Value("Message").String().IsEqual(placeorder.ErrNoPlaceOrderProcess.Error())
    57  
    58  	// set payment selection to a working one
    59  	response = e.PUT("/api/v1/cart/payment-selection").WithQuery("gateway", "fake_payment_gateway").WithQuery("method", "payment_completed").Expect()
    60  	response.Status(200).JSON().Object().Value("Success").Boolean().IsEqual(true)
    61  
    62  	// start place order again
    63  	response = e.PUT("/api/v1/checkout/placeorder").WithQuery("returnURL", "http://www.example.org").Expect()
    64  	response.Status(201).JSON().Object().Value("UUID").String().NotEmpty()
    65  
    66  	// refresh place order
    67  	response = e.POST("/api/v1/checkout/placeorder/refresh").Expect()
    68  	response.Status(200).JSON().Object().Value("State").String().NotEmpty()
    69  	response = e.POST("/api/v1/checkout/placeorder/refresh-blocking").Expect()
    70  	response.Status(200).JSON().Object().Value("State").String().NotEmpty()
    71  
    72  	// get last place order context
    73  	response = e.GET("/api/v1/checkout/placeorder").Expect()
    74  	response.Status(200).JSON().Object().Value("FailedReason").String().IsEqual("")
    75  	response.Status(200).JSON().Object().Value("State").String().IsEqual(states.Success{}.Name())
    76  }