Exemplo n.º 1
0
func TestFaqs(t *testing.T) {
	var f faq_model.Faq
	var err error
	dtx, err := apicontextmock.Mock()
	if err != nil {
		t.Log(err)
	}
	Convey("Test Faqs", t, func() {
		//test create
		form := url.Values{"question": {"test"}, "answer": {"testAnswer"}}
		v := form.Encode()
		body := strings.NewReader(v)
		testThatHttp.Request("post", "/faqs", "", "", Create, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
		So(f, ShouldHaveSameTypeAs, faq_model.Faq{})

		//test update
		form = url.Values{"question": {"test new"}, "answer": {"testAnswer new"}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.RequestWithDtx("put", "/faqs/", ":id", strconv.Itoa(f.ID), Update, body, "application/x-www-form-urlencoded", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
		So(f, ShouldHaveSameTypeAs, faq_model.Faq{})

		//test get
		testThatHttp.RequestWithDtx("get", "/faqs/", ":id", strconv.Itoa(f.ID), Get, nil, "application/x-www-form-urlencoded", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
		So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
		So(f.Question, ShouldEqual, "test new")

		//test getall
		testThatHttp.Request("get", "/faqs", "", "", GetAll, nil, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var fs faq_model.Faqs
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &fs)
		So(len(fs), ShouldBeGreaterThanOrEqualTo, 0)

		//test search - responds w/ horrid pagination object
		testThatHttp.Request("get", "/faqs/search", "", "?question=test new", Search, nil, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var l pagination.Objects
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &l)
		So(len(l.Objects), ShouldBeGreaterThanOrEqualTo, 0)

		//test delete
		testThatHttp.Request("delete", "/faqs/", ":id", strconv.Itoa(f.ID), Delete, nil, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
		So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
	})
	_ = apicontextmock.DeMock(dtx)
}
Exemplo n.º 2
0
func TestApplicationGuide(t *testing.T) {
	var a applicationGuide.ApplicationGuide
	var err error
	Convey("Testing ApplicationGuide", t, func() {
		//test create
		form := url.Values{"url": {"test"}, "fileType": {"pdf"}, "website_id": {"1"}}
		v := form.Encode()
		body := strings.NewReader(v)
		testThatHttp.Request("post", "/applicationGuide", "", "", CreateApplicationGuide, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &a)
		So(err, ShouldBeNil)
		So(a, ShouldHaveSameTypeAs, applicationGuide.ApplicationGuide{})

		//test create using json
		var jsonAppGuide applicationGuide.ApplicationGuide
		jsonAppGuide.Url = "www.www.com"
		jsonAppGuide.FileType = "pdf"
		jsonAppGuide.Website.ID = 1
		bodyBytes, _ := json.Marshal(jsonAppGuide)
		bodyJson := bytes.NewReader(bodyBytes)
		testThatHttp.Request("post", "/applicationGuide", "", "", CreateApplicationGuide, bodyJson, "application/json")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &jsonAppGuide)
		So(err, ShouldBeNil)
		So(jsonAppGuide, ShouldHaveSameTypeAs, applicationGuide.ApplicationGuide{})

		//test get
		testThatHttp.Request("get", "/applicationGuide/", ":id", strconv.Itoa(a.ID), GetApplicationGuide, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &a)
		So(err, ShouldBeNil)
		So(a, ShouldHaveSameTypeAs, applicationGuide.ApplicationGuide{})
		So(a.Url, ShouldEqual, "test")

		//test get by website
		testThatHttp.Request("get", "/applicationGuide/website/", ":id", strconv.Itoa(a.Website.ID), GetApplicationGuidesByWebsite, nil, "")
		var as []applicationGuide.ApplicationGuide
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &as)
		So(err, ShouldBeNil)
		So(len(as), ShouldBeGreaterThanOrEqualTo, 0)
		So(a.Url, ShouldEqual, "test")

		//test delete
		testThatHttp.Request("delete", "/applicationGuide/", ":id", strconv.Itoa(a.ID), DeleteApplicationGuide, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &a)
		So(err, ShouldBeNil)

		//cleanup
		err = jsonAppGuide.Delete()

	})
}
Exemplo n.º 3
0
func TestCustomerLocation(t *testing.T) {
	var err error
	var loc customer.CustomerLocation

	Convey("Testing customer/Location", t, func() {
		//test create customer location
		form := url.Values{"name": {"Dave Grohl"}, "address": {"404 S. Barstow St."}, "city": {"Eau Claire"}}
		v := form.Encode()
		body := strings.NewReader(v)
		thyme := time.Now()
		testThatHttp.Request("post", "/customer/location", "", "", SaveLocation, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &loc)
		So(err, ShouldBeNil)
		So(loc, ShouldHaveSameTypeAs, customer.CustomerLocation{})
		So(loc.Id, ShouldBeGreaterThan, 0)

		//test update location with json
		loc.Fax = "715-839-0000"
		bodyBytes, _ := json.Marshal(loc)
		bodyJson := bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("put", "/customer/location/", ":id", strconv.Itoa(loc.Id), SaveLocation, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &loc)
		So(err, ShouldBeNil)
		So(loc, ShouldHaveSameTypeAs, customer.CustomerLocation{})

		//test get location
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/location/", ":id", strconv.Itoa(loc.Id), GetLocation, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &loc)
		So(err, ShouldBeNil)
		So(loc, ShouldHaveSameTypeAs, customer.CustomerLocation{})

		//test delete location
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/location/", ":id", strconv.Itoa(loc.Id), DeleteLocation, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &loc)
		So(err, ShouldBeNil)
		So(loc, ShouldHaveSameTypeAs, customer.CustomerLocation{})

	})
}
Exemplo n.º 4
0
func TestGeography(t *testing.T) {
	var err error
	var s geography.States
	var c geography.Countries

	dtx, err := apicontextmock.Mock()
	if err != nil {
		t.Log(err)
	}

	Convey("Testing Geography", t, func() {
		//test get states
		thyme := time.Now()
		testThatHttp.Request("get", "/geography/states", "", "?key="+dtx.APIKey, GetAllStates, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &s)
		So(err, ShouldBeNil)
		So(s, ShouldHaveSameTypeAs, geography.States{})

		//test get countries
		thyme = time.Now()
		testThatHttp.Request("get", "/geography/countries", "", "?key="+dtx.APIKey, GetAllCountries, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, geography.Countries{})

		//test get countries and states
		thyme = time.Now()
		testThatHttp.Request("get", "/geography/countrystates", "", "?key="+dtx.APIKey, GetAllCountriesAndStates, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, geography.Countries{})

	})
	_ = apicontextmock.DeMock(dtx)
}
Exemplo n.º 5
0
func TestBlog(t *testing.T) {
	var b blog_model.Blog
	var bc blog_model.BlogCategory
	var err error
	dtx, err := apicontextmock.Mock()
	if err != nil {
		t.Log(err)
	}
	Convey("Testing Blog", t, func() {
		//test create blog cats
		form := url.Values{"name": {"test cat"}, "slug": {"a slug here"}}
		v := form.Encode()
		body := strings.NewReader(v)
		testThatHttp.Request("post", "/blogs/categories", "", "", CreateBlogCategory, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bc)
		So(err, ShouldBeNil)
		So(bc, ShouldHaveSameTypeAs, blog_model.BlogCategory{})

		//test create blog
		form = url.Values{"title": {"test"}, "slug": {"a slug"}, "texts": {"some text here"}, "categoryID": {strconv.Itoa(bc.ID)}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.RequestWithDtx("post", "/blogs", "", "", CreateBlog, body, "application/x-www-form-urlencoded", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)
		So(err, ShouldBeNil)
		So(b, ShouldHaveSameTypeAs, blog_model.Blog{})

		//test get blogs
		testThatHttp.Request("get", "/blog", "", "", GetAll, nil, "application/x-www-form-urlencoded")
		var bs blog_model.Blogs
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bs)
		So(len(bs), ShouldBeGreaterThanOrEqualTo, 0)
		So(err, ShouldBeNil)

		//test get blog
		testThatHttp.Request("get", "/blog/", ":id", strconv.Itoa(b.ID), GetBlog, nil, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)
		So(b, ShouldHaveSameTypeAs, blog_model.Blog{})
		So(err, ShouldBeNil)
		So(b.Title, ShouldEqual, "test")

		//test get blog cats
		testThatHttp.RequestWithDtx("get", "/blog/categories", "", "", GetAllCategories, nil, "application/x-www-form-urlencoded", dtx)
		var bcs blog_model.BlogCategories
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bcs)
		So(len(bcs), ShouldBeGreaterThanOrEqualTo, 0)
		So(err, ShouldBeNil)

		//test get blog cat
		testThatHttp.RequestWithDtx("get", "/blog/category/", ":id", strconv.Itoa(bc.ID), GetBlogCategory, nil, "application/x-www-form-urlencoded", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bc)
		So(bc, ShouldHaveSameTypeAs, blog_model.BlogCategory{})
		So(err, ShouldBeNil)

		//test search
		testThatHttp.RequestWithDtx("get", "/blog/search/", "", "?title="+b.Title, Search, nil, "application/x-www-form-urlencoded", dtx)
		var l pagination.Objects
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &l)
		So(len(l.Objects), ShouldBeGreaterThanOrEqualTo, 0)
		So(err, ShouldBeNil)

		//test update blog
		form = url.Values{"name": {"test cat"}, "slug": {"a slug here"}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("put", "/blogs/", ":id", strconv.Itoa(b.ID), UpdateBlog, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)
		So(err, ShouldBeNil)
		So(b, ShouldHaveSameTypeAs, blog_model.Blog{})

		//test delete blog cat
		testThatHttp.Request("delete", "/blog/categories/", ":id", strconv.Itoa(bc.ID), DeleteBlogCategory, nil, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bc)
		So(err, ShouldBeNil)

		//test delete blog
		testThatHttp.RequestWithDtx("delete", "/blog/", ":id", strconv.Itoa(b.ID), DeleteBlog, nil, "application/x-www-form-urlencoded", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)
		So(err, ShouldBeNil)

	})
	_ = apicontextmock.DeMock(dtx)
}
Exemplo n.º 6
0
func TestBrand(t *testing.T) {
	var b brand.Brand
	var err error
	Convey("Testing Brand", t, func() {
		//test create
		form := url.Values{"name": {"RonCo"}, "code": {"RONCO"}}
		v := form.Encode()
		body := strings.NewReader(v)

		thyme := time.Now()
		testThatHttp.Request("post", "/brand", "", "", CreateBrand, body, "application/x-www-form-urlencoded")
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)

		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(err, ShouldBeNil)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(b, ShouldHaveSameTypeAs, brand.Brand{})

		//test update
		form = url.Values{"code": {"RONCOandFriends"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("put", "/brand/", ":id", strconv.Itoa(b.ID), UpdateBrand, body, "application/x-www-form-urlencoded")
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)

		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(err, ShouldBeNil)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(b, ShouldHaveSameTypeAs, brand.Brand{})

		//test get
		thyme = time.Now()
		testThatHttp.Request("get", "/brand/", ":id", strconv.Itoa(b.ID), GetBrand, nil, "")
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)

		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(err, ShouldBeNil)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(b, ShouldHaveSameTypeAs, brand.Brand{})

		//test get all
		thyme = time.Now()
		testThatHttp.Request("get", "/brand", "", "", GetAllBrands, nil, "")
		var bs brand.Brands
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bs)

		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(err, ShouldBeNil)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(bs, ShouldHaveSameTypeAs, brand.Brands{})

		//test delete
		thyme = time.Now()
		testThatHttp.Request("delete", "/brand/", ":id", strconv.Itoa(b.ID), DeleteBrand, nil, "")
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &b)

		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(err, ShouldBeNil)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(b, ShouldHaveSameTypeAs, brand.Brand{})
	})
}
Exemplo n.º 7
0
func TestCustomerPrice(t *testing.T) {
	var err error
	var p customer.Price
	var ps customer.Prices
	var c customer.Customer
	c.Name = "Dog Bountyhunter"
	c.Create()

	Convey("Testing customer/Price", t, func() {
		//test create customer price
		form := url.Values{"custID": {strconv.Itoa(c.Id)}, "partID": {"11000"}, "price": {"123456"}}
		v := form.Encode()
		body := strings.NewReader(v)
		thyme := time.Now()
		testThatHttp.Request("post", "/customer/prices", "", "", CreateUpdatePrice, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, customer.Price{})
		So(p.ID, ShouldBeGreaterThan, 0)

		//test update customer price
		form = url.Values{"isSale": {"true"}, "saleStart": {"01/01/2001"}, "saleEnd": {"01/01/2015"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/prices/", ":id", strconv.Itoa(p.ID), CreateUpdatePrice, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, customer.Price{})
		So(p.IsSale, ShouldEqual, 1)
		start, _ := time.Parse(inputTimeFormat, "01/01/2001")
		So(p.SaleStart, ShouldResemble, start)

		//test get customer price
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/prices/", ":id", strconv.Itoa(p.ID), GetPrice, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, customer.Price{})

		//test get all customer price
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/prices", "", "", GetAllPrices, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*8) //Long
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ps)
		So(err, ShouldBeNil)
		So(ps, ShouldHaveSameTypeAs, customer.Prices{})

		//test get customer price by part
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/prices/part/", ":id", strconv.Itoa(p.ID), GetPricesByPart, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ps)
		So(err, ShouldBeNil)
		So(ps, ShouldHaveSameTypeAs, customer.Prices{})

		//test get customer price by customer
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/pricesByCustomer/", ":id", strconv.Itoa(c.Id), GetPriceByCustomer, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, customer.Price{})

		//test get sales
		form = url.Values{"id": {strconv.Itoa(c.Id)}, "start": {"01/01/2000"}, "end": {"01/01/2016"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/prices/sale", "", "", GetSales, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ps)
		So(err, ShouldBeNil)
		So(ps, ShouldHaveSameTypeAs, customer.Prices{})

		//test delete customer price
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/prices/", ":id", strconv.Itoa(p.ID), DeletePrice, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, customer.Price{})
	})
	//teardown
	c.Delete()
}
Exemplo n.º 8
0
func TestCustomer(t *testing.T) {
	var err error
	var c customer.Customer
	var cu customer.CustomerUser
	once.Do(initDtx)
	defer apicontextmock.DeMock(dtx)

	cu.Id = dtx.UserID
	err = cu.Get(dtx.APIKey)
	if err != nil {
		t.Log(err)
	}
	c.Users = append(c.Users, cu)

	Convey("Testing customer/Customer", t, func() {
		//test create customer
		c.Name = "Jason Voorhees"
		c.Email = "*****@*****.**"
		bodyBytes, _ := json.Marshal(c)
		bodyJson := bytes.NewReader(bodyBytes)
		thyme := time.Now()
		testThatHttp.Request("put", "/customer", "", "?key=", SaveCustomer, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})
		So(c.Id, ShouldBeGreaterThan, 0)

		//test update customer
		c.Fax = "666-1313"
		c.State.Id = 1
		bodyBytes, _ = json.Marshal(c)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("put", "/customer/", ":id", strconv.Itoa(c.Id)+"?key=", SaveCustomer, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})
		So(c.Id, ShouldBeGreaterThan, 0)

		thyme = time.Now()
		testThatHttp.RequestWithDtx("post", "/customer", "", "?key=", GetCustomer, nil, "", dtx)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})
		So(c.Id, ShouldBeGreaterThan, 0)

		// get customer locations
		thyme = time.Now()
		testThatHttp.RequestWithDtx("get", "/customer/locations", "", "?key=", GetLocations, nil, "", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*6)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c.Locations)
		So(err, ShouldBeNil)
		So(c.Locations, ShouldHaveSameTypeAs, []customer.CustomerLocation{})

		// //get user
		thyme = time.Now()
		testThatHttp.RequestWithDtx("post", "/customer/user", "", "?key="+dtx.APIKey, GetUser, nil, "", nil)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
		So(err, ShouldBeNil)
		So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})

		//get users
		thyme = time.Now()
		testThatHttp.RequestWithDtx("get", "/customer/users", "", "?key=", GetUsers, nil, "", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*5)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var cus []customer.CustomerUser
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cus)
		So(err, ShouldBeNil)
		So(cus, ShouldHaveSameTypeAs, []customer.CustomerUser{})

		// get customer price
		// price.CustID = c.Id
		// price.Create()
		// thyme = time.Now()
		// testThatHttp.Request("get", "/new/customer/price/", ":id", strconv.Itoa(p.ID)+"?key="+apiKey, GetCustomerPrice, nil, "")
		// So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		// So(testThatHttp.Response.Code, ShouldEqual, 200)
		// var price float64
		// err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
		// So(err, ShouldBeNil)
		// So(price, ShouldHaveSameTypeAs, 7.1)

		// //get customer cart reference
		// ci.CustID = c.Id
		// ci.Create()
		// thyme = time.Now()
		// testThatHttp.Request("get", "/new/customer/cartRef/", ":id", strconv.Itoa(p.ID)+"?key="+apiKey, GetCustomerCartReference, nil, "")
		// So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		// So(testThatHttp.Response.Code, ShouldEqual, 200)
		// var reference int
		// err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &reference)
		// So(err, ShouldBeNil)
		// So(reference, ShouldHaveSameTypeAs, 7)

		//test delete customer
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/", ":id", strconv.Itoa(c.Id)+"?key=", DeleteCustomer, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})
		So(c.Id, ShouldBeGreaterThan, 0)

	})
	//cleanup
	err = cu.Delete()
	err = c.Delete()

}
Exemplo n.º 9
0
func TestCustomerContent(t *testing.T) {
	flag.Parse()
	//customer - for db setup only
	var c customer.Customer
	var content custcontent.CustomerContent
	var partContent custcontent.PartContent
	var categoryContent custcontent.CustomerContent
	var ct custcontent.ContentType
	var crs custcontent.CustomerContentRevisions
	var contents []custcontent.CustomerContent
	var catContent custcontent.CategoryContent
	var catContents []custcontent.CategoryContent
	var err error
	var apiKey string

	catContent.CategoryId = 1

	ct.Type = "test"
	ct.Create()

	c.Name = "test cust"
	c.Create()

	Convey("Testing customer/Customer_content", t, func() {
		//test create part content
		content.Text = "new content"
		content.ContentType.Id = ct.Id
		bodyBytes, _ := json.Marshal(content)
		bodyJson := bytes.NewReader(bodyBytes)
		thyme := time.Now()
		testThatHttp.Request("post", "/customer/cms/part/", ":id", strconv.Itoa(11000)+"?key="+dtx.APIKey, CreatePartContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		if testThatHttp.Response.Code == 200 { //returns 500 when ninnemana user doesn't exist
			So(testThatHttp.Response.Code, ShouldEqual, 200)
			err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &content)
			So(err, ShouldBeNil)
			So(content, ShouldHaveSameTypeAs, custcontent.CustomerContent{})
		}

		//create category content
		categoryContent.Text = "new content"
		categoryContent.ContentType.Id = ct.Id
		bodyBytes, _ = json.Marshal(categoryContent)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/cms/category/", ":id", strconv.Itoa(catContent.CategoryId)+"?key="+apiKey, CreateCategoryContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &categoryContent)
		So(err, ShouldBeNil)
		So(categoryContent, ShouldHaveSameTypeAs, custcontent.CustomerContent{})

		//test update part content
		content.Text = "newerer content"
		bodyBytes, _ = json.Marshal(content)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("put", "/customer/cms/part/", ":id", strconv.Itoa(11000)+"?key="+apiKey, UpdatePartContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &content)
		So(err, ShouldBeNil)
		So(content, ShouldHaveSameTypeAs, custcontent.CustomerContent{})

		//test update category content
		categoryContent.Text = "newerer content"
		bodyBytes, _ = json.Marshal(categoryContent)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("put", "/customer/cms/part/", ":id", strconv.Itoa(catContent.CategoryId)+"?key="+apiKey, UpdateCategoryContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &categoryContent)
		So(err, ShouldBeNil)
		So(categoryContent, ShouldHaveSameTypeAs, custcontent.CustomerContent{})

		//test get part content (unique)
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/part/", ":id", strconv.Itoa(11000)+"?key="+apiKey, UniquePartContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &contents)
		So(err, ShouldBeNil)
		So(contents, ShouldHaveSameTypeAs, []custcontent.CustomerContent{})

		//test get all part content
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/part", "", "?key="+apiKey, AllPartContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &contents)
		So(err, ShouldBeNil)
		So(contents, ShouldHaveSameTypeAs, []custcontent.CustomerContent{})

		//test get category content (all content)
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/part", "", "?key="+apiKey, AllCategoryContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &contents)
		So(err, ShouldBeNil)
		So(contents, ShouldHaveSameTypeAs, []custcontent.CustomerContent{})

		//test get unique category content
		catContent.Content = append(catContent.Content, content) //setup some category Content
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/category/", ":id", strconv.Itoa(catContent.CategoryId)+"?key="+apiKey, UniqueCategoryContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &catContents)
		So(err, ShouldBeNil)
		So(catContents, ShouldHaveSameTypeAs, []custcontent.CategoryContent{})

		//test get all content
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms", "", "?key="+apiKey, GetAllContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &contents)
		So(err, ShouldBeNil)
		So(contents, ShouldHaveSameTypeAs, []custcontent.CustomerContent{})

		//test get content by id
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/", ":id", strconv.Itoa(content.Id)+"?key="+apiKey, GetContentById, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &content)
		So(err, ShouldBeNil)
		So(content, ShouldHaveSameTypeAs, custcontent.CustomerContent{})

		//test get content revisions by id
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/", ":id/revisions", strconv.Itoa(content.Id)+"/revisions?key="+apiKey, GetContentRevisionsById, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &crs)
		So(err, ShouldBeNil)
		So(crs, ShouldHaveSameTypeAs, custcontent.CustomerContentRevisions{})

		//test get all content types
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/cms/content_types", "", "?key="+apiKey, GetAllContentTypes, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var cts []custcontent.ContentType
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cts)
		So(err, ShouldBeNil)
		So(cts, ShouldHaveSameTypeAs, []custcontent.ContentType{})
		So(len(cts), ShouldBeGreaterThan, 0)

		//test delete part content
		bodyBytes, _ = json.Marshal(content)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/cms/part/", ":id", strconv.Itoa(11000)+"?key="+apiKey, DeletePartContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &partContent)
		So(err, ShouldBeNil)
		So(partContent, ShouldHaveSameTypeAs, custcontent.PartContent{})

		//test delete category content
		bodyBytes, _ = json.Marshal(categoryContent)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/cms/category/", ":id", strconv.Itoa(catContent.CategoryId)+"?key="+apiKey, DeleteCategoryContent, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &content)
		So(err, ShouldBeNil)
		So(content, ShouldHaveSameTypeAs, custcontent.CustomerContent{})

	})
	//teardown
	err = content.DeleteById()
	err = categoryContent.DeleteById()

	for _, con := range catContent.Content {
		err = con.DeleteById()
	}
	err = c.Delete()

	err = ct.Delete()

}
Exemplo n.º 10
0
func TestDealers_New(t *testing.T) {
	var err error
	var c customer.Customer
	var cs customer.Customers
	var loc customer.CustomerLocation
	var locs customer.CustomerLocations

	dtx, err := apicontextmock.Mock()
	if err != nil {
		t.Log(err)
	}
	//setup lcoation for getById
	loc.Address = "123 Test Ave."
	loc.Create(dtx)

	Convey("Testing Dealers_New", t, func() {
		//test get etailers
		thyme := time.Now()
		testThatHttp.RequestWithDtx("get", "/dealers/etailer", "", "?key="+dtx.APIKey, GetEtailers, nil, "", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds())
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cs)
		So(err, ShouldBeNil)
		So(cs, ShouldHaveSameTypeAs, customer.Customers{})
		So(len(cs), ShouldBeGreaterThanOrEqualTo, 0)

		//test get local dealers
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/local", "", "?key="+dtx.APIKey+"&latlng=43.853282,-95.571675,45.800981,-90.468526&center=44.83536,-93.0201", GetLocalDealers, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var dls customer.DealerLocations
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &dls)
		So(err, ShouldBeNil)
		So(dls, ShouldHaveSameTypeAs, customer.DealerLocations{})

		//test get local dealers
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/local/regions", "", "?key="+dtx.APIKey, GetLocalRegions, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*5) //Long test
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var stateRegions []customer.StateRegion
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &stateRegions)
		So(err, ShouldBeNil)
		So(stateRegions, ShouldHaveSameTypeAs, []customer.StateRegion{})

		//test get dealerTypes
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/local/types", "", "?key="+dtx.APIKey, GetLocalDealerTypes, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var types []customer.DealerType
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &types)
		So(err, ShouldBeNil)
		So(types, ShouldHaveSameTypeAs, []customer.DealerType{})

		//test get dealerTiers
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/local/tiers", "", "?key="+dtx.APIKey, GetLocalDealerTiers, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var tiers []customer.DealerTier
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &tiers)
		So(err, ShouldBeNil)
		So(tiers, ShouldHaveSameTypeAs, []customer.DealerTier{})

		//test get dealerTiers
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/etailer/platinum", "", "?key="+dtx.APIKey, PlatinumEtailers, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cs)
		So(err, ShouldBeNil)
		So(cs, ShouldHaveSameTypeAs, customer.Customers{})

		//test get location by id
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/location/", ":id", strconv.Itoa(loc.Id)+"?key="+dtx.APIKey, GetLocationById, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &loc)
		So(err, ShouldBeNil)
		So(loc, ShouldHaveSameTypeAs, customer.CustomerLocation{})

		//test get all business classes
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/business/classes", "", "?key="+dtx.APIKey, GetAllBusinessClasses, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var bcs customer.BusinessClasses
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &bcs)
		So(err, ShouldBeNil)
		So(bcs, ShouldHaveSameTypeAs, customer.BusinessClasses{})

		//test search Locations
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/search/", ":search", "test?key="+dtx.APIKey, SearchLocations, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &locs)
		So(err, ShouldBeNil)
		So(locs, ShouldHaveSameTypeAs, customer.CustomerLocations{})

		//test search Locations by type
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/search/type/", ":search", "test?key="+dtx.APIKey, SearchLocationsByType, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &locs)
		So(err, ShouldBeNil)
		So(locs, ShouldHaveSameTypeAs, customer.CustomerLocations{})

		//test search Locations by lat long
		thyme = time.Now()
		testThatHttp.Request("get", "/dealers/search/geo/", ":latitude/:longitude", fmt.Sprint(c.Latitude)+"/"+fmt.Sprint(c.Longitude)+"?key="+dtx.APIKey, SearchLocationsByType, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		So(testThatHttp.Response, ShouldNotBeNil)
		So(testThatHttp.Response.Body, ShouldNotBeNil)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &dls)
		So(err, ShouldBeNil)
		So(dls, ShouldHaveSameTypeAs, customer.DealerLocations{})

	})
	//teardown
	loc.Delete(dtx)
	_ = apicontextmock.DeMock(dtx)
}
Exemplo n.º 11
0
func TestCustomerUser(t *testing.T) {

	var err error
	var cu customer.CustomerUser
	var c customer.Customer
	c.Name = "Dog Bountyhunter"
	c.BrandIDs = append(c.BrandIDs, 1)
	c.Create()

	var pub, pri, auth apiKeyType.ApiKeyType
	if database.GetCleanDBFlag() != "" {
		t.Log(database.GetCleanDBFlag())
		//setup apiKeyTypes
		pub.Type = "Public"
		pri.Type = "Private"
		auth.Type = "Authentication"
		pub.Create()
		pri.Create()
		auth.Create()
	}
	Convey("Testing customer/User", t, func() {
		//test create customer user
		form := url.Values{"name": {"Mitt Romney"}, "email": {"*****@*****.**"}, "pass": {"robthepoor"}, "customerID": {strconv.Itoa(c.Id)}, "isActive": {"true"}, "locationID": {"1"}, "isSudo": {"true"}, "cust_ID": {strconv.Itoa(c.Id)}}
		v := form.Encode()
		body := strings.NewReader(v)
		thyme := time.Now()
		testThatHttp.Request("post", "/customer/user/register", "", "", RegisterUser, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
		So(err, ShouldBeNil)
		So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
		So(cu.Id, ShouldNotBeEmpty)
		//key stuff - get apiKey
		var apiKey string
		for _, k := range cu.Keys {
			if strings.ToLower(k.Type) == "public" {
				apiKey = k.Key
			}
		}

		//test update customer user
		form = url.Values{"name": {"Michelle Bachman"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/user/", ":id", cu.Id, UpdateCustomerUser, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
		So(err, ShouldBeNil)
		So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
		So(cu.Name, ShouldNotEqual, "Mitt Romney")

		//test authenticateUser
		err = c.JoinUser(cu)
		So(err, ShouldBeNil)
		form = url.Values{"email": {"*****@*****.**"}, "password": {"robthepoor"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/auth", "", "", AuthenticateUser, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})

		//test keyed user authentication
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/auth", "", "?key="+apiKey, KeyedUserAuthentication, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, customer.Customer{})

		//test get user by id
		thyme = time.Now()
		testThatHttp.Request("get", "/customer/", ":id", cu.Id+"?key="+apiKey, GetUserById, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
		So(err, ShouldBeNil)
		So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})

		//test change user password
		form = url.Values{"email": {"*****@*****.**"}, "oldPass": {"robthepoor"}, "newPass": {"prolife"}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/user/changePassword", "", "?key="+apiKey, ChangePassword, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var result string
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &result)
		So(err, ShouldBeNil)
		So(result, ShouldHaveSameTypeAs, "Success")

		//test reset  user password
		form = url.Values{"email": {"*****@*****.**"}, "customerID": {strconv.Itoa(c.CustomerId)}}
		v = form.Encode()
		body = strings.NewReader(v)
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/user/resetPassword", "", "?key="+apiKey, ResetPassword, body, "application/x-www-form-urlencoded")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &result)
		So(err, ShouldBeNil)
		So(result, ShouldHaveSameTypeAs, "Success")

		//test generate api key
		thyme = time.Now()
		testThatHttp.Request("post", "/customer/user/", ":id/key/:type", cu.Id+"/key/PRIVATE?key="+apiKey, GenerateApiKey, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var newKey customer.ApiCredentials
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &newKey)
		So(err, ShouldBeNil)
		So(newKey.Key, ShouldHaveSameTypeAs, "string")

		//test delete customer users by customerId
		var cu2 customer.CustomerUser
		cu2.Create([]int{1})
		c.JoinUser(cu2)
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/allUsersByCustomerID/", ":id", strconv.Itoa(c.Id), DeleteCustomerUsersByCustomerID, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var response string
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &response)
		So(err, ShouldBeNil)
		So(response, ShouldHaveSameTypeAs, "this is a string")

		//test delete customer user
		thyme = time.Now()
		testThatHttp.Request("delete", "/customer/user/", ":id", cu.Id, DeleteCustomerUser, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
		So(err, ShouldBeNil)
		So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
		So(cu.Id, ShouldNotBeEmpty)
		cu2.Delete()
	})
	//teardown
	err = c.Delete()
	if err != nil {
		t.Log(err)
	}

	if database.EmptyDb != nil {
		err = pub.Delete()
		if err != nil {
			t.Log(err)
		}
		err = pri.Delete()
		if err != nil {
			t.Log(err)
		}
		err = auth.Delete()
		if err != nil {
			t.Log(err)
		}
	}

	err = cu.Delete()
	if err != nil {
		t.Log(err)
	}

}
Exemplo n.º 12
0
func TestContact(t *testing.T) {
	var c contact.Contact
	var ct contact.ContactType
	var cr contact.ContactReceiver
	var err error
	Convey("Testing Contact", t, func() {

		//test create contact type using form
		form := url.Values{"name": {"test type"}, "brandId": {"1"}}
		v := form.Encode()
		body := strings.NewReader(v)
		testThatHttp.Request("post", "/contact/types", "", "", AddContactType, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ct)
		So(err, ShouldBeNil)
		So(ct, ShouldHaveSameTypeAs, contact.ContactType{})

		//test create contact receiver using form
		form = url.Values{"first_name": {"test name"}, "last_name": {"test last name"}, "email": {"*****@*****.**"}, "contact_types": {strconv.Itoa(ct.ID)}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("post", "/contact/receivers", "", "", AddContactReceiver, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cr)
		So(err, ShouldBeNil)
		So(cr, ShouldHaveSameTypeAs, contact.ContactReceiver{})

		//test create contact using json
		flag.Set("noEmail", "true") //do not send email during tests
		c.LastName = "smith"
		c.FirstName = "fred"
		c.Type = strconv.Itoa(ct.ID)
		c.Email = "*****@*****.**"
		c.Message = "test mes"
		c.Subject = "test sub"
		bodyBytes, _ := json.Marshal(c)
		bodyJson := bytes.NewReader(bodyBytes)
		testThatHttp.Request("post", "/contact/", ":contactTypeID", strconv.Itoa(ct.ID), AddDealerContact, bodyJson, "application/json")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, contact.Contact{})

		//test update contact using form
		form = url.Values{"last_name": {"formLastName"}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("put", "/contact/", ":id", strconv.Itoa(c.ID), UpdateContact, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, contact.Contact{})

		//test update contact using json
		c.LastName = "jsonLastName"
		bodyBytes, _ = json.Marshal(c)
		bodyJson = bytes.NewReader(bodyBytes)
		testThatHttp.Request("put", "/contact/", ":id", strconv.Itoa(c.ID), UpdateContact, bodyJson, "application/json")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)
		So(c, ShouldHaveSameTypeAs, contact.Contact{})

		//test update contact type using form
		form = url.Values{"name": {"formName"}, "show": {"true"}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("put", "/contact/types/", ":id", strconv.Itoa(ct.ID), UpdateContactType, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ct)
		So(err, ShouldBeNil)
		So(ct, ShouldHaveSameTypeAs, contact.ContactType{})

		//test update contact receiver using form
		form = url.Values{"first_name": {"new test name"}, "last_name": {"new test last name"}, "contact_types": {strconv.Itoa(ct.ID)}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("put", "/contact/receivers/", ":id", strconv.Itoa(cr.ID), UpdateContactReceiver, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cr)
		So(err, ShouldBeNil)
		So(cr, ShouldHaveSameTypeAs, contact.ContactReceiver{})

		//test get contact
		testThatHttp.Request("get", "/contact/", ":id", strconv.Itoa(c.ID), GetContact, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)

		//test get all contacts
		form = url.Values{"page": {"1"}, "count": {"1"}}
		v = form.Encode()
		body = strings.NewReader(v)
		testThatHttp.Request("get", "/contact", "", "", GetAllContacts, body, "application/x-www-form-urlencoded")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var cs contact.Contacts
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cs)
		So(err, ShouldBeNil)
		So(cs, ShouldHaveSameTypeAs, contact.Contacts{})
		So(len(cs), ShouldBeGreaterThanOrEqualTo, 0)

		//test get contact type
		testThatHttp.Request("get", "/contact/types/", ":id", strconv.Itoa(ct.ID), GetContactType, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ct)
		So(err, ShouldBeNil)
		So(ct, ShouldHaveSameTypeAs, contact.ContactType{})

		//test get all contact type
		testThatHttp.Request("get", "/contact/types", "", "", GetAllContactTypes, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var cts contact.ContactTypes
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cts)
		So(err, ShouldBeNil)
		So(cts, ShouldHaveSameTypeAs, contact.ContactTypes{})

		//test get receivers by contact type
		testThatHttp.Request("get", "/contact/types/receivers/", ":id", strconv.Itoa(ct.ID), GetReceiversByContactType, nil, "")
		var crs contact.ContactReceivers
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &crs)
		So(err, ShouldBeNil)
		So(crs, ShouldHaveSameTypeAs, contact.ContactReceivers{})
		So(len(crs), ShouldBeGreaterThan, 0)

		//test get contact receiver
		testThatHttp.Request("get", "/contact/receiver/", ":id", strconv.Itoa(cr.ID), GetContactReceiver, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cr)
		So(err, ShouldBeNil)

		//test get all contact receiver
		testThatHttp.Request("get", "/contact/receiver", "", "", GetAllContactReceivers, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &crs)
		So(err, ShouldBeNil)
		So(crs, ShouldHaveSameTypeAs, contact.ContactReceivers{})
		So(len(crs), ShouldBeGreaterThan, 0)

		//test delete contact
		testThatHttp.Request("delete", "/contact/", ":id", strconv.Itoa(c.ID), DeleteContact, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
		So(err, ShouldBeNil)

		//test delete contact type
		testThatHttp.Request("delete", "/contact/types/", ":id", strconv.Itoa(ct.ID), DeleteContactType, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ct)
		So(err, ShouldBeNil)

		//test delete contact receiver
		testThatHttp.Request("delete", "/contact/receiver/", ":id", strconv.Itoa(cr.ID), DeleteContactReceiver, nil, "")
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cr)
		So(err, ShouldBeNil)

	})
}
Exemplo n.º 13
0
func TestParts(t *testing.T) {
	var err error
	var p products.Part
	p.ID = 10999 //set part number here for use in creating related objects
	var price products.Price
	// var cu customer.CustomerUser
	var cat products.Category
	cat.Create()

	//create install sheet content type
	var contentType custcontent.ContentType
	contentType.Type = "InstallationSheet"
	err = contentType.Create()

	//create install sheet content
	var installSheetContent products.Content
	installSheetContent.Text = "https://www.curtmfg.com/masterlibrary/13201/installsheet/CM_13201_INS.PDF"
	installSheetContent.ContentType.Id = contentType.Id
	err = installSheetContent.Create()

	//create video type -- used in creating video during video test
	var vt video.VideoType
	vt.Name = "test type"
	vt.Create()

	//key types
	var pub, pri, auth apiKeyType.ApiKeyType
	if database.GetCleanDBFlag() != "" {
		//setup apiKeyTypes

		pub.Type = "public"
		pri.Type = "private"
		auth.Type = "authentication"
		pub.Create()
		pri.Create()
		auth.Create()
	}

	dtx, err := apicontextmock.Mock()
	if err != nil {
		t.Log(err)
	}

	Convey("TestingParts", t, func() {
		//test create part
		p.Categories = append(p.Categories, cat)
		p.OldPartNumber = "8675309"
		p.ShortDesc = "test part"
		p.Content = append(p.Content, installSheetContent)
		bodyBytes, _ := json.Marshal(p)
		bodyJson := bytes.NewReader(bodyBytes)
		thyme := time.Now()
		testThatHttp.RequestWithDtx("post", "/part", "", "?key="+dtx.APIKey, CreatePart, bodyJson, "application/json", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, products.Part{})
		So(p.ID, ShouldEqual, 10999)

		p.BindCustomer(dtx)

		var custPrice customer.Price
		custPrice.CustID = dtx.CustomerID
		custPrice.PartID = p.ID
		err = custPrice.Create()

		//test create price
		price.Price = 987
		price.PartId = p.ID
		price.Type = "test"
		bodyBytes, _ = json.Marshal(price)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.RequestWithDtx("post", "/price", "", "?key="+dtx.APIKey, SavePrice, bodyJson, "application/json", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
		So(err, ShouldBeNil)
		So(price, ShouldHaveSameTypeAs, products.Price{})
		So(price.Id, ShouldBeGreaterThan, 0)

		//test update price
		price.Type = "tester"
		bodyBytes, _ = json.Marshal(price)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.RequestWithDtx("post", "/price/", ":id", strconv.Itoa(price.Id)+"?key="+dtx.APIKey, SavePrice, bodyJson, "application/json", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
		So(err, ShouldBeNil)
		So(price, ShouldHaveSameTypeAs, products.Price{})
		So(price.Type, ShouldNotEqual, "test")

		// //test get part prices
		thyme = time.Now()
		testThatHttp.RequestWithDtx("get", "/part/", ":part/prices", strconv.Itoa(p.ID)+"/prices?key="+dtx.APIKey, Prices, nil, "", dtx)
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var prices []products.Price
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &prices)
		So(err, ShouldBeNil)
		So(prices, ShouldHaveSameTypeAs, []products.Price{})

		// //test get part categories
		thyme = time.Now()
		testThatHttp.Request("get", "/part/", ":part/categories", strconv.Itoa(p.ID)+"/categories?key="+dtx.APIKey, Categories, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var cats []products.Category
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cats)
		So(err, ShouldBeNil)
		So(cats, ShouldHaveSameTypeAs, []products.Category{})

		//test get part install sheet
		thyme = time.Now()
		testThatHttp.Request("get", "/part/", ":part", strconv.Itoa(p.ID)+".pdf?key="+dtx.APIKey, InstallSheet, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*6) //three seconds
		So(testThatHttp.Response.Code, ShouldEqual, 200)

		//test get videos
		//create part video
		var partVid video.Video

		err = partVid.Create(dtx)

		err = partVid.CreateJoinPart(p.ID)

		thyme = time.Now()
		testThatHttp.Request("get", "/part/videos/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Videos, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var ps []products.PartVideo
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &ps)
		So(err, ShouldBeNil)
		So(len(ps), ShouldBeGreaterThan, 0)

		//get active approved reviews
		//create active approved review
		var review products.Review
		review.PartID = p.ID
		review.Rating = 1
		review.Active = true
		review.Approved = true
		err = review.Create(dtx)
		thyme = time.Now()
		testThatHttp.Request("get", "/part/reviews/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, ActiveApprovedReviews, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var reviews products.Reviews
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &reviews)
		So(err, ShouldBeNil)
		So(len(reviews), ShouldBeGreaterThan, 0)
		review.Delete(dtx) //teardown - part has FK constraint on review.partID

		//get packaging - no package created in test
		thyme = time.Now()
		testThatHttp.Request("get", "/part/packages/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Packaging, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var pack []products.Package
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &pack)
		So(err, ShouldBeNil)
		So(pack, ShouldHaveSameTypeAs, []products.Package{})

		//get content
		thyme = time.Now()
		testThatHttp.Request("get", "/part/content/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, GetContent, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var content products.Content
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &content)
		So(err, ShouldBeNil)
		So(content, ShouldHaveSameTypeAs, products.Content{})

		//get attributes
		thyme = time.Now()
		testThatHttp.Request("get", "/part/attributes/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Attributes, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var attributes []products.Attribute
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &attributes)
		So(err, ShouldBeNil)
		So(attributes, ShouldHaveSameTypeAs, []products.Attribute{})

		//test get images
		thyme = time.Now()
		testThatHttp.Request("get", "/part/images/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Images, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var images []products.Image
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &images)
		So(err, ShouldBeNil)
		So(images, ShouldHaveSameTypeAs, []products.Image{})

		//test get vehicles
		thyme = time.Now()
		testThatHttp.Request("get", "/part/vehicles/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Vehicles, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var vs []products.Vehicle
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &vs)
		So(err, ShouldBeNil)
		So(vs, ShouldHaveSameTypeAs, []products.Vehicle{})

		//test get related
		thyme = time.Now()
		testThatHttp.Request("get", "/part/related/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, GetRelated, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var parts []products.Part
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &parts)
		So(err, ShouldBeNil)
		So(parts, ShouldHaveSameTypeAs, []products.Part{})

		//test get
		thyme = time.Now()
		t.Log(strconv.Itoa(p.ID))
		testThatHttp.Request("get", "/part/", ":part", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, Get, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds())
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		var part products.Part
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &part)
		So(err, ShouldBeNil)
		So(part, ShouldHaveSameTypeAs, products.Part{})

		//test latest
		thyme = time.Now()
		testThatHttp.Request("get", "/part/latest", "", "?key="+dtx.APIKey, Latest, nil, "")
		t.Log("Get latest parts benchmark: ", time.Since(thyme))
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &parts)
		So(err, ShouldBeNil)
		So(parts, ShouldHaveSameTypeAs, []products.Part{})

		// test all
		thyme = time.Now()
		testThatHttp.Request("get", "/part/all", "", "?key="+dtx.APIKey, AllBasics, nil, "")
		t.Log("Get all basic parts benchmark: ", time.Since(thyme))
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &parts)
		So(err, ShouldBeNil)
		So(parts, ShouldHaveSameTypeAs, []products.Part{})

		//test featured
		thyme = time.Now()
		testThatHttp.Request("get", "/part/featured", "", "?key="+dtx.APIKey, Featured, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*3) //3 seconds!
		t.Log("Get featured parts benchmark: ", time.Since(thyme))
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &parts)
		So(err, ShouldBeNil)
		So(parts, ShouldHaveSameTypeAs, []products.Part{})

		//test get all parts
		thyme = time.Now()
		testThatHttp.Request("get", "/part", "", "?key="+dtx.APIKey, All, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*6) //6 seconds
		t.Log("Get all parts benchmark: ", time.Since(thyme))
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &parts)
		So(err, ShouldBeNil)
		So(parts, ShouldHaveSameTypeAs, []products.Part{})

		//test get price
		thyme = time.Now()
		testThatHttp.Request("get", "/price/", ":id", strconv.Itoa(price.Id)+"?key="+dtx.APIKey, GetPrice, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
		So(err, ShouldBeNil)
		So(price, ShouldHaveSameTypeAs, products.Price{})

		//test get old part Number
		thyme = time.Now()
		testThatHttp.Request("get", "/part/old/", ":part", p.OldPartNumber+"?key="+dtx.APIKey, OldPartNumber, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, products.Part{})
		So(p.OldPartNumber, ShouldEqual, "8675309")
		So(p.ID, ShouldEqual, 10999)

		//test delete price
		thyme = time.Now()
		testThatHttp.Request("delete", "/price/", ":id", strconv.Itoa(price.Id)+"?key="+dtx.APIKey, DeletePrice, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
		So(err, ShouldBeNil)
		So(price, ShouldHaveSameTypeAs, products.Price{})

		//test update part
		p.OldPartNumber = "8675309"
		p.InstallSheet, err = url.Parse("www.sheetsrus.com")
		bodyBytes, _ = json.Marshal(p)
		bodyJson = bytes.NewReader(bodyBytes)
		thyme = time.Now()
		testThatHttp.Request("put", "/part/", ":id", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, UpdatePart, bodyJson, "application/json")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds())
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, products.Part{})
		So(p.OldPartNumber, ShouldEqual, "8675309")
		So(p.ID, ShouldEqual, 10999)

		//test delete part
		thyme = time.Now()
		testThatHttp.Request("delete", "/part/", ":id", strconv.Itoa(p.ID)+"?key="+dtx.APIKey, DeletePart, nil, "")
		So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
		So(testThatHttp.Response.Code, ShouldEqual, 200)
		err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &p)
		So(err, ShouldBeNil)
		So(p, ShouldHaveSameTypeAs, products.Part{})

		// //teardown
		custPrice.Delete()
		partVid.Delete(dtx)
		partVid.DeleteJoinPart(p.ID)

	})
	//teardown
	p.Delete(dtx)
	cat.Delete(dtx)
	if database.GetCleanDBFlag() != "" {
		pub.Delete()
		pri.Delete()
		auth.Delete()
	}
	contentType.Delete()
	installSheetContent.Delete()
	vt.Delete()

	_ = apicontextmock.DeMock(dtx)

}