コード例 #1
0
ファイル: account_test.go プロジェクト: ninnemana/API
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)
	})
}
コード例 #2
0
ファイル: address_test.go プロジェクト: ninnemana/API
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)
	})
}
コード例 #3
0
ファイル: address_test.go プロジェクト: ninnemana/API
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)
		})
	})
}
コード例 #4
0
ファイル: account_test.go プロジェクト: ninnemana/API
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)
	})
}