FIX: ordering
* Fix broken user id * ascending/descending
This commit is contained in:
parent
ca62cad04e
commit
18cf0e7f26
|
@ -12,9 +12,17 @@ module DiscoursePatrons
|
|||
|
||||
def payments_order
|
||||
if %w(created_at amount).include?(params[:order])
|
||||
params[:order].to_sym
|
||||
{ params[:order] => ascending }
|
||||
else
|
||||
:created_at
|
||||
{ created_at: :asc }
|
||||
end
|
||||
end
|
||||
|
||||
def ascending
|
||||
if params[:ascending] == 'false'
|
||||
:desc
|
||||
else
|
||||
:asc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ module DiscoursePatrons
|
|||
description: SiteSetting.discourse_patrons_payment_description,
|
||||
receipt_email: params[:receipt_email],
|
||||
confirm: true,
|
||||
customer: user_id
|
||||
metadata: { user_id: user_id }
|
||||
)
|
||||
|
||||
Payment.create(
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
export default Ember.Controller.extend({
|
||||
queryParams: ["order"],
|
||||
queryParams: ["order", "ascending"],
|
||||
order: null,
|
||||
ascending: true,
|
||||
|
||||
actions: {
|
||||
loadMore() {},
|
||||
|
||||
orderPayments(order) {
|
||||
if (order === this.get("order")) {
|
||||
this.toggleProperty("ascending");
|
||||
}
|
||||
|
||||
this.set("order", order);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,19 @@ export default Discourse.Route.extend({
|
|||
queryParams: {
|
||||
order: {
|
||||
refreshModel: true
|
||||
},
|
||||
ascending: {
|
||||
refreshModel: true
|
||||
}
|
||||
},
|
||||
|
||||
model(params) {
|
||||
return ajax("/patrons/admin", {
|
||||
method: "get",
|
||||
data: { order: params.order }
|
||||
data: {
|
||||
order: params.order,
|
||||
ascending: params.ascending
|
||||
}
|
||||
}).then(results => results);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
|
||||
{{#unless model.error}}
|
||||
<h3>{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}</h3>
|
||||
|
||||
<h3>{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}</h3>
|
||||
<p>
|
||||
{{cook-text siteSettings.discourse_patrons_success_page}}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{{cook-text siteSettings.discourse_patrons_success_page}}
|
||||
</p>
|
||||
|
||||
{{#if model}}
|
||||
<table>
|
||||
<tr>
|
||||
<td>{{i18n 'discourse_patrons.payment_intent_id'}}</td>
|
||||
|
@ -17,4 +16,4 @@
|
|||
<td>{{model.amount}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
|
|
|
@ -9,5 +9,9 @@ module DiscoursePatrons
|
|||
it 'is a subclass of AdminController' do
|
||||
expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true)
|
||||
end
|
||||
|
||||
# TODO: authenticate to test these
|
||||
it "is ascending"
|
||||
it "is has ordered by"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,13 +49,13 @@ module DiscoursePatrons
|
|||
|
||||
it 'allows admin to see receipts' do
|
||||
controller.expects(:current_user).returns(admin)
|
||||
::Stripe::PaymentIntent.expects(:retrieve).returns(customer: user.id)
|
||||
::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: user.id })
|
||||
get :show, params: { pid: '123' }, format: :json
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'does not allow another the user to see receipts' do
|
||||
::Stripe::PaymentIntent.expects(:retrieve).returns(customer: 9999)
|
||||
::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: 9999 })
|
||||
get :show, params: { pid: '123' }, format: :json
|
||||
|
||||
aggregate_failures do
|
||||
|
@ -85,7 +85,7 @@ module DiscoursePatrons
|
|||
amount: 9000,
|
||||
receipt_email: 'hello@example.com',
|
||||
currency: 'aud',
|
||||
customer: current_user.id
|
||||
metadata: { user_id: current_user.id }
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -134,8 +134,8 @@ module DiscoursePatrons
|
|||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'has the customer id' do
|
||||
::Stripe::PaymentIntent.expects(:create).with(has_entry(:customer, current_user.id)).returns(payment)
|
||||
it 'has the user id' do
|
||||
::Stripe::PaymentIntent.expects(:create).with(has_entry(:metadata, { user_id: current_user.id })).returns(payment)
|
||||
post :create, params: {}, format: :json
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue