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 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) }) }
func TestSearch(t *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { t.Log(err) } qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) Convey("Testing Search with empty term", t, func() { response = httprunner.Req(Search, "GET", "/search", "/search", &qs) So(response.Code, ShouldEqual, 500) So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil) }) Convey("Testing Search with `Hitch`", t, func() { response = httprunner.Req(Search, "GET", "/search/:term", "/search/Hitch", &qs) So(response.Code, ShouldEqual, 200) }) }