flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/tests/graphql/customer_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  	"github.com/gavv/httpexpect/v2"
    11  
    12  	"flamingo.me/flamingo-commerce/v3/test/integrationtest"
    13  	"flamingo.me/flamingo-commerce/v3/test/integrationtest/projecttest/helper"
    14  )
    15  
    16  func Test_CommerceCustomerStatus(t *testing.T) {
    17  	t.Parallel()
    18  	baseURL := "http://" + FlamingoURL
    19  	type expected struct {
    20  		status bool
    21  		userID string
    22  	}
    23  	tests := []struct {
    24  		name         string
    25  		performLogin bool
    26  		expected     expected
    27  	}{
    28  		{
    29  			name:         "not logged in",
    30  			performLogin: false,
    31  			expected: expected{
    32  				status: false,
    33  				userID: "",
    34  			},
    35  		},
    36  		{
    37  			name:         "logged in",
    38  			performLogin: true,
    39  			expected: expected{
    40  				status: true,
    41  				userID: "username",
    42  			},
    43  		},
    44  	}
    45  
    46  	for _, tt := range tests {
    47  		t.Run(tt.name, func(t *testing.T) {
    48  			e := integrationtest.NewHTTPExpect(t, baseURL)
    49  			if tt.performLogin {
    50  				loginTestCustomer(t, e)
    51  			}
    52  
    53  			resp := helper.GraphQlRequest(t, e, loadGraphQL(t, "customer_status", nil)).Expect()
    54  			resp.Status(http.StatusOK)
    55  			getValue(resp, "Commerce_Customer_Status", "isLoggedIn").Boolean().IsEqual(tt.expected.status)
    56  			getValue(resp, "Commerce_Customer_Status", "userID").String().IsEqual(tt.expected.userID)
    57  		})
    58  	}
    59  }
    60  
    61  func Test_CommerceCustomer(t *testing.T) {
    62  	t.Parallel()
    63  	baseURL := "http://" + FlamingoURL
    64  
    65  	tests := []struct {
    66  		name         string
    67  		performLogin bool
    68  		validator    func(t *testing.T, response *httpexpect.Response)
    69  	}{
    70  		{
    71  			name:         "not logged in",
    72  			performLogin: false,
    73  			validator: func(t *testing.T, response *httpexpect.Response) {
    74  				response.JSON().Object().Value("data").Object().Value("Commerce_Customer").IsNull()
    75  			},
    76  		},
    77  		{
    78  			name:         "logged in",
    79  			performLogin: true,
    80  			validator: func(t *testing.T, response *httpexpect.Response) {
    81  				getValue(response, "Commerce_Customer", "id").IsEqual("username")
    82  				personalData := getValue(response, "Commerce_Customer", "personalData").Object()
    83  				personalData.Value("firstName").IsEqual("Flamingo")
    84  				personalData.Value("lastName").IsEqual("Commerce")
    85  				personalData.Value("birthday").IsEqual("2019-04-02")
    86  			},
    87  		},
    88  	}
    89  
    90  	for _, tt := range tests {
    91  		t.Run(tt.name, func(t *testing.T) {
    92  			e := integrationtest.NewHTTPExpect(t, baseURL)
    93  			if tt.performLogin {
    94  				loginTestCustomer(t, e)
    95  			}
    96  
    97  			resp := helper.GraphQlRequest(t, e, loadGraphQL(t, "customer", nil)).Expect()
    98  			resp.Status(http.StatusOK)
    99  			tt.validator(t, resp)
   100  		})
   101  	}
   102  }