func Test_AccountLogin(t *testing.T) { Convey("with shop identifier", t, func() { shopID := cart.InsertTestData() So(shopID, ShouldNotBeNil) val := shopID.Hex() qs := make(url.Values, 0) qs.Add("shop", val) cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", } cust.Password = "******" response = httprunner.JsonRequest("POST", "/shopify/account", &qs, cust, AddAccount) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) cust.Password = "" response = httprunner.Req(AccountLogin, "POST", "", "/shopify/account/login", &qs, nil, cust) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) cust.Password = "******" response = httprunner.Req(AccountLogin, "POST", "", "/shopify/account/login", &qs, nil, cust) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) }) }
func BenchmarkGetCustomerAddresses(b *testing.B) { shopID := cart.InsertTestData() if shopID == nil { b.Error("failed to create a shop") b.Fail() } val := shopID.Hex() qs := make(url.Values, 0) qs.Add("shop", val) cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", Password: "******", } if err := cust.Insert("http://www.example.com"); err != nil { b.Error(err.Error()) b.Fail() } (&httprunner.BenchmarkOptions{ Method: "GET", Route: "/shopify/customers/" + cust.Id.Hex() + "/addresses", ParameterizedRoute: "/shopify/customers/:id/addresses", Handler: GetAddresses, QueryString: &qs, Runs: b.N, }).RequestBenchmark() }
func Test_SetDefaultAddress(t *testing.T) { Convey("with shop identifier", t, func() { shopID := cart.InsertTestData() So(shopID, ShouldNotBeNil) qs := make(url.Values, 0) qs.Add("shop", shopID.Hex()) cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", Password: "******", } response = httprunner.JsonRequest("POST", "/shopify/customers", &qs, cust, AddCustomer) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) addr := cart.CustomerAddress{ Address1: "1119 Sunset Lane", City: "Altoona", Company: "AN & Co.", FirstName: "Alex", LastName: "Ninneman", Phone: "7153082604", Province: "Wisconsin", ProvinceCode: "WI", Country: "US", CountryCode: "US", CountryName: "United States", Zip: "54720", } response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, &addr, AddAddress) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &addr), ShouldBeNil) response = httprunner.ParameterizedJsonRequest("PUT", "/shopify/customers/:id/addresses/:address/default", "/shopify/customers/1234/addresses/1234/default", &qs, &addr, SetDefaultAddress) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) response = httprunner.ParameterizedJsonRequest("PUT", "/shopify/customers/:id/addresses/:address/default", "/shopify/customers/"+shopID.Hex()+"/addresses/1234/default", &qs, &cust, SetDefaultAddress) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) response = httprunner.ParameterizedJsonRequest("PUT", "/shopify/customers/:id/addresses/:address/default", "/shopify/customers/"+cust.Id.Hex()+"/addresses/1234/default", &qs, &cust, SetDefaultAddress) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) response = httprunner.ParameterizedJsonRequest("PUT", "/shopify/customers/:id/addresses/:address/default", "/shopify/customers/"+cust.Id.Hex()+"/addresses/"+cust.Id.Hex()+"/default", &qs, &cust, SetDefaultAddress) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) response = httprunner.ParameterizedJsonRequest("PUT", "/shopify/customers/:id/addresses/:address/default", "/shopify/customers/"+cust.Id.Hex()+"/addresses/"+addr.Id.Hex()+"/default", &qs, &addr, SetDefaultAddress) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &addr), ShouldBeNil) }) }
func Test_GetCustomerAddresses(t *testing.T) { Convey("no shop identifier", t, func() { response = httprunner.Request("GET", "/shopify/customers/1234/addresses", nil, GetAddresses) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) vals := make(url.Values, 0) vals.Add("shop", "testing") response = httprunner.Request("GET", "/shopify/customers/1234/addresses", nil, GetAddresses) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) }) Convey("with shop identifier", t, func() { shopID := cart.InsertTestData() So(shopID, ShouldNotBeNil) val := shopID.Hex() qs := make(url.Values, 0) qs.Add("shop", val) Convey("with bad customer reference", func() { response = httprunner.ParameterizedRequest("GET", "/shopify/customers/:id/addresses", "/shopify/customers/1234/addresses", &qs, nil, GetAddresses) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) }) Convey("with good customer reference", func() { cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", Password: "******", } response = httprunner.JsonRequest("POST", "/shopify/customers", &qs, cust, AddCustomer) t.Log(response.Body.String()) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) response = httprunner.ParameterizedRequest("GET", "/shopify/customers/:id/addresses", "/shopify/customers/"+shopID.Hex()+"/addresses", &qs, nil, GetAddresses) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) response = httprunner.ParameterizedRequest("GET", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, nil, GetAddresses) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &[]cart.CustomerAddress{}), ShouldBeNil) qs.Add("limit", "10") qs.Add("page", "1") response = httprunner.ParameterizedRequest("GET", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, nil, GetAddresses) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &[]cart.CustomerAddress{}), ShouldBeNil) }) }) }
func Test_EditAccount(t *testing.T) { Convey("with shop identifier", t, func() { shopID := cart.InsertTestData() So(shopID, ShouldNotBeNil) val := shopID.Hex() qs := make(url.Values, 0) qs.Add("shop", val) cust := cart.Customer{ ShopId: *shopID, FirstName: "Alex", LastName: "Ninneman", Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com", } cust.Password = "******" response = httprunner.JsonRequest("POST", "/shopify/account", &qs, cust, AddAccount) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) cust.Email = time.Now().Format(time.RFC3339Nano) + "@gmail.com" header := map[string]interface{}{ "Authorization": "Bearer as;ldskfja;lfdj", } response = httprunner.Req(EditAccount, "PUT", "", "/shopify/account", &qs, nil, cust, header) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) header = map[string]interface{}{ "Authorization": "Bearer " + cust.Token, } cust.FirstName = "" response = httprunner.Req(EditAccount, "PUT", "", "/shopify/account", &qs, nil, cust, header) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) cust.FirstName = "Alex" response = httprunner.Req(EditAccount, "PUT", "", "/shopify/account", &qs, nil, cust, header) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &cust), ShouldBeNil) }) }