Skip to content

Commit

Permalink
convert some tests to use RegisterResponderWithQuery (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
umsu2 authored and andrewhoff committed Dec 20, 2018
1 parent 422649a commit 4b0481a
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 37 deletions.
16 changes: 11 additions & 5 deletions asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ func TestAssetList(t *testing.T) {
func TestAssetGet(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder(
params := map[string]string{
"asset[key]": "foo/bar.liquid",
"theme_id": "1",
}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/themes/1/assets.json?asset[key]=foo/bar.liquid&theme_id=1",
"https://fooshop.myshopify.com/admin/themes/1/assets.json",
params,
httpmock.NewStringResponder(
200,
`{"asset": {"key":"foo\/bar.liquid"}}`,
Expand Down Expand Up @@ -93,9 +97,11 @@ func TestAssetDelete(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder(
params := map[string]string{"asset[key]": "foo/bar.liquid"}
httpmock.RegisterResponderWithQuery(
"DELETE",
"https://fooshop.myshopify.com/admin/themes/1/assets.json?asset[key]=foo/bar.liquid",
"https://fooshop.myshopify.com/admin/themes/1/assets.json",
params,
httpmock.NewStringResponder(200, "{}"),
)

Expand Down
4 changes: 3 additions & 1 deletion collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func TestCollectCount(t *testing.T) {
httpmock.NewStringResponder(200, `{"count": 5}`))

params := map[string]string{"since_id": "123"}
httpmock.RegisterResponderWithQuery("GET", "https://fooshop.myshopify.com/admin/collects/count.json", params,
httpmock.RegisterResponderWithQuery("GET",
"https://fooshop.myshopify.com/admin/collects/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Collect.Count(nil)
Expand Down
12 changes: 10 additions & 2 deletions customcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func TestCustomCollectionCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/custom_collections/count.json",
httpmock.NewStringResponder(200, `{"count": 5}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/custom_collections/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/custom_collections/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.CustomCollection.Count(nil)
Expand Down Expand Up @@ -175,7 +179,11 @@ func TestCustomCollectionCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/collections/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.CustomCollection.CountMetafields(1, nil)
Expand Down
18 changes: 14 additions & 4 deletions customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func TestCustomerCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/count.json",
httpmock.NewStringResponder(200, `{"count": 5}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/customers/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Customer.Count(nil)
Expand Down Expand Up @@ -310,7 +314,11 @@ func TestCustomerCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/customers/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Customer.CountMetafields(1, nil)
Expand Down Expand Up @@ -420,9 +428,11 @@ func TestCustomerListOrders(t *testing.T) {
"https://fooshop.myshopify.com/admin/customers/1/orders.json",
httpmock.NewStringResponder(200, "{\"orders\":[]}"),
)
httpmock.RegisterResponder(
params := map[string]string{"status": "any"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/customers/1/orders.json?status=any",
"https://fooshop.myshopify.com/admin/customers/1/orders.json",
params,
httpmock.NewBytesResponder(200, loadFixture("orders.json")),
)

Expand Down
6 changes: 5 additions & 1 deletion fulfillment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func TestFulfillmentCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/orders/123/fulfillments/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123}
Expand Down
6 changes: 5 additions & 1 deletion goshopify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,11 @@ func TestCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/foocount",
httpmock.NewStringResponder(200, `{"count": 5}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/foocount?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/foocount",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

// Test without options
Expand Down
6 changes: 5 additions & 1 deletion image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func TestImageCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/images/count.json",
httpmock.NewStringResponder(200, `{"count": 2}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/images/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/products/1/images/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 1}`))

cnt, err := client.Image.Count(1, nil)
Expand Down
6 changes: 5 additions & 1 deletion metafield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func TestMetafieldCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Metafield.Count(nil)
Expand Down
30 changes: 25 additions & 5 deletions order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ func TestOrderList(t *testing.T) {
func TestOrderListOptions(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders.json?fields=id,name&limit=250&page=10&status=any",
params := map[string]string{
"fields": "id,name",
"limit": "250",
"page": "10",
"status": "any",
}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/orders.json",
params,
httpmock.NewBytesResponder(200, loadFixture("orders.json")))

options := OrderListOptions{
Expand Down Expand Up @@ -171,7 +179,11 @@ func TestOrderCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/count.json",
httpmock.NewStringResponder(200, `{"count": 7}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/orders/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Order.Count(nil)
Expand Down Expand Up @@ -272,7 +284,11 @@ func TestOrderCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/orders/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Order.CountMetafields(1, nil)
Expand Down Expand Up @@ -398,7 +414,11 @@ func TestOrderCountFulfillments(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/orders/1/fulfillments/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Order.CountFulfillments(1, nil)
Expand Down
12 changes: 10 additions & 2 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func TestPageCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/pages/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Page.Count(nil)
Expand Down Expand Up @@ -161,7 +165,11 @@ func TestPageCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/pages/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Page.CountMetafields(1, nil)
Expand Down
18 changes: 15 additions & 3 deletions product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func TestProductListFilterByIds(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products.json?ids=1,2,3",
params := map[string]string{"ids": "1,2,3"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/products.json",
params,
httpmock.NewStringResponder(200, `{"products": [{"id":1},{"id":2},{"id":3}]}`))

listOptions := ListOptions{IDs: []int{1, 2, 3}}
Expand All @@ -61,7 +65,11 @@ func TestProductCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/products/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Product.Count(nil)
Expand Down Expand Up @@ -184,7 +192,11 @@ func TestProductCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/products/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Product.CountMetafields(1, nil)
Expand Down
8 changes: 4 additions & 4 deletions recurringapplicationcharge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ func TestRecurringApplicationChargeServiceOp_Delete(t *testing.T) {
func TestRecurringApplicationChargeServiceOp_Update(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder(
params := map[string]string{"recurring_application_charge[capped_amount]": "100"}
httpmock.RegisterResponderWithQuery(
"PUT",
"https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/customize.jso"+
"n?recurring_application_charge[capped_amount]=100",
"https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/customize.json",
params,
httpmock.NewStringResponder(
200, `{"recurring_application_charge":{"id":455696195,"capped_amount":"100.00"}}`,
),
Expand Down
6 changes: 5 additions & 1 deletion redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func TestRedirectCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/redirects/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/redirects/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/redirects/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Redirect.Count(nil)
Expand Down
12 changes: 10 additions & 2 deletions smartcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func TestSmartCollectionCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/smart_collections/count.json",
httpmock.NewStringResponder(200, `{"count": 5}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/smart_collections/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/smart_collections/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.SmartCollection.Count(nil)
Expand Down Expand Up @@ -178,7 +182,11 @@ func TestSmartCollectionCountMetafields(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/collections/1/metafields/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.SmartCollection.CountMetafields(1, nil)
Expand Down
6 changes: 4 additions & 2 deletions theme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ func TestThemeList(t *testing.T) {
),
)

httpmock.RegisterResponder(
params := map[string]string{"role": "main"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/themes.json?role=main",
"https://fooshop.myshopify.com/admin/themes.json",
params,
httpmock.NewStringResponder(
200,
`{"themes": [{"id":1}]}`,
Expand Down
6 changes: 5 additions & 1 deletion variant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ func TestVariantCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/variants/count.json",
httpmock.NewStringResponder(200, `{"count": 3}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/variants/count.json?created_at_min=2016-01-01T00:00:00Z",
params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/products/1/variants/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Variant.Count(1, nil)
Expand Down
6 changes: 5 additions & 1 deletion webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func TestWebhookCount(t *testing.T) {
httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/count.json",
httpmock.NewStringResponder(200, `{"count": 7}`))

httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/count.json?topic=orders/paid",
params := map[string]string{"topic": "orders/paid"}
httpmock.RegisterResponderWithQuery(
"GET",
"https://fooshop.myshopify.com/admin/webhooks/count.json",
params,
httpmock.NewStringResponder(200, `{"count": 2}`))

cnt, err := client.Webhook.Count(nil)
Expand Down

0 comments on commit 4b0481a

Please sign in to comment.