Forráskód Böngészése

recurring application tests

Eric Ponce 11 éve
szülő
commit
23ebd1cd0e

+ 4 - 4
lib/shopify_api/resources/recurring_application_charge.rb

@@ -1,7 +1,7 @@
 module ShopifyAPI
   class RecurringApplicationCharge < Base
     undef_method :test
-    
+
     class << self
       def current
         all.find { |c| c.status == 'active' }
@@ -11,13 +11,13 @@ module ShopifyAPI
         define_method(status) { all.select { |c| c.status == status.to_s } }
       end
     end
-    
+
     def cancel
       load_attributes_from_response(self.destroy)
     end
-    
+
     def activate
       load_attributes_from_response(post(:activate))
     end
   end
-end
+end

+ 20 - 0
test/fixtures/recurring_application_charge.json

@@ -0,0 +1,20 @@
+{
+  "recurring_application_charge": {
+    "activated_on": null,
+    "api_client_id": 755357713,
+    "billing_on": null,
+    "cancelled_on": null,
+    "created_at": "2014-01-20T13:42:19-05:00",
+    "id": 654381177,
+    "name": "Super Duper Plan",
+    "price": "10.00",
+    "return_url": "http://super-duper.shopifyapps.com",
+    "status": "pending",
+    "test": null,
+    "trial_days": 0,
+    "trial_ends_on": null,
+    "updated_at": "2014-01-20T13:42:19-05:00",
+    "decorated_return_url": "http://super-duper.shopifyapps.com?charge_id=654381177",
+    "confirmation_url": "http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164"
+  }
+}

+ 101 - 5
test/fixtures/recurring_application_charges.json

@@ -1,10 +1,106 @@
 {
   "recurring_application_charges": [
     {
-      "name": "Super Duper Plan",
-      "price": 10.0,
-      "return_url": "http://super-duper.shopifyapps.com",
-      "status": "active"
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696194,
+      "name": "Super Mega Plan2",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "active",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
+    },
+    {
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696195,
+      "name": "Super Mega Plan2",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "pending",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
+    },
+    {
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696196,
+      "name": "Super Mega Plan3",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "cancelled",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
+    },
+    {
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696197,
+      "name": "Super Mega Plan4",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "accepted",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
+    },
+    {
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696198,
+      "name": "Super Mega Plan5",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "declined",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
+    },
+    {
+      "activated_on": null,
+      "api_client_id": 755357713,
+      "billing_on": "2014-01-19T00:00:00+00:00",
+      "cancelled_on": null,
+      "created_at": "2014-01-20T13:41:37-05:00",
+      "id": 455696199,
+      "name": "Super Mega Plan",
+      "price": "15.00",
+      "return_url": "http://yourapp.com",
+      "status": "accepted",
+      "test": null,
+      "trial_days": 0,
+      "trial_ends_on": null,
+      "updated_at": "2014-01-20T13:42:20-05:00",
+      "decorated_return_url": "http://yourapp.com?charge_id=455696195"
     }
   ]
-}
+}

+ 94 - 8
test/recurring_application_charge_test.rb

@@ -1,21 +1,107 @@
 require 'test_helper'
 
 class RecurringApplicationChargeTest < Test::Unit::TestCase
-  context "#all" do
-    should "get all charges" do
-      fake "recurring_application_charges"
 
-      charges = ShopifyAPI::RecurringApplicationCharge.all
-      assert_equal "Super Duper Plan", charges.first.name
-    end
+  def test_recurring_application_charges_create
+    fake "recurring_application_charges", :method => :post, :status => 201, :body => load_fixture('recurring_application_charge')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.create(
+      name: "Default Plan",
+      price: 10.0,
+      return_url: "http://test.com/confirm"
+    )
+
+    assert_equal 'http://apple.myshopify.com/admin/charges/654381177/confirm_recurring_application_charge?signature=BAhpBHkQASc%3D--419fc7424f8c290ac2b21b9004ed223e35b52164', charge.confirmation_url
+  end
+
+  def test_get_recurring_application_charges
+    fake "recurring_application_charges/654381177", :method => :get, :status => 201, :body => load_fixture('recurring_application_charge')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.find(654381177)
+
+    assert_equal "Super Duper Plan", charge.name
   end
 
+  def test_list_recurring_application_charges
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.find(:all)
+
+    assert_equal "Super Mega Plan", charge.last.name
+  end
+
+  def test_list_since_recurring_application_charges
+    fake "recurring_application_charges.json?since_id=64512345",:extension => false, :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.find(:all, :params => {:since_id => '64512345'})
+
+    assert_equal "Super Mega Plan", charge.last.name
+  end
+
+  def test_list_fields_recurring_application_charges
+    fake "recurring_application_charges.json?fields=name",:extension => false, :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.find(:all, :params => {:fields => 'name'})
+
+    assert_equal "Super Mega Plan", charge.last.name
+  end
+
+  def test_pending_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.pending
+
+    assert_equal "Super Mega Plan2", charge.last.name
+  end
 
-  should "not fail when there are no charges" do
+  def test_cancelled_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.cancelled
+
+    assert_equal "Super Mega Plan3", charge.last.name
+  end
+
+  def test_accepted_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.accepted
+
+    assert_equal "Super Mega Plan4", charge.first.name
+    assert_equal "Super Mega Plan", charge.last.name
+  end
+
+  def test_declined_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+
+    charge = ShopifyAPI::RecurringApplicationCharge.declined
+
+    assert_equal "Super Mega Plan5", charge.last.name
+  end
+
+  def test_activate_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+    fake "recurring_application_charges/455696199/activate", :method => :post, :status => 200, :body => "{}"
+
+    charge = ShopifyAPI::RecurringApplicationCharge.accepted
+
+    assert_equal true, charge.last.activate
+  end
+
+  def test_cancel_recurring_application_charge
+    fake "recurring_application_charges", :method => :get, :status => 201, :body => load_fixture('recurring_application_charges')
+    fake "recurring_application_charges/455696194", :method => :delete, :status => 200, :body => "{}"
+
+    charge = ShopifyAPI::RecurringApplicationCharge.current
+    assert_equal true, charge.cancel
+  end
+
+  def test_no_recurring_application_charge_found
     fake "recurring_application_charges", body: {recurring_application_charges: []}.to_json
 
     assert_equal 0, ShopifyAPI::RecurringApplicationCharge.all.count
     assert_equal nil, ShopifyAPI::RecurringApplicationCharge.current
     assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
   end
-end
+
+end