fix paths in request specs

This commit is contained in:
Rimian Perkins 2019-12-03 11:48:12 +11:00
parent 949e32e4fb
commit a95c119bcf
10 changed files with 77 additions and 77 deletions

View File

@ -13,11 +13,11 @@ module DiscoursePatrons
describe "index" do describe "index" do
it "does not get the plans" do it "does not get the plans" do
::Stripe::Plan.expects(:list).never ::Stripe::Plan.expects(:list).never
get "/patrons/admin/plans.json" get "/s/admin/plans.json"
end end
it "not ok" do it "not ok" do
get "/patrons/admin/plans.json" get "/s/admin/plans.json"
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -25,11 +25,11 @@ module DiscoursePatrons
describe "create" do describe "create" do
it "does not create a plan" do it "does not create a plan" do
::Stripe::Plan.expects(:create).never ::Stripe::Plan.expects(:create).never
post "/patrons/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' } post "/s/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' }
end end
it "is not ok" do it "is not ok" do
post "/patrons/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' } post "/s/admin/plans.json", params: { name: 'Rick Astley', amount: 1, interval: 'week' }
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -37,11 +37,11 @@ module DiscoursePatrons
describe "show" do describe "show" do
it "does not show the plan" do it "does not show the plan" do
::Stripe::Plan.expects(:retrieve).never ::Stripe::Plan.expects(:retrieve).never
get "/patrons/admin/plans/plan_12345.json" get "/s/admin/plans/plan_12345.json"
end end
it "is not ok" do it "is not ok" do
get "/patrons/admin/plans/plan_12345.json" get "/s/admin/plans/plan_12345.json"
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -49,11 +49,11 @@ module DiscoursePatrons
describe "update" do describe "update" do
it "does not update a plan" do it "does not update a plan" do
::Stripe::Plan.expects(:update).never ::Stripe::Plan.expects(:update).never
delete "/patrons/admin/plans/plan_12345.json" delete "/s/admin/plans/plan_12345.json"
end end
it "is not ok" do it "is not ok" do
delete "/patrons/admin/plans/plan_12345.json" delete "/s/admin/plans/plan_12345.json"
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -61,11 +61,11 @@ module DiscoursePatrons
describe "delete" do describe "delete" do
it "does not delete a plan" do it "does not delete a plan" do
::Stripe::Plan.expects(:delete).never ::Stripe::Plan.expects(:delete).never
patch "/patrons/admin/plans/plan_12345.json" patch "/s/admin/plans/plan_12345.json"
end end
it "is not ok" do it "is not ok" do
patch "/patrons/admin/plans/plan_12345.json" patch "/s/admin/plans/plan_12345.json"
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -79,25 +79,25 @@ module DiscoursePatrons
describe "index" do describe "index" do
it "lists the plans" do it "lists the plans" do
::Stripe::Plan.expects(:list).with(nil) ::Stripe::Plan.expects(:list).with(nil)
get "/patrons/admin/plans.json" get "/s/admin/plans.json"
end end
it "lists the plans for the product" do it "lists the plans for the product" do
::Stripe::Plan.expects(:list).with(product: 'prod_id123') ::Stripe::Plan.expects(:list).with(product: 'prod_id123')
get "/patrons/admin/plans.json", params: { product_id: 'prod_id123' } get "/s/admin/plans.json", params: { product_id: 'prod_id123' }
end end
end end
describe "show" do describe "show" do
it "shows a plan" do it "shows a plan" do
::Stripe::Plan.expects(:retrieve).with('plan_12345').returns(currency: 'aud') ::Stripe::Plan.expects(:retrieve).with('plan_12345').returns(currency: 'aud')
get "/patrons/admin/plans/plan_12345.json" get "/s/admin/plans/plan_12345.json"
expect(response.status).to eq 200 expect(response.status).to eq 200
end end
it "upcases the currency" do it "upcases the currency" do
::Stripe::Plan.expects(:retrieve).with('plan_12345').returns(currency: 'aud') ::Stripe::Plan.expects(:retrieve).with('plan_12345').returns(currency: 'aud')
get "/patrons/admin/plans/plan_12345.json" get "/s/admin/plans/plan_12345.json"
expect(response.body).to eq '{"currency":"AUD"}' expect(response.body).to eq '{"currency":"AUD"}'
end end
end end
@ -105,56 +105,56 @@ module DiscoursePatrons
describe "create" do describe "create" do
it "creates a plan with a nickname" do it "creates a plan with a nickname" do
::Stripe::Plan.expects(:create).with(has_entry(:nickname, 'Veg')) ::Stripe::Plan.expects(:create).with(has_entry(:nickname, 'Veg'))
post "/patrons/admin/plans.json", params: { nickname: 'Veg', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { nickname: 'Veg', metadata: { group_name: '' } }
end end
it "creates a plan with a currency" do it "creates a plan with a currency" do
::Stripe::Plan.expects(:create).with(has_entry(:currency, 'AUD')) ::Stripe::Plan.expects(:create).with(has_entry(:currency, 'AUD'))
post "/patrons/admin/plans.json", params: { currency: 'AUD', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { currency: 'AUD', metadata: { group_name: '' } }
end end
it "creates a plan with an interval" do it "creates a plan with an interval" do
::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week')) ::Stripe::Plan.expects(:create).with(has_entry(:interval, 'week'))
post "/patrons/admin/plans.json", params: { interval: 'week', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { interval: 'week', metadata: { group_name: '' } }
end end
it "creates a plan with an amount" do it "creates a plan with an amount" do
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102')) ::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
post "/patrons/admin/plans.json", params: { amount: '102', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { amount: '102', metadata: { group_name: '' } }
end end
it "creates a plan with a trial period" do it "creates a plan with a trial period" do
::Stripe::Plan.expects(:create).with(has_entry(:trial_period_days, '14')) ::Stripe::Plan.expects(:create).with(has_entry(:trial_period_days, '14'))
post "/patrons/admin/plans.json", params: { trial_period_days: '14', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { trial_period_days: '14', metadata: { group_name: '' } }
end end
it "creates a plan with a product" do it "creates a plan with a product" do
::Stripe::Plan.expects(:create).with(has_entry(product: 'prod_walterwhite')) ::Stripe::Plan.expects(:create).with(has_entry(product: 'prod_walterwhite'))
post "/patrons/admin/plans.json", params: { product: 'prod_walterwhite', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { product: 'prod_walterwhite', metadata: { group_name: '' } }
end end
it "creates a plan with an active status" do it "creates a plan with an active status" do
::Stripe::Plan.expects(:create).with(has_entry(:active, 'false')) ::Stripe::Plan.expects(:create).with(has_entry(:active, 'false'))
post "/patrons/admin/plans.json", params: { active: 'false', metadata: { group_name: '' } } post "/s/admin/plans.json", params: { active: 'false', metadata: { group_name: '' } }
end end
it 'has a metadata' do it 'has a metadata' do
::Stripe::Plan.expects(:create).with(has_entry(metadata: { group_name: 'discourse-user-group-name' })) ::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' } } post "/s/admin/plans.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
end end
end end
describe "update" do describe "update" do
it "updates a plan" do it "updates a plan" do
::Stripe::Plan.expects(:update) ::Stripe::Plan.expects(:update)
patch "/patrons/admin/plans/plan_12345.json", params: { metadata: { group_name: 'discourse-user-group-name' } } patch "/s/admin/plans/plan_12345.json", params: { metadata: { group_name: 'discourse-user-group-name' } }
end end
end end
describe "delete" do describe "delete" do
it "deletes a plan" do it "deletes a plan" do
::Stripe::Plan.expects(:delete).with('plan_12345') ::Stripe::Plan.expects(:delete).with('plan_12345')
delete "/patrons/admin/plans/plan_12345.json" delete "/s/admin/plans/plan_12345.json"
end end
end end
end end

View File

@ -12,31 +12,31 @@ module DiscoursePatrons
context 'unauthenticated' do context 'unauthenticated' do
it "does not list the products" do it "does not list the products" do
::Stripe::Product.expects(:list).never ::Stripe::Product.expects(:list).never
get "/patrons/admin/products.json" get "/s/admin/products.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it "does not create the product" do it "does not create the product" do
::Stripe::Product.expects(:create).never ::Stripe::Product.expects(:create).never
post "/patrons/admin/products.json" post "/s/admin/products.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it "does not show the product" do it "does not show the product" do
::Stripe::Product.expects(:retrieve).never ::Stripe::Product.expects(:retrieve).never
get "/patrons/admin/products/prod_qwerty123.json" get "/s/admin/products/prod_qwerty123.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it "does not update the product" do it "does not update the product" do
::Stripe::Product.expects(:update).never ::Stripe::Product.expects(:update).never
put "/patrons/admin/products/prod_qwerty123.json" put "/s/admin/products/prod_qwerty123.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it "does not delete the product" do it "does not delete the product" do
::Stripe::Product.expects(:delete).never ::Stripe::Product.expects(:delete).never
delete "/patrons/admin/products/u2.json" delete "/s/admin/products/u2.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
end end
@ -49,60 +49,60 @@ module DiscoursePatrons
describe 'index' do describe 'index' do
it "gets the empty products" do it "gets the empty products" do
::Stripe::Product.expects(:list) ::Stripe::Product.expects(:list)
get "/patrons/admin/products.json" get "/s/admin/products.json"
end end
end end
describe 'create' do describe 'create' do
it 'is of product type service' do it 'is of product type service' do
::Stripe::Product.expects(:create).with(has_entry(:type, 'service')) ::Stripe::Product.expects(:create).with(has_entry(:type, 'service'))
post "/patrons/admin/products.json", params: {} post "/s/admin/products.json", params: {}
end end
it 'has a name' do it 'has a name' do
::Stripe::Product.expects(:create).with(has_entry(:name, 'Jesse Pinkman')) ::Stripe::Product.expects(:create).with(has_entry(:name, 'Jesse Pinkman'))
post "/patrons/admin/products.json", params: { name: 'Jesse Pinkman' } post "/s/admin/products.json", params: { name: 'Jesse Pinkman' }
end end
it 'has an active attribute' do it 'has an active attribute' do
::Stripe::Product.expects(:create).with(has_entry(active: 'false')) ::Stripe::Product.expects(:create).with(has_entry(active: 'false'))
post "/patrons/admin/products.json", params: { active: 'false' } post "/s/admin/products.json", params: { active: 'false' }
end end
it 'has a statement descriptor' do it 'has a statement descriptor' do
::Stripe::Product.expects(:create).with(has_entry(statement_descriptor: 'Blessed are the cheesemakers')) ::Stripe::Product.expects(:create).with(has_entry(statement_descriptor: 'Blessed are the cheesemakers'))
post "/patrons/admin/products.json", params: { statement_descriptor: 'Blessed are the cheesemakers' } post "/s/admin/products.json", params: { statement_descriptor: 'Blessed are the cheesemakers' }
end end
it 'has no statement descriptor if empty' do it 'has no statement descriptor if empty' do
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never ::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
post "/patrons/admin/products.json", params: { statement_descriptor: '' } post "/s/admin/products.json", params: { statement_descriptor: '' }
end end
it 'has a description' do it 'has a description' do
::Stripe::Product.expects(:create).with(has_entry(metadata: { description: 'Oi, I think he just said bless be all the bignoses!' })) ::Stripe::Product.expects(:create).with(has_entry(metadata: { description: 'Oi, I think he just said bless be all the bignoses!' }))
post "/patrons/admin/products.json", params: { metadata: { description: 'Oi, I think he just said bless be all the bignoses!' } } post "/s/admin/products.json", params: { metadata: { description: 'Oi, I think he just said bless be all the bignoses!' } }
end end
end end
describe 'show' do describe 'show' do
it 'retrieves the product' do it 'retrieves the product' do
::Stripe::Product.expects(:retrieve).with('prod_walterwhite') ::Stripe::Product.expects(:retrieve).with('prod_walterwhite')
get "/patrons/admin/products/prod_walterwhite.json" get "/s/admin/products/prod_walterwhite.json"
end end
end end
describe 'update' do describe 'update' do
it 'updates the product' do it 'updates the product' do
::Stripe::Product.expects(:update) ::Stripe::Product.expects(:update)
patch "/patrons/admin/products/prod_walterwhite.json", params: {} patch "/s/admin/products/prod_walterwhite.json", params: {}
end end
end end
describe 'delete' do describe 'delete' do
it 'deletes the product' do it 'deletes the product' do
::Stripe::Product.expects(:delete).with('prod_walterwhite') ::Stripe::Product.expects(:delete).with('prod_walterwhite')
delete "/patrons/admin/products/prod_walterwhite.json" delete "/s/admin/products/prod_walterwhite.json"
end end
end end
end end

View File

@ -11,13 +11,13 @@ module DiscoursePatrons
context 'unauthenticated' do context 'unauthenticated' do
it "does nothing" do it "does nothing" do
::Stripe::Subscription.expects(:list).never ::Stripe::Subscription.expects(:list).never
get "/patrons/admin/subscriptions.json" get "/s/admin/subscriptions.json"
expect(response.status).to eq(403) expect(response.status).to eq(403)
end end
it "does not destroy a subscription" do it "does not destroy a subscription" do
::Stripe::Subscription.expects(:delete).never ::Stripe::Subscription.expects(:delete).never
patch "/patrons/admin/subscriptions/sub_12345.json" patch "/s/admin/subscriptions/sub_12345.json"
end end
end end
@ -30,7 +30,7 @@ module DiscoursePatrons
describe "index" do describe "index" do
it "gets the subscriptions and products" do it "gets the subscriptions and products" do
::Stripe::Subscription.expects(:list).with(expand: ['data.plan.product']) ::Stripe::Subscription.expects(:list).with(expand: ['data.plan.product'])
get "/patrons/admin/subscriptions.json" get "/s/admin/subscriptions.json"
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
end end
@ -58,7 +58,7 @@ module DiscoursePatrons
) )
expect { expect {
delete "/patrons/admin/subscriptions/sub_12345.json" delete "/s/admin/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscoursePatrons::Customer.count }.by(-1)
end end
@ -72,7 +72,7 @@ module DiscoursePatrons
) )
expect { expect {
delete "/patrons/admin/subscriptions/sub_12345.json" delete "/s/admin/subscriptions/sub_12345.json"
}.to change { user.groups.count }.by(-1) }.to change { user.groups.count }.by(-1)
end end
@ -86,7 +86,7 @@ module DiscoursePatrons
) )
expect { expect {
delete "/patrons/admin/subscriptions/sub_12345.json" delete "/s/admin/subscriptions/sub_12345.json"
}.not_to change { user.groups.count } }.not_to change { user.groups.count }
end end
end end

View File

@ -14,7 +14,7 @@ module DiscoursePatrons
end end
it "is ok" do it "is ok" do
get "/patrons/admin.json" get "/s/admin.json"
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
end end

View File

@ -18,14 +18,14 @@ module DiscoursePatrons
source: 'tok_interesting' source: 'tok_interesting'
) )
post "/patrons/customers.json", params: { source: 'tok_interesting' } post "/s/customers.json", params: { source: 'tok_interesting' }
end end
it "saves the customer" do it "saves the customer" do
::Stripe::Customer.expects(:create).returns(id: 'cus_id23456') ::Stripe::Customer.expects(:create).returns(id: 'cus_id23456')
expect { expect {
post "/patrons/customers.json", params: { source: 'tok_interesting' } post "/s/customers.json", params: { source: 'tok_interesting' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscoursePatrons::Customer.count }
end end
end end

View File

@ -8,7 +8,7 @@ module DiscoursePatrons
describe "not authenticated" do describe "not authenticated" do
it "does not list the invoices" do it "does not list the invoices" do
::Stripe::Invoice.expects(:list).never ::Stripe::Invoice.expects(:list).never
get "/patrons/invoices.json" get "/s/invoices.json"
expect(response.status).to eq 403 expect(response.status).to eq 403
end end
end end
@ -24,7 +24,7 @@ module DiscoursePatrons
describe "other user invoices" do describe "other user invoices" do
it "does not list the invoices" do it "does not list the invoices" do
::Stripe::Invoice.expects(:list).never ::Stripe::Invoice.expects(:list).never
get "/patrons/invoices.json", params: { user_id: 999999 } get "/s/invoices.json", params: { user_id: 999999 }
end end
end end
@ -32,7 +32,7 @@ module DiscoursePatrons
context "stripe customer does not exist" do context "stripe customer does not exist" do
it "lists empty" do it "lists empty" do
::Stripe::Invoice.expects(:list).never ::Stripe::Invoice.expects(:list).never
get "/patrons/invoices.json", params: { user_id: user.id } get "/s/invoices.json", params: { user_id: user.id }
expect(response.body).to eq "[]" expect(response.body).to eq "[]"
end end
end end
@ -44,7 +44,7 @@ module DiscoursePatrons
it "lists the invoices" do it "lists the invoices" do
::Stripe::Invoice.expects(:list).with(customer: 'cus_id4567') ::Stripe::Invoice.expects(:list).with(customer: 'cus_id4567')
get "/patrons/invoices.json", params: { user_id: user.id } get "/s/invoices.json", params: { user_id: user.id }
end end
end end
end end

View File

@ -7,12 +7,12 @@ module DiscoursePatrons
describe "index" do describe "index" do
it "lists the active plans" do it "lists the active plans" do
::Stripe::Plan.expects(:list).with(active: true) ::Stripe::Plan.expects(:list).with(active: true)
get "/patrons/plans.json" get "/s/plans.json"
end end
it "lists the active plans for a product" do it "lists the active plans for a product" do
::Stripe::Plan.expects(:list).with(active: true, product: 'prod_3765') ::Stripe::Plan.expects(:list).with(active: true, product: 'prod_3765')
get "/patrons/plans.json", params: { product_id: 'prod_3765' } get "/s/plans.json", params: { product_id: 'prod_3765' }
end end
it "orders and serialises the plans" do it "orders and serialises the plans" do
@ -24,7 +24,7 @@ module DiscoursePatrons
] ]
) )
get "/patrons/plans.json" get "/s/plans.json"
expect(JSON.parse(response.body)).to eq([ expect(JSON.parse(response.body)).to eq([
{ "amount" => 1000, "currency" => "aud", "id" => "plan_id678", "interval" => "week" }, { "amount" => 1000, "currency" => "aud", "id" => "plan_id678", "interval" => "week" },

View File

@ -26,7 +26,7 @@ module DiscoursePatrons
it "gets products" do it "gets products" do
::Stripe::Product.expects(:list).with(active: true).returns(data: [product]) ::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/patrons/products.json" get "/s/products.json"
expect(JSON.parse(response.body)).to eq([{ expect(JSON.parse(response.body)).to eq([{
"id" => "prodct_23456", "id" => "prodct_23456",
@ -40,7 +40,7 @@ module DiscoursePatrons
::DiscoursePatrons::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x') ::DiscoursePatrons::Customer.create(product_id: product[:id], user_id: user.id, customer_id: 'x')
::Stripe::Product.expects(:list).with(active: true).returns(data: [product]) ::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/patrons/products.json" get "/s/products.json"
data = JSON.parse(response.body) data = JSON.parse(response.body)
expect(data.first["subscribed"]).to eq true expect(data.first["subscribed"]).to eq true
end end
@ -49,7 +49,7 @@ module DiscoursePatrons
::DiscoursePatrons::Customer.delete_all ::DiscoursePatrons::Customer.delete_all
::Stripe::Product.expects(:list).with(active: true).returns(data: [product]) ::Stripe::Product.expects(:list).with(active: true).returns(data: [product])
get "/patrons/products.json" get "/s/products.json"
data = JSON.parse(response.body) data = JSON.parse(response.body)
expect(data.first["subscribed"]).to eq false expect(data.first["subscribed"]).to eq false
end end
@ -58,7 +58,7 @@ module DiscoursePatrons
describe 'show' do describe 'show' do
it 'retrieves the product' do it 'retrieves the product' do
::Stripe::Product.expects(:retrieve).with('prod_walterwhite').returns(product) ::Stripe::Product.expects(:retrieve).with('prod_walterwhite').returns(product)
get "/patrons/products/prod_walterwhite.json" get "/s/products/prod_walterwhite.json"
expect(JSON.parse(response.body)).to eq( expect(JSON.parse(response.body)).to eq(
"id" => "prodct_23456", "id" => "prodct_23456",

View File

@ -8,7 +8,7 @@ module DiscoursePatrons
it "does not create a subscription" do it "does not create a subscription" do
::Stripe::Plan.expects(:retrieve).never ::Stripe::Plan.expects(:retrieve).never
::Stripe::Subscription.expects(:create).never ::Stripe::Subscription.expects(:create).never
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
end end
end end
@ -33,7 +33,7 @@ module DiscoursePatrons
).returns(status: 'active') ).returns(status: 'active')
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscoursePatrons::Customer.count }
end end
@ -42,7 +42,7 @@ module DiscoursePatrons
::Stripe::Subscription.expects(:create).returns(status: 'active') ::Stripe::Subscription.expects(:create).returns(status: 'active')
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { DiscoursePatrons::Customer.count } }.to change { DiscoursePatrons::Customer.count }
end end
end end
@ -58,13 +58,13 @@ module DiscoursePatrons
it "does not add the user to the admins group" do it "does not add the user to the admins group" do
::Stripe::Plan.expects(:retrieve).returns(metadata: { group_name: 'admins' }) ::Stripe::Plan.expects(:retrieve).returns(metadata: { group_name: 'admins' })
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
expect(user.admin).to eq false expect(user.admin).to eq false
end end
it "does not add the user to other group" do it "does not add the user to other group" do
::Stripe::Plan.expects(:retrieve).returns(metadata: { group_name: 'other' }) ::Stripe::Plan.expects(:retrieve).returns(metadata: { group_name: 'other' })
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
expect(user.groups).to be_empty expect(user.groups).to be_empty
end end
end end
@ -78,7 +78,7 @@ module DiscoursePatrons
::Stripe::Subscription.expects(:create).returns(status: 'failed') ::Stripe::Subscription.expects(:create).returns(status: 'failed')
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.not_to change { group.users.count } }.not_to change { group.users.count }
expect(user.groups).to be_empty expect(user.groups).to be_empty
@ -88,7 +88,7 @@ module DiscoursePatrons
::Stripe::Subscription.expects(:create).returns(status: 'active') ::Stripe::Subscription.expects(:create).returns(status: 'active')
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { group.users.count } }.to change { group.users.count }
expect(user.groups).not_to be_empty expect(user.groups).not_to be_empty
@ -98,7 +98,7 @@ module DiscoursePatrons
::Stripe::Subscription.expects(:create).returns(status: 'trialing') ::Stripe::Subscription.expects(:create).returns(status: 'trialing')
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/s/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
}.to change { group.users.count } }.to change { group.users.count }
expect(user.groups).not_to be_empty expect(user.groups).not_to be_empty

View File

@ -11,12 +11,12 @@ module DiscoursePatrons
context "not authenticated" do context "not authenticated" do
it "does not get the subscriptions" do it "does not get the subscriptions" do
::Stripe::Customer.expects(:list).never ::Stripe::Customer.expects(:list).never
get "/patrons/user/subscriptions.json" get "/s/user/subscriptions.json"
end end
it "does not destroy a subscription" do it "does not destroy a subscription" do
::Stripe::Subscription.expects(:delete).never ::Stripe::Subscription.expects(:delete).never
patch "/patrons/user/subscriptions/sub_12345.json" patch "/s/user/subscriptions/sub_12345.json"
end end
end end
@ -67,7 +67,7 @@ module DiscoursePatrons
expand: ['data.subscriptions'] expand: ['data.subscriptions']
).returns(customers) ).returns(customers)
get "/patrons/user/subscriptions.json" get "/s/user/subscriptions.json"
subscription = JSON.parse(response.body).first subscription = JSON.parse(response.body).first
@ -105,7 +105,7 @@ module DiscoursePatrons
.never .never
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.not_to change { DiscoursePatrons::Customer.count } }.not_to change { DiscoursePatrons::Customer.count }
expect(response.status).to eq 422 expect(response.status).to eq 422
@ -125,7 +125,7 @@ module DiscoursePatrons
.never .never
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.not_to change { DiscoursePatrons::Customer.count } }.not_to change { DiscoursePatrons::Customer.count }
expect(response.status).to eq 422 expect(response.status).to eq 422
@ -144,7 +144,7 @@ module DiscoursePatrons
.expects(:delete) .expects(:delete)
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { user.groups.count }.by(-1) }.to change { user.groups.count }.by(-1)
end end
@ -161,7 +161,7 @@ module DiscoursePatrons
.expects(:delete) .expects(:delete)
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.not_to change { user.groups.count } }.not_to change { user.groups.count }
end end
@ -179,7 +179,7 @@ module DiscoursePatrons
.with('sub_12345') .with('sub_12345')
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscoursePatrons::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200
@ -199,7 +199,7 @@ module DiscoursePatrons
.with('sub_12345') .with('sub_12345')
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscoursePatrons::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200
@ -219,7 +219,7 @@ module DiscoursePatrons
.with('sub_12345') .with('sub_12345')
expect { expect {
delete "/patrons/user/subscriptions/sub_12345.json" delete "/s/user/subscriptions/sub_12345.json"
}.to change { DiscoursePatrons::Customer.count }.by(-1) }.to change { DiscoursePatrons::Customer.count }.by(-1)
expect(response.status).to eq 200 expect(response.status).to eq 200