Files
discourse-subscriptions/spec/requests/plans_controller_spec.rb
T

44 lines
1.5 KiB
Ruby
Raw Normal View History

2019-10-10 13:52:55 +11:00
# frozen_string_literal: true
require 'rails_helper'
2019-12-04 11:23:45 +11:00
module DiscourseSubscriptions
2019-10-10 13:52:55 +11:00
RSpec.describe PlansController do
let(:user) { Fabricate(:user) }
before do
sign_in(user)
end
2019-10-10 13:52:55 +11:00
describe "index" do
2019-10-24 10:39:10 +11:00
it "lists the active plans" do
::Stripe::Price.expects(:list).with(active: true)
2019-12-03 11:48:12 +11:00
get "/s/plans.json"
2019-10-10 13:52:55 +11:00
end
2019-11-01 10:18:57 +11:00
2019-11-04 16:37:21 +11:00
it "lists the active plans for a product" do
::Stripe::Price.expects(:list).with(active: true, product: 'prod_3765')
2019-12-03 11:48:12 +11:00
get "/s/plans.json", params: { product_id: 'prod_3765' }
2019-11-04 16:37:21 +11:00
end
2019-11-01 10:18:57 +11:00
it "orders and serialises the plans" do
::Stripe::Price.expects(:list).returns(
2019-11-01 10:18:57 +11:00
data: [
{ id: 'plan_id123', unit_amount: 1220, currency: 'aud', recurring: { interval: 'year' }, metadata: {} },
{ id: 'plan_id234', unit_amount: 1399, currency: 'usd', recurring: { interval: 'year' }, metadata: {} },
{ id: 'plan_id678', unit_amount: 1000, currency: 'aud', recurring: { interval: 'week' }, metadata: {} }
2019-11-01 10:18:57 +11:00
]
2019-11-01 12:30:19 +11:00
)
2019-11-01 10:18:57 +11:00
2019-12-03 11:48:12 +11:00
get "/s/plans.json"
2019-11-01 10:18:57 +11:00
2020-05-22 11:20:05 -05:00
expect(response.parsed_body).to eq([
{ "currency" => "aud", "id" => "plan_id123", "recurring" => { "interval" => "year" }, "unit_amount" => 1220 },
{ "currency" => "usd", "id" => "plan_id234", "recurring" => { "interval" => "year" }, "unit_amount" => 1399 },
{ "currency" => "aud", "id" => "plan_id678", "recurring" => { "interval" => "week" }, "unit_amount" => 1000 }
2019-11-01 10:18:57 +11:00
])
end
2019-10-10 13:52:55 +11:00
end
end
end