discourse-subscriptions/spec/requests/admin/subscriptions_controller_sp...

61 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-09 22:09:24 -04:00
# frozen_string_literal: true
require 'rails_helper'
module DiscoursePatrons
2019-10-09 22:52:55 -04:00
RSpec.describe Admin::SubscriptionsController do
it 'is a subclass of AdminController' do
expect(DiscoursePatrons::Admin::SubscriptionsController < ::Admin::AdminController).to eq(true)
end
2019-10-09 22:09:24 -04:00
2019-10-14 22:18:25 -04:00
context 'unauthenticated' do
it "does nothing" do
::Stripe::Subscription.expects(:list).never
get "/patrons/admin/subscriptions.json"
expect(response.status).to eq(403)
end
2019-11-13 18:51:04 -05:00
it "does not destroy a subscription" do
::Stripe::Subscription.expects(:delete).never
patch "/patrons/admin/subscriptions/sub_12345.json"
end
2019-10-14 22:18:25 -04:00
end
context 'authenticated' do
2019-11-28 04:44:38 -05:00
let(:user) { Fabricate(:user) }
2019-10-14 22:18:25 -04:00
let(:admin) { Fabricate(:admin) }
before { sign_in(admin) }
2019-11-13 18:51:04 -05:00
describe "index" do
it "gets the subscriptions and products" do
::Stripe::Subscription.expects(:list).with(expand: ['data.plan.product'])
2019-11-13 18:51:04 -05:00
get "/patrons/admin/subscriptions.json"
expect(response.status).to eq(200)
end
end
describe "destroy" do
2019-11-28 04:44:38 -05:00
before do
DiscoursePatrons::Customer.create(
user_id: user.id,
customer_id: 'c_123',
product_id: 'pr_34578'
)
end
it "deletes a customer" do
::Stripe::Subscription
.expects(:delete)
.with('sub_12345')
.returns(customer: 'c_123', plan: { product: { id: 'pr_34578' } })
expect {
delete "/patrons/admin/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1)
2019-11-13 18:51:04 -05:00
end
2019-10-14 22:18:25 -04:00
end
2019-10-09 22:09:24 -04:00
end
end
end