discourse-subscriptions/spec/requests/plans_controller_spec.rb

44 lines
1.5 KiB
Ruby
Raw Normal View History

2019-10-09 22:52:55 -04:00
# frozen_string_literal: true
require 'rails_helper'
2019-12-03 19:23:45 -05:00
module DiscourseSubscriptions
2019-10-09 22:52:55 -04:00
RSpec.describe PlansController do
let(:user) { Fabricate(:user) }
before do
sign_in(user)
end
2019-10-09 22:52:55 -04:00
describe "index" do
it "lists the active plans" do
::Stripe::Price.expects(:list).with(active: true)
2019-12-02 19:48:12 -05:00
get "/s/plans.json"
2019-10-09 22:52:55 -04:00
end
2019-10-31 19:18:57 -04:00
2019-11-04 00:37:21 -05:00
it "lists the active plans for a product" do
::Stripe::Price.expects(:list).with(active: true, product: 'prod_3765')
2019-12-02 19:48:12 -05:00
get "/s/plans.json", params: { product_id: 'prod_3765' }
2019-11-04 00:37:21 -05:00
end
2019-10-31 19:18:57 -04:00
it "orders and serialises the plans" do
::Stripe::Price.expects(:list).returns(
2019-10-31 19:18:57 -04: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-10-31 19:18:57 -04:00
]
2019-10-31 21:30:19 -04:00
)
2019-10-31 19:18:57 -04:00
2019-12-02 19:48:12 -05:00
get "/s/plans.json"
2019-10-31 19:18:57 -04: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-10-31 19:18:57 -04:00
])
end
2019-10-09 22:52:55 -04:00
end
end
end