user group specs. help page

This commit is contained in:
Rimian Perkins 2019-10-24 15:48:03 +11:00
parent 8650e6c236
commit eead6fd345
3 changed files with 48 additions and 26 deletions

View File

@ -6,28 +6,34 @@
{{/link-to}} {{/link-to}}
</p> </p>
<table class="table discourse-patrons-admin"> {{#if model}}
<thead> <table class="table discourse-patrons-admin">
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th> <thead>
<th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th> <th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
<th class="td-right">{{i18n 'discourse_patrons.admin.products.product.active'}}</th> <th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th>
<th></th> <th class="td-right">{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
</thead> <th></th>
{{#each model as |product|}} </thead>
<tr> {{#each model as |product|}}
<td>{{product.name}}</td> <tr>
<td>{{format-date product.createdFormatted}}</td> <td>{{product.name}}</td>
<td class="td-right">{{product.active}}</td> <td>{{format-date product.createdFormatted}}</td>
<td class="td-right"> <td class="td-right">{{product.active}}</td>
{{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}} <td class="td-right">
{{d-icon "far-edit"}} {{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}}
{{/link-to}} {{d-icon "far-edit"}}
{{d-button {{/link-to}}
action=(route-action "destroyProduct") {{d-button
actionParam=product action=(route-action "destroyProduct")
icon="trash-alt" actionParam=product
class="btn-danger btn no-text btn-icon"}} icon="trash-alt"
</td> class="btn-danger btn no-text btn-icon"}}
</tr> </td>
{{/each}} </tr>
</table> {{/each}}
</table>
{{else}}
<p>
{{i18n 'discourse_patrons.admin.products.product_help'}}
</p>
{{/if}}

View File

@ -76,6 +76,7 @@ en:
plan_help: Create a pricing plan to subscribe customers to this product plan_help: Create a pricing plan to subscribe customers to this product
active: Active active: Active
created_at: Created created_at: Created
product_help: Before cutomers can subscribe to your site, you need to create at least one product and an associated plan.
plans: plans:
title: Pricing Plans title: Pricing Plans
operations: operations:

View File

@ -27,12 +27,21 @@ module DiscoursePatrons
let(:group) { Fabricate(:group, name: group_name) } let(:group) { Fabricate(:group, name: group_name) }
context "unauthorized group" do context "unauthorized group" do
before do
::Stripe::Subscription.expects(:create).returns(status: 'active')
end
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' })
::Stripe::Subscription.expects(:create).returns(status: 'active')
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/patrons/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
::Stripe::Plan.expects(:retrieve).returns(metadata: { group_name: 'other' })
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
expect(user.groups).to be_empty
end
end end
context "plan has group in metadata" do context "plan has group in metadata" do
@ -46,6 +55,8 @@ module DiscoursePatrons
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/patrons/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
end end
it "adds the user to the group when the subscription is active" do it "adds the user to the group when the subscription is active" do
@ -54,6 +65,8 @@ module DiscoursePatrons
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/patrons/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
end end
it "adds the user to the group when the subscription is trialing" do it "adds the user to the group when the subscription is trialing" do
@ -62,6 +75,8 @@ module DiscoursePatrons
expect { expect {
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } post "/patrons/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
end end
end end
end end