From e9ddb2a47678eb3d4298e0f1de044a6846f4c696 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 17 Sep 2013 10:57:03 -0700 Subject: This doesn't actually run any tests, but at least includes what we might want to test regarding subscriptions. --- billing/test/integration/subscription_test.rb | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 billing/test/integration/subscription_test.rb (limited to 'billing/test/integration/subscription_test.rb') diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb new file mode 100644 index 0000000..7410118 --- /dev/null +++ b/billing/test/integration/subscription_test.rb @@ -0,0 +1,48 @@ +require 'test_helper' +require 'fake_braintree' +require 'capybara/rails' + +class SubscriptionTest < ActionDispatch::IntegrationTest + include Warden::Test::Helpers + include Capybara::DSL + + setup do + Warden.test_mode! + @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin') + @customer = FactoryGirl.create(:customer) + @braintree_customer = FactoryGirl.create(:braintree_customer) + @customer.braintree_customer_id = @braintree_customer.id + @customer.save + @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id}) + # unfortunately @braintree_customer.credit_cards.first.subscriptions still returns empty array + end + + teardown do + Warden.test_reset! + @admin.destroy + @customer.destroy + end + + test "admin can cancel subscription for another" do + skip "not sure about testing admin cancelling subscription with fake_braintree" + login_as @admin + #visit user_subscriptions_path(@customer.user_id) + #delete :destroy, :id => @subscription.id + end + + #test "admin cannot add subscription for another" do + #end + + #test "authenticated user can cancel own subscription" do + #end + + #test "user cannot add subscription if they have active one" do + #end + + #test "user can view own subscriptions" + #end + + #test "admin can view another user's subscriptions" do + #end + +end -- cgit v1.2.3 From d9c088fb288783f6afca441d870003c0f288a532 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 18 Sep 2013 10:30:01 +0200 Subject: failing tests for subscriptions functional: test canceling a subscription integration: investigate the issue with creating a subscription --- billing/test/integration/subscription_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'billing/test/integration/subscription_test.rb') diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index 7410118..c53131e 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -13,8 +13,6 @@ class SubscriptionTest < ActionDispatch::IntegrationTest @braintree_customer = FactoryGirl.create(:braintree_customer) @customer.braintree_customer_id = @braintree_customer.id @customer.save - @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id}) - # unfortunately @braintree_customer.credit_cards.first.subscriptions still returns empty array end teardown do @@ -23,6 +21,11 @@ class SubscriptionTest < ActionDispatch::IntegrationTest @customer.destroy end + test "can create subscription" do + @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id}) + assert @braintree_customer.credit_cards.first.subscriptions.present? + end + test "admin can cancel subscription for another" do skip "not sure about testing admin cancelling subscription with fake_braintree" login_as @admin -- cgit v1.2.3 From c934787aa13977c3bb13155745f51ea71728d175 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 18 Sep 2013 12:47:42 +0200 Subject: working integration test --- billing/test/integration/subscription_test.rb | 31 +++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'billing/test/integration/subscription_test.rb') diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index c53131e..b893896 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -5,32 +5,31 @@ require 'capybara/rails' class SubscriptionTest < ActionDispatch::IntegrationTest include Warden::Test::Helpers include Capybara::DSL + include CustomerTestHelper + include StubRecordHelper setup do Warden.test_mode! - @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin') - @customer = FactoryGirl.create(:customer) - @braintree_customer = FactoryGirl.create(:braintree_customer) - @customer.braintree_customer_id = @braintree_customer.id - @customer.save + @admin = stub_record :user, :admin => true + @customer = stub_customer + @braintree_customer = @customer.braintree_customer + response = Braintree::Subscription.create plan_id: '5', + payment_method_token: @braintree_customer.credit_cards.first.token + @subscription = response.subscription + Capybara.current_driver = Capybara.javascript_driver end teardown do Warden.test_reset! - @admin.destroy - @customer.destroy end - test "can create subscription" do - @subscription = FakeBraintree::Subscription.new({:payment_method_token => @braintree_customer.credit_cards.first, :plan_id => '5'}, {:id => @braintree_customer.id, :merchant_id => Braintree::Configuration.merchant_id}) - assert @braintree_customer.credit_cards.first.subscriptions.present? - end - - test "admin can cancel subscription for another" do - skip "not sure about testing admin cancelling subscription with fake_braintree" + test "admin can see subscription for another" do login_as @admin - #visit user_subscriptions_path(@customer.user_id) - #delete :destroy, :id => @subscription.id + @customer.stubs(:subscriptions).returns([@subscription]) + visit user_subscriptions_path(@customer.user_id) + assert page.has_content?("Subscriptions") + assert page.has_content?("Status: Active") + page.save_screenshot('/tmp/subscriptions.png') end #test "admin cannot add subscription for another" do -- cgit v1.2.3