示例#1
0
func Test_AddAddress(t *testing.T) {
	Convey("with no shop identifier", t, func() {
		qs := make(url.Values, 0)

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/1234/addresses", &qs, nil, AddAddress)
		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)
		qs := make(url.Values, 0)
		qs.Add("shop", shopID.Hex())

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/1234/addresses", &qs, nil, AddAddress)
		So(response.Code, ShouldEqual, 500)
		So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil)

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/"+shopID.Hex()+"/addresses", &qs, nil, AddAddress)
		So(response.Code, ShouldEqual, 500)
		So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil)

		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)

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, &cart.Shop{}, AddAddress)
		So(response.Code, ShouldEqual, 500)
		So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil)

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, &cart.Shop{}, AddAddress)
		So(response.Code, ShouldEqual, 500)
		So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), 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",
		}

		response = httprunner.ParameterizedJsonRequest("POST", "/shopify/customers/:id/addresses", "/shopify/customers/"+cust.Id.Hex()+"/addresses", &qs, &addr, AddAddress)
		So(response.Code, ShouldEqual, 500)
		So(json.Unmarshal(response.Body.Bytes(), &apierror.ApiErr{}), ShouldBeNil)

		addr.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(), &cart.CustomerAddress{}), ShouldBeNil)
	})
}