spec unauthenticated plans request
This commit is contained in:
parent
8cc4f880eb
commit
321f6b8a71
|
@ -5,53 +5,93 @@ require 'rails_helper'
|
||||||
module DiscoursePatrons
|
module DiscoursePatrons
|
||||||
module Admin
|
module Admin
|
||||||
RSpec.describe PlansController do
|
RSpec.describe PlansController do
|
||||||
let(:admin) { Fabricate(:admin) }
|
it 'is a subclass of AdminController' do
|
||||||
|
expect(DiscoursePatrons::Admin::PlansController < ::Admin::AdminController).to eq(true)
|
||||||
before { sign_in(admin) }
|
|
||||||
|
|
||||||
xit 'is a subclass of AdminController' do
|
|
||||||
expect(DiscoursePatrons::Admin::PlansController < Admin::AdminController).to eq(true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "index" do
|
context 'not authenticated' do
|
||||||
it "is ok" do
|
describe "index" do
|
||||||
::Stripe::Plan.expects(:list)
|
it "does not get the plans" do
|
||||||
get "/patrons/admin/plans.json"
|
::Stripe::Plan.expects(:list).never
|
||||||
|
get "/patrons/admin/plans.json"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "not ok" do
|
||||||
|
get "/patrons/admin/plans.json"
|
||||||
|
expect(response.status).to eq 403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "create" do
|
||||||
|
it "does not create a plan" do
|
||||||
|
::Stripe::Plan.expects(:create).never
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is not ok" do
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' }
|
||||||
|
expect(response.status).to eq 403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "delete" do
|
||||||
|
it "does not delete a plan" do
|
||||||
|
::Stripe::Plan.expects(:delete).never
|
||||||
|
delete "/patrons/admin/plans/plan_12345.json"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is not ok" do
|
||||||
|
delete "/patrons/admin/plans/plan_12345.json"
|
||||||
|
expect(response.status).to eq 403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "create" do
|
context 'authenticated' do
|
||||||
it "creates a plan with a currency" do
|
let(:admin) { Fabricate(:admin) }
|
||||||
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
|
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
|
before { sign_in(admin) }
|
||||||
post "/patrons/admin/plans.json", params: {}
|
|
||||||
|
describe "index" do
|
||||||
|
it "is ok" do
|
||||||
|
::Stripe::Plan.expects(:list)
|
||||||
|
get "/patrons/admin/plans.json"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with an interval" do
|
describe "create" do
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
|
it "creates a plan with a currency" do
|
||||||
post "/patrons/admin/plans.json", params: { interval: 'week' }
|
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
|
||||||
|
post "/patrons/admin/plans.json", params: {}
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a plan with an interval" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
|
||||||
|
post "/patrons/admin/plans.json", params: { interval: 'week' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a plan with an amount" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
|
||||||
|
post "/patrons/admin/plans.json", params: { amount: '102' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a plan with a title" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(:product, name: 'Rick Astley'))
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a plan with an id" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(id: 'rick-astley'))
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with an amount" do
|
describe "delete" do
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
|
it "deletes a plan" do
|
||||||
post "/patrons/admin/plans.json", params: { amount: '102' }
|
::Stripe::Plan.expects(:delete).with('plan_12345')
|
||||||
end
|
delete "/patrons/admin/plans/plan_12345.json"
|
||||||
|
end
|
||||||
it "creates a plan with a title" do
|
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:product, name: 'Rick Astley'))
|
|
||||||
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates a plan with an id" do
|
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(id: 'rick-astley'))
|
|
||||||
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "delete" do
|
|
||||||
it "deletes a plan" do
|
|
||||||
::Stripe::Plan.expects(:delete).with('plan_12345')
|
|
||||||
delete "/patrons/admin/plans/plan_12345.json"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,8 @@ module DiscoursePatrons
|
||||||
|
|
||||||
before { sign_in(admin) }
|
before { sign_in(admin) }
|
||||||
|
|
||||||
xit 'is a subclass of AdminController' do
|
it 'is a subclass of AdminController' do
|
||||||
expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true)
|
expect(DiscoursePatrons::AdminController < ::Admin::AdminController).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is ok" do
|
it "is ok" do
|
||||||
|
|
|
@ -9,8 +9,8 @@ module DiscoursePatrons
|
||||||
|
|
||||||
before { sign_in(admin) }
|
before { sign_in(admin) }
|
||||||
|
|
||||||
xit 'is a subclass of AdminController' do
|
it 'is a subclass of AdminController' do
|
||||||
expect(DiscoursePatrons::SubscriptionsController < Admin::AdminController).to eq(true)
|
expect(DiscoursePatrons::SubscriptionsController < ::Admin::AdminController).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gets the empty subscriptions" do
|
it "gets the empty subscriptions" do
|
||||||
|
|
Loading…
Reference in New Issue