discourse-subscriptions/spec/requests/plans_controller_spec.rb

38 lines
1.3 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
describe "index" do
it "lists the active plans" do
::Stripe::Plan.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::Plan.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
2019-10-31 21:30:19 -04:00
::Stripe::Plan.expects(:list).returns(
2019-10-31 19:18:57 -04:00
data: [
{ id: 'plan_id123', amount: 1220, currency: 'aud', interval: 'year', metadata: {} },
{ id: 'plan_id234', amount: 1399, currency: 'usd', interval: 'year', metadata: {} },
{ id: 'plan_id678', amount: 1000, currency: 'aud', interval: 'week', metadata: {} }
]
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(JSON.parse(response.body)).to eq([
2019-10-31 19:50:34 -04:00
{ "amount" => 1000, "currency" => "aud", "id" => "plan_id678", "interval" => "week" },
{ "amount" => 1220, "currency" => "aud", "id" => "plan_id123", "interval" => "year" },
{ "amount" => 1399, "currency" => "usd", "id" => "plan_id234", "interval" => "year" }
2019-10-31 19:18:57 -04:00
])
end
2019-10-09 22:52:55 -04:00
end
end
end