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
|
2020-07-06 12:11:04 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2019-10-09 22:52:55 -04:00
|
|
|
describe "index" do
|
2019-10-23 19:39:10 -04:00
|
|
|
it "lists the active plans" do
|
2020-07-15 09:44:40 -04:00
|
|
|
::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
|
2020-07-15 09:44:40 -04:00
|
|
|
::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
|
2020-07-15 09:44:40 -04:00
|
|
|
::Stripe::Price.expects(:list).returns(
|
2019-10-31 19:18:57 -04:00
|
|
|
data: [
|
2020-07-15 09:44:40 -04:00
|
|
|
{ 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
|
|
|
|
2020-05-22 12:20:05 -04:00
|
|
|
expect(response.parsed_body).to eq([
|
2020-07-15 09:44:40 -04:00
|
|
|
{ "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
|