Browse Source

Add ShopifyAPI::CustomerSavedSearch

Christian Joudrey 11 years ago
parent
commit
d50bc4bd73

+ 5 - 0
lib/shopify_api/resources/customer_saved_search.rb

@@ -0,0 +1,5 @@
+module ShopifyAPI
+  class CustomerSavedSearch < Base
+    has_many :customers, :class_name => ShopifyAPI::Customer
+  end
+end

+ 20 - 0
test/customer_saved_search_test.rb

@@ -0,0 +1,20 @@
+require 'test_helper'
+
+class CustomerSavedSearchTest < Test::Unit::TestCase
+  def setup
+    super
+    load_customer_saved_search
+  end
+
+  def test_get_customers_from_customer_saved_search
+    fake 'customers.json?customer_saved_search_id=8899730', :body => load_fixture('customer_saved_search_customers'), :extension => false
+    assert_equal 1, @customer_saved_search.customers.length
+    assert_equal 112223902, @customer_saved_search.customers.first.id
+  end
+
+  private
+  def load_customer_saved_search
+    fake 'customer_saved_searches/8899730', :body => load_fixture('customer_saved_search')
+    @customer_saved_search = ShopifyAPI::CustomerSavedSearch.find(8899730)
+  end
+end

+ 9 - 0
test/fixtures/customer_saved_search.json

@@ -0,0 +1,9 @@
+{
+  "customer_saved_search": {
+    "created_at": "2013-01-21T13:26:12-05:00",
+    "id": 8899730,
+    "name": "Accepts Marketing",
+    "updated_at": "2013-01-21T13:26:12-05:00",
+    "query": "accepts_marketing:1"
+  }
+}

+ 60 - 0
test/fixtures/customer_saved_search_customers.json

@@ -0,0 +1,60 @@
+{
+  "customers": [
+    {
+      "accepts_marketing": true,
+      "created_at": "2013-01-29T16:33:35-05:00",
+      "email": "john.smith@gmail.com",
+      "first_name": "John",
+      "id": 112223902,
+      "last_name": "Smith",
+      "last_order_id": null,
+      "multipass_identifier": null,
+      "note": "This is sample note",
+      "orders_count": 0,
+      "state": "disabled",
+      "total_spent": "0.00",
+      "updated_at": "2013-03-05T17:00:05-05:00",
+      "verified_email": true,
+      "tags": "Buyer, Canadian",
+      "last_order_name": null,
+      "default_address": {
+        "address1": "1234 Simple Road",
+        "address2": null,
+        "city": "Ottawa",
+        "company": null,
+        "country": "Canada",
+        "first_name": "John",
+        "id": 152583148,
+        "last_name": "Smith",
+        "phone": "555-555-5555",
+        "province": "Ontario",
+        "zip": "K2H 0A0",
+        "name": "John Smith",
+        "province_code": "ON",
+        "country_code": "CA",
+        "country_name": "Canada",
+        "default": true
+      },
+      "addresses": [
+        {
+          "address1": "1234 Simple Road",
+          "address2": null,
+          "city": "Ottawa",
+          "company": null,
+          "country": "Canada",
+          "first_name": "John",
+          "id": 152583148,
+          "last_name": "Smith",
+          "phone": "555-555-5555",
+          "province": "Ontario",
+          "zip": "K2H 0A0",
+          "name": "John Smith",
+          "province_code": "ON",
+          "country_code": "CA",
+          "country_name": "Canada",
+          "default": true
+        }
+      ]
+    }
+  ]
+}