From 76c70b0ed4088f4c0830eff4d6b1b6785408a3e4 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 6 Apr 2016 11:27:56 +0200 Subject: [PATCH] basic subscription test --- test/integration/subscriptions_test.rb | 33 ++++++++++++++++++++++++++ test/test_helper.rb | 13 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/integration/subscriptions_test.rb diff --git a/test/integration/subscriptions_test.rb b/test/integration/subscriptions_test.rb new file mode 100644 index 000000000..b58ab10eb --- /dev/null +++ b/test/integration/subscriptions_test.rb @@ -0,0 +1,33 @@ +class SubscriptionsTest < ActionDispatch::IntegrationTest + + + setup do + @user = User.find_by_username('jdupont') + login_as(@user, scope: :user) + end + + test "user take a subscription" do + plan = Plan.where(group_id: @user.group.id, type: 'Plan').first + + post '/api/subscriptions', + { + subscription: { + plan_id: plan.id, + user_id: @user.id, + card_token: stripe_card_token + } + }.to_json, + { + 'Accept' => Mime::JSON, + 'Content-Type' => Mime::JSON.to_s + } + + assert_equal 201, response.status, response.body + assert_equal Mime::JSON, response.content_type + + subscription = json_response(response.body) + assert_equal plan.id, subscription[:plan_id] + + end + +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 4e951ee6f..e13e11357 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,6 +7,8 @@ Sidekiq::Testing.fake! require 'minitest/reporters' Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({ color: true })] +require "stripe" + class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... @@ -16,6 +18,17 @@ class ActiveSupport::TestCase def json_response(body) JSON.parse(body, symbolize_names: true) end + + def stripe_card_token + Stripe::Token.create( + :card => { + :number => "4242424242424242", + :exp_month => 4, + :exp_year => DateTime.now.next_year.year, + :cvc => "314" + }, + ).id + end end class ActionDispatch::IntegrationTest