discourse-subscriptions/spec/requests/admin/plans_controller_spec.rb

151 lines
5.2 KiB
Ruby
Raw Normal View History

2019-10-09 21:08:52 -04:00
# frozen_string_literal: true
require 'rails_helper'
module DiscoursePatrons
module Admin
RSpec.describe PlansController do
2019-10-09 21:31:32 -04:00
it 'is a subclass of AdminController' do
expect(DiscoursePatrons::Admin::PlansController < ::Admin::AdminController).to eq(true)
2019-10-09 21:08:52 -04:00
end
2019-10-09 21:31:32 -04:00
context 'not authenticated' do
describe "index" do
it "does not get the plans" do
::Stripe::Plan.expects(:list).never
get "/patrons/admin/plans.json"
end
2019-10-09 21:08:52 -04:00
2019-10-09 21:31:32 -04:00
it "not ok" do
get "/patrons/admin/plans.json"
expect(response.status).to eq 403
end
2019-10-09 21:08:52 -04:00
end
2019-10-09 21:31:32 -04:00
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
2019-10-09 21:08:52 -04:00
end
2019-10-17 05:34:26 -04:00
describe "show" do
it "does not show the plan" do
::Stripe::Plan.expects(:retrieve).never
get "/patrons/admin/plans/plan_12345.json"
end
it "is not ok" do
get "/patrons/admin/plans/plan_12345.json"
expect(response.status).to eq 403
end
end
2019-10-23 00:55:06 -04:00
describe "update" do
it "does not update a plan" do
::Stripe::Plan.expects(:update).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
2019-10-09 21:31:32 -04:00
describe "delete" do
it "does not delete a plan" do
::Stripe::Plan.expects(:delete).never
2019-10-23 00:55:06 -04:00
patch "/patrons/admin/plans/plan_12345.json"
2019-10-09 21:31:32 -04:00
end
it "is not ok" do
2019-10-23 00:55:06 -04:00
patch "/patrons/admin/plans/plan_12345.json"
2019-10-09 21:31:32 -04:00
expect(response.status).to eq 403
end
2019-10-09 21:08:52 -04:00
end
2019-10-09 21:31:32 -04:00
end
2019-10-09 21:08:52 -04:00
2019-10-09 21:31:32 -04:00
context 'authenticated' do
let(:admin) { Fabricate(:admin) }
before { sign_in(admin) }
describe "index" do
2019-10-09 22:52:55 -04:00
it "lists the plans" do
2019-10-21 00:28:45 -04:00
::Stripe::Plan.expects(:list).with(nil)
2019-10-09 21:31:32 -04:00
get "/patrons/admin/plans.json"
end
2019-10-21 00:28:45 -04:00
it "lists the plans for the product" do
::Stripe::Plan.expects(:list).with(product: 'prod_id123')
get "/patrons/admin/plans.json", params: { product_id: 'prod_id123' }
end
2019-10-09 21:08:52 -04:00
end
2019-10-09 21:31:32 -04:00
describe "create" do
2019-10-17 05:34:26 -04:00
it "creates a plan with a nickname" do
::Stripe::Plan.expects(:create).with(has_entry(:nickname, 'Veg'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { nickname: 'Veg', metadata: { group_name: '' } }
2019-10-17 05:34:26 -04:00
end
2019-10-09 21:31:32 -04:00
it "creates a plan with a currency" do
SiteSetting.stubs(:discourse_patrons_currency).returns('aud')
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'aud'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { metadata: { group_name: '' } }
2019-10-09 21:31:32 -04:00
end
it "creates a plan with an interval" do
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { interval: 'week', metadata: { group_name: '' } }
2019-10-09 21:31:32 -04:00
end
it "creates a plan with an amount" do
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { amount: '102', metadata: { group_name: '' } }
2019-10-09 21:31:32 -04:00
end
2019-10-22 19:16:17 -04:00
it "creates a plan with a trial period" do
::Stripe::Plan.expects(:create).with(has_entry(:trial_period_days, '14'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { trial_period_days: '14', metadata: { group_name: '' } }
2019-10-22 19:16:17 -04:00
end
2019-10-16 21:07:06 -04:00
it "creates a plan with a product" do
2019-10-17 05:34:26 -04:00
::Stripe::Plan.expects(:create).with(has_entry(product: 'prod_walterwhite'))
2019-10-22 20:50:54 -04:00
post "/patrons/admin/plans.json", params: { product: 'prod_walterwhite', metadata: { group_name: '' } }
end
2019-10-23 19:02:31 -04:00
it "creates a plan with an active status" do
::Stripe::Plan.expects(:create).with(has_entry(:active, 'false'))
post "/patrons/admin/plans.json", params: { active: 'false', metadata: { group_name: '' } }
end
2019-10-22 20:50:54 -04:00
it 'has a metadata' do
::Stripe::Plan.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' }))
post "/patrons/admin/plans.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
2019-10-09 21:31:32 -04:00
end
2019-10-09 21:08:52 -04:00
end
2019-10-23 00:55:06 -04:00
describe "update" do
it "updates a plan" do
::Stripe::Plan.expects(:update)
patch "/patrons/admin/plans/plan_12345.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
end
end
2019-10-09 21:31:32 -04:00
describe "delete" do
it "deletes a plan" do
::Stripe::Plan.expects(:delete).with('plan_12345')
delete "/patrons/admin/plans/plan_12345.json"
end
2019-10-09 21:08:52 -04:00
end
end
end
end
end