mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
basic subscription test
This commit is contained in:
parent
b6dcacaa8a
commit
76c70b0ed4
33
test/integration/subscriptions_test.rb
Normal file
33
test/integration/subscriptions_test.rb
Normal file
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user