flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/tests/graphql/cartvalidator_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package graphql_test 5 6 import ( 7 "net/http" 8 "testing" 9 10 "flamingo.me/flamingo-commerce/v3/test/integrationtest" 11 "flamingo.me/flamingo-commerce/v3/test/integrationtest/projecttest/helper" 12 ) 13 14 // In Commerce, the secondary port of `Validator` from cart/domain/validation/cartValidator.go 15 // is not implemented. So the query will always return an empty result. 16 // This test checks just if the query works 17 func Test_CartValidator(t *testing.T) { 18 baseURL := "http://" + FlamingoURL 19 e := integrationtest.NewHTTPExpect(t, baseURL) 20 21 prepareCart(t, e) 22 23 response := helper.GraphQlRequest(t, e, loadGraphQL(t, "validate_cart", nil)).Expect() 24 response.Status(http.StatusOK) 25 getValue(response, "Commerce_Cart_Validator", "hasCommonError").Boolean().IsFalse() 26 } 27 28 // This test checks if qty Restrictions work 29 func Test_CartRestrictor(t *testing.T) { 30 baseURL := "http://" + FlamingoURL 31 e := integrationtest.NewHTTPExpect(t, baseURL) 32 33 t.Run("restricted product", func(t *testing.T) { 34 response := helper.GraphQlRequest(t, e, loadGraphQL(t, "validate_restrictor", map[string]string{"MARKETPLACE_CODE": "fake_simple"})).Expect() 35 response.Status(http.StatusOK) 36 getValue(response, "Commerce_Cart_QtyRestriction", "isRestricted").Boolean().IsTrue() 37 }) 38 39 t.Run("unrestricted product", func(t *testing.T) { 40 response := helper.GraphQlRequest(t, e, loadGraphQL(t, "validate_restrictor", map[string]string{"MARKETPLACE_CODE": "fake_configurable"})).Expect() 41 response.Status(http.StatusOK) 42 getValue(response, "Commerce_Cart_QtyRestriction", "isRestricted").Boolean().IsFalse() 43 }) 44 45 t.Run("404 product", func(t *testing.T) { 46 response := helper.GraphQlRequest(t, e, loadGraphQL(t, "validate_restrictor", map[string]string{"MARKETPLACE_CODE": "some"})).Expect() 47 response.Status(http.StatusOK) 48 response.JSON().Object().Value("errors").NotNull() 49 }) 50 51 }