func TestTestTestimonials(t *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { t.Log(err) } Convey("Testimonials", t, func() { var test testimonials.Testimonial var tests testimonials.Testimonials qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) test.BrandID = dtx.BrandID test.Content = "test content - controller test" response := httprunner.ParameterizedJsonRequest("POST", "/testimonials", "/testimonials", &qs, test, Save) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &test), ShouldEqual, nil) test.FirstName = "test name" response = httprunner.ParameterizedJsonRequest("PUT", "/testimonials", "/testimonials", &qs, test, Save) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &test), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/testimonials/:id", "/testimonials/"+strconv.Itoa(test.ID), &qs, nil, GetTestimonial) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &test), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/testimonials", "/testimonials", &qs, nil, GetAllTestimonials) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &tests), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/testimonials/:id", "/testimonials/"+strconv.Itoa(test.ID), &qs, nil, Delete) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &test), ShouldEqual, nil) }) _ = apicontextmock.DeMock(dtx) }
func TestTechSupport(te *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { te.Log(err) } Convey("TechSupport", te, func() { var t techSupport.TechSupport var ts []techSupport.TechSupport qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) t.Contact.LastName = "test contact" t.Contact.FirstName = "test contact first" t.Contact.Email = "*****@*****.**" t.Contact.Type = "test" t.Contact.Subject = "test" t.Contact.Message = "test" t.Contact.Brand.ID = dtx.BrandID t.BrandID = dtx.BrandID err = t.Contact.Add(dtx) So(err, ShouldBeNil) response := httprunner.ParameterizedJsonRequest("POST", "/techSupport/:contactReceiverTypeID/:sendEmail", "/techSupport/1/false", &qs, t, CreateTechSupport) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &t), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/techSupport/:id", "/techSupport/"+strconv.Itoa(t.ID), &qs, nil, GetTechSupport) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &t), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/techSupport/contact/:id", "/techSupport/contact/"+strconv.Itoa(t.Contact.ID), &qs, nil, GetTechSupportByContact) te.Log(response.Body) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &ts), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/techSupport", "/techSupport", &qs, nil, GetAllTechSupport) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &ts), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/techSupport/:id", "/techSupport/"+strconv.Itoa(t.ID), &qs, nil, DeleteTechSupport) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &t), ShouldEqual, nil) err = t.Contact.Delete() So(err, ShouldBeNil) }) _ = apicontextmock.DeMock(dtx) }
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 TestSite(t *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { t.Log(err) } Convey("Site Contents", t, func() { var c site.Content var contents site.Contents var cr site.ContentRevision c.WebsiteId = dtx.WebsiteID qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) c.Title = "test content - controller test" cr.Text = "test revision - controller test" c.ContentRevisions = append(c.ContentRevisions, cr) response := httprunner.ParameterizedJsonRequest("POST", "/site/content", "/site/content", &qs, c, SaveContent) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &c), ShouldEqual, nil) c.Active = true response = httprunner.ParameterizedJsonRequest("PUT", "/site/content/:id", "/site/content/"+strconv.Itoa(c.Id), &qs, c, SaveContent) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &c), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/content/:id", "/site/content/"+strconv.Itoa(c.Id), &qs, nil, GetContent) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &c), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/content", "/site/content", &qs, nil, GetAllContents) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &contents), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/content/:id/revisions", "/site/content/"+strconv.Itoa(c.Id)+"/revisions", &qs, nil, GetContentRevisions) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &c), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/site/content/:id", "/site/content/"+strconv.Itoa(c.Id), &qs, nil, DeleteContent) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &c), ShouldEqual, nil) }) Convey("Site Menu", t, func() { var m site.Menu var menus site.Menus m.WebsiteId = dtx.WebsiteID qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) m.Name = "test menu - controller test" response := httprunner.ParameterizedJsonRequest("POST", "/site/menu", "/site/menu", &qs, m, SaveMenu) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &m), ShouldEqual, nil) m.Active = true response = httprunner.ParameterizedJsonRequest("PUT", "/site/menu/:id", "/site/menu/"+strconv.Itoa(m.Id), &qs, m, SaveMenu) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &m), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/menu/:id", "/site/menu/"+strconv.Itoa(m.Id), &qs, nil, GetMenu) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &m), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/menu", "/site/menu", &qs, nil, GetAllMenus) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &menus), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/menu/contents/:id", "/site/menu/contents/"+strconv.Itoa(m.Id), &qs, nil, GetMenuWithContents) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &m), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/site/menu/:id", "/site/menu/"+strconv.Itoa(m.Id), &qs, nil, DeleteMenu) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &m), ShouldEqual, nil) }) Convey("Site Menu", t, func() { var s site.Website qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) s.Description = "test site - controller test" response := httprunner.ParameterizedJsonRequest("POST", "/site", "/site", &qs, s, SaveSite) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &s), ShouldEqual, nil) s.Url = "www.controllertest.com" response = httprunner.ParameterizedJsonRequest("PUT", "/site/:id", "/site/"+strconv.Itoa(s.ID), &qs, s, SaveSite) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &s), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/site/:id/details", "/site/"+strconv.Itoa(s.ID)+"/details", &qs, nil, GetSiteDetails) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &s), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/site/:id", "/site/"+strconv.Itoa(s.ID), &qs, nil, DeleteSite) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &s), ShouldEqual, nil) }) _ = apicontextmock.DeMock(dtx) }
func TestVehicles(t *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { t.Log(err) } Convey("Vehicls", t, func() { var l products.Lookup ti := time.Now().Second() rand.Seed(int64(ti)) //get all qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) response := httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) if len(l.Years) < 1 { return } //year qs.Add("year", strconv.Itoa(l.Years[rand.Intn(len(l.Years))])) response = httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) if len(l.Makes) < 1 { return } //make qs.Add("make", l.Makes[rand.Intn(len(l.Makes))]) response = httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) if len(l.Models) < 1 { return } //model qs.Add("model", l.Models[rand.Intn(len(l.Models))]) response = httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) if len(l.Submodels) < 1 { So(len(l.Parts), ShouldBeGreaterThan, 0) return } t.Log(l.Vehicle, len(l.Parts)) //submodel qs.Add("submodel", l.Submodels[rand.Intn(len(l.Submodels))]) response = httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) if len(l.Configurations) < 1 { So(len(l.Parts), ShouldBeGreaterThan, 0) return } //configs for _, v := range l.Configurations { qs.Add(v.Type, v.Options[rand.Intn(len(v.Options))]) } response = httprunner.ParameterizedJsonRequest("POST", "/vehicle", "/vehicle", &qs, &qs, Query) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) So(len(l.Parts), ShouldBeGreaterThanOrEqualTo, 0) }) _ = apicontextmock.DeMock(dtx) }
func TestWebProperty(t *testing.T) { dtx, err := apicontextmock.Mock() if err != nil { t.Log(err) } Convey("Test Web Property", t, func() { var wt webProperty_model.WebPropertyType var wr webProperty_model.WebPropertyRequirement var wn webProperty_model.WebPropertyNote var w webProperty_model.WebProperty var ws webProperty_model.WebProperties var wts []webProperty_model.WebPropertyType var wrs []webProperty_model.WebPropertyRequirement var wns []webProperty_model.WebPropertyNote qs := make(url.Values, 0) qs.Add("key", dtx.APIKey) w.CustID = dtx.CustomerID wt.Type = "controller test type" w.Name = "controller test name" wr.Compliance = true wn.Text = "controller test text" //POST response := httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/type", "/webProperties/json/type", &qs, wt, CreateUpdateWebPropertyType) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wt), ShouldEqual, nil) wt.Type = "999" response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/type/:id", "/webProperties/json/type/"+strconv.Itoa(wt.ID), &qs, wt, CreateUpdateWebPropertyType) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wt), ShouldEqual, nil) w.WebPropertyType = wt response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/requirement", "/webProperties/json/requirement", &qs, wr, CreateUpdateWebPropertyRequirement) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wr), ShouldEqual, nil) response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/requirement/:id", "/webProperties/json/requirement/"+strconv.Itoa(wr.RequirementID), &qs, wr, CreateUpdateWebPropertyRequirement) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wr), ShouldEqual, nil) w.WebPropertyRequirements = append(w.WebPropertyRequirements, wr) response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/note", "/webProperties/json/note", &qs, wn, CreateUpdateWebPropertyNote) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wn), ShouldEqual, nil) response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/note/:id", "/webProperties/json/note/"+strconv.Itoa(wn.ID), &qs, wn, CreateUpdateWebPropertyNote) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wn), ShouldEqual, nil) w.WebPropertyNotes = append(w.WebPropertyNotes, wn) response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json", "/webProperties/json", &qs, w, CreateUpdateWebProperty) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &w), ShouldEqual, nil) response = httprunner.ParameterizedJsonRequest("POST", "/webProperties/json/:id", "/webProperties/json/"+strconv.Itoa(w.ID), &qs, w, CreateUpdateWebProperty) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &w), ShouldEqual, nil) //GET response = httprunner.ParameterizedRequest("GET", "/webProperties/:id", "/webProperties/"+strconv.Itoa(w.ID), &qs, nil, Get) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &w), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/webProperties", "/webProperties", &qs, nil, GetAll) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &ws), ShouldEqual, nil) So(len(ws), ShouldBeGreaterThan, 0) response = httprunner.ParameterizedRequest("GET", "/webProperties/type/:id", "/webProperties/type/"+strconv.Itoa(wt.ID), &qs, nil, GetWebPropertyType) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wt), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/webProperties/type", "/webProperties/type/", &qs, nil, GetAllTypes) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wts), ShouldEqual, nil) So(len(wts), ShouldBeGreaterThan, 0) response = httprunner.ParameterizedRequest("GET", "/webProperties/requirement/:id", "/webProperties/requirement/"+strconv.Itoa(wr.RequirementID), &qs, nil, GetWebPropertyRequirement) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wr), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/webProperties/requirement", "/webProperties/requirement", &qs, nil, GetAllRequirements) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wrs), ShouldEqual, nil) So(len(wrs), ShouldBeGreaterThan, 0) response = httprunner.ParameterizedRequest("GET", "/webProperties/note/:id", "/webProperties/note/"+strconv.Itoa(wn.ID), &qs, nil, GetWebPropertyNote) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wn), ShouldEqual, nil) response = httprunner.ParameterizedRequest("GET", "/webProperties/note", "/webProperties/note/", &qs, nil, GetAllNotes) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wns), ShouldEqual, nil) So(len(wns), ShouldBeGreaterThan, 0) qs.Add("name", "controller test name") response = httprunner.ParameterizedRequest("GET", "/webProperties/search", "/webProperties/search/", &qs, nil, Search) So(response.Code, ShouldEqual, 200) var l interface{} So(json.Unmarshal(response.Body.Bytes(), &l), ShouldEqual, nil) //DELETE response = httprunner.ParameterizedRequest("DELETE", "/webProperties/requirement/:id", "/webProperties/requirement/"+strconv.Itoa(wr.RequirementID), &qs, nil, DeleteWebPropertyRequirement) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wr), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/webProperties/note/:id", "/webProperties/note/"+strconv.Itoa(wn.ID), &qs, nil, DeleteWebPropertyNote) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wn), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/webProperties/:id", "/webProperties/"+strconv.Itoa(w.ID), &qs, nil, DeleteWebProperty) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &w), ShouldEqual, nil) response = httprunner.ParameterizedRequest("DELETE", "/webProperties/type/:id", "/webProperties/type/"+strconv.Itoa(wt.ID), &qs, nil, DeleteWebPropertyType) So(response.Code, ShouldEqual, 200) So(json.Unmarshal(response.Body.Bytes(), &wt), ShouldEqual, nil) }) _ = apicontextmock.DeMock(dtx) }