From 4b0481a422a06e8d29cdce516cb43f11817e94c1 Mon Sep 17 00:00:00 2001 From: Yang Date: Thu, 20 Dec 2018 10:58:27 -0600 Subject: [PATCH] convert some tests to use RegisterResponderWithQuery (#36) --- asset_test.go | 16 +++++++++++----- collect_test.go | 4 +++- customcollection_test.go | 12 ++++++++++-- customer_test.go | 18 ++++++++++++++---- fulfillment_test.go | 6 +++++- goshopify_test.go | 6 +++++- image_test.go | 6 +++++- metafield_test.go | 6 +++++- order_test.go | 30 +++++++++++++++++++++++++----- page_test.go | 12 ++++++++++-- product_test.go | 18 +++++++++++++++--- recurringapplicationcharge_test.go | 8 ++++---- redirect_test.go | 6 +++++- smartcollection_test.go | 12 ++++++++++-- theme_test.go | 6 ++++-- variant_test.go | 6 +++++- webhook_test.go | 6 +++++- 17 files changed, 141 insertions(+), 37 deletions(-) diff --git a/asset_test.go b/asset_test.go index 11205426..13f6699c 100644 --- a/asset_test.go +++ b/asset_test.go @@ -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"}}`, @@ -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, "{}"), ) diff --git a/collect_test.go b/collect_test.go index a336f38b..5b232135 100644 --- a/collect_test.go +++ b/collect_test.go @@ -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) diff --git a/customcollection_test.go b/customcollection_test.go index e063cb1a..76e37334 100644 --- a/customcollection_test.go +++ b/customcollection_test.go @@ -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) @@ -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) diff --git a/customer_test.go b/customer_test.go index 26743ede..7d2a6e49 100644 --- a/customer_test.go +++ b/customer_test.go @@ -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) @@ -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) @@ -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")), ) diff --git a/fulfillment_test.go b/fulfillment_test.go index 5782af3e..c73a11f3 100644 --- a/fulfillment_test.go +++ b/fulfillment_test.go @@ -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} diff --git a/goshopify_test.go b/goshopify_test.go index 179b5668..8f485a29 100644 --- a/goshopify_test.go +++ b/goshopify_test.go @@ -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 diff --git a/image_test.go b/image_test.go index 54d6df68..9cc981fd 100644 --- a/image_test.go +++ b/image_test.go @@ -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) diff --git a/metafield_test.go b/metafield_test.go index eeb38e7c..86614dca 100644 --- a/metafield_test.go +++ b/metafield_test.go @@ -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) diff --git a/order_test.go b/order_test.go index 05b62c48..a8bea8ed 100644 --- a/order_test.go +++ b/order_test.go @@ -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{ @@ -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) @@ -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) @@ -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) diff --git a/page_test.go b/page_test.go index 2f3798ea..c450d83b 100644 --- a/page_test.go +++ b/page_test.go @@ -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) @@ -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) diff --git a/product_test.go b/product_test.go index b472c01a..c98b3908 100644 --- a/product_test.go +++ b/product_test.go @@ -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}} @@ -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) @@ -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) diff --git a/recurringapplicationcharge_test.go b/recurringapplicationcharge_test.go index 339886d3..199a548b 100644 --- a/recurringapplicationcharge_test.go +++ b/recurringapplicationcharge_test.go @@ -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"}}`, ), diff --git a/redirect_test.go b/redirect_test.go index 2140e018..6dbdaa3b 100644 --- a/redirect_test.go +++ b/redirect_test.go @@ -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) diff --git a/smartcollection_test.go b/smartcollection_test.go index c9cd5106..6c35376b 100644 --- a/smartcollection_test.go +++ b/smartcollection_test.go @@ -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) @@ -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) diff --git a/theme_test.go b/theme_test.go index d590add7..afc761eb 100644 --- a/theme_test.go +++ b/theme_test.go @@ -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}]}`, diff --git a/variant_test.go b/variant_test.go index dd647253..b606886e 100644 --- a/variant_test.go +++ b/variant_test.go @@ -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) diff --git a/webhook_test.go b/webhook_test.go index 35d3e5af..f983446d 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -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)