Browse Source

Merge pull request #285 from Shopify/application_credit_resource

application credit resource
Jason Zhao 8 years ago
parent
commit
303a1cc25b

+ 4 - 0
lib/shopify_api/resources/application_credit.rb

@@ -0,0 +1,4 @@
+module ShopifyAPI
+  class ApplicationCredit < Base
+  end
+end

+ 35 - 0
test/application_credit_test.rb

@@ -0,0 +1,35 @@
+require 'test_helper'
+
+class ApplicationCreditTest < Test::Unit::TestCase
+  def test_application_credit_create
+    fake "application_credits", method: :post, status: 201, body: load_fixture('application_credit')
+
+    credit = ShopifyAPI::ApplicationCredit.create(
+      description: "refund for application charge",
+      amount: 5.00,
+      api_client_id: 861378,
+      shop_id: 487168
+    )
+
+    assert_equal 'refund for application charge', credit.description
+    assert_equal '5.00', credit.amount
+  end
+
+  def test_get_application_credit
+    fake "application_credits/803742", method: :get, status: 201, body: load_fixture('application_credit')
+
+    credit = ShopifyAPI::ApplicationCredit.find(803742)
+
+    assert_equal 'refund for application charge', credit.description
+    assert_equal '5.00', credit.amount
+  end
+
+  def test_list_application_credits
+    fake "application_credits", method: :get, status: 201, body: load_fixture('application_credits')
+
+    credit = ShopifyAPI::ApplicationCredit.find(:all)
+
+    assert_equal 2, credit.size
+    assert_equal '10.00', credit.last.amount
+  end
+end

+ 12 - 0
test/fixtures/application_credit.json

@@ -0,0 +1,12 @@
+{
+  "application_credit": {
+    "id": 803742,
+    "api_client_id": 861378,
+    "partner_id": 549861,
+    "shop_id": 487168,
+    "amount": "5.00",
+    "description": "refund for application charge",
+    "created_at": "2015-07-10T15:03:51+10:00",
+    "updated_at": "2015-07-10T15:03:51+10:00"
+  }
+}

+ 24 - 0
test/fixtures/application_credits.json

@@ -0,0 +1,24 @@
+{
+  "application_charges": [
+    {
+      "id": 803742,
+      "api_client_id": 861378,
+      "shop_id": 487168,
+      "amount": "5.00",
+      "billing_status": "pending",
+      "description": "refund for application charge",
+      "created_at": "2015-07-10T15:03:51+10:00",
+      "updated_at": "2015-07-10T15:03:51+10:00"
+    },
+    {
+      "id": 803743,
+      "api_client_id": 861378,
+      "shop_id": 487168,
+      "amount": "10.00",
+      "billing_status": "pending",
+      "description": "refund for application charge",
+      "created_at": "2015-07-10T15:03:51+10:00",
+      "updated_at": "2015-07-10T15:03:51+10:00"
+    }
+  ]
+}