mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
(bug) store: admins cant order free carts for themselves
This commit is contained in:
parent
9b4c47d733
commit
ccd3899ebc
@ -4,6 +4,7 @@
|
||||
- Keep usage history of prepaid packs
|
||||
- OpenAPI reservation endpoint can be filtered by date
|
||||
- OpenAPI users endpoint now returns the ID of the InvoicingProfile
|
||||
- Fix a bug: privileged users cannot order free carts for themselves in the store
|
||||
- Fix a bug: wrong counting of minutes used when using a prepaid pack
|
||||
- Fix a bug: empty advanced accounting code is not defaulted to the general setting
|
||||
- Fix a bug: invalid style in accounting codes settings
|
||||
|
@ -17,7 +17,7 @@ class Checkout::PaymentService
|
||||
|
||||
CouponService.new.validate(coupon_code, order.statistic_profile.user.id)
|
||||
|
||||
amount = debit_amount(order)
|
||||
amount = debit_amount(order, coupon_code)
|
||||
if (operator.privileged? && operator != order.statistic_profile.user) || amount.zero?
|
||||
Payments::LocalService.new.payment(order, coupon_code)
|
||||
elsif Stripe::Helper.enabled? && payment_id.present?
|
||||
|
8
test/fixtures/coupons.yml
vendored
8
test/fixtures/coupons.yml
vendored
@ -47,3 +47,11 @@ twentyp:
|
||||
updated_at: '2021-06-18 14:53:54.770895'
|
||||
validity_per_user: forever
|
||||
amount_off:
|
||||
internal:
|
||||
name: Internal use
|
||||
code: INTERNCOUP100
|
||||
percent_off: 100
|
||||
valid_until:
|
||||
max_usages:
|
||||
active: true
|
||||
validity_per_user: forever
|
||||
|
@ -206,4 +206,51 @@ class Store::AdminOrderForHimselfTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_equal 403, response.status
|
||||
end
|
||||
|
||||
test 'admin pay a free order with success' do
|
||||
login_as(@admin, scope: :user)
|
||||
|
||||
invoice_count = Invoice.count
|
||||
invoice_items_count = InvoiceItem.count
|
||||
|
||||
post '/api/checkout/payment',
|
||||
params: {
|
||||
coupon_code: 'INTERNCOUP100',
|
||||
order_token: @cart1.token,
|
||||
customer_id: @admin.id
|
||||
}.to_json, headers: default_headers
|
||||
|
||||
@cart1.reload
|
||||
|
||||
# general assertions
|
||||
assert_equal 200, response.status
|
||||
assert_equal invoice_count + 1, Invoice.count
|
||||
assert_equal invoice_items_count + 2, InvoiceItem.count
|
||||
|
||||
# invoice_items assertions
|
||||
invoice_item = InvoiceItem.last
|
||||
|
||||
assert invoice_item.check_footprint
|
||||
|
||||
# invoice assertions
|
||||
invoice = Invoice.last
|
||||
assert_invoice_pdf invoice
|
||||
assert_not_nil invoice.debug_footprint
|
||||
|
||||
assert @cart1.payment_gateway_object.blank?
|
||||
assert invoice.payment_gateway_object.blank?
|
||||
assert invoice.total.zero?
|
||||
assert invoice.check_footprint
|
||||
|
||||
# notification
|
||||
assert_not_empty Notification.where(attached_object: invoice)
|
||||
|
||||
assert_equal 'paid', @cart1.state
|
||||
assert_equal 'local', @cart1.payment_method
|
||||
assert_equal 0, @cart1.paid_total
|
||||
|
||||
activity = @cart1.order_activities.last
|
||||
assert_equal 'paid', activity.activity_type
|
||||
assert_equal @admin.invoicing_profile.id, activity.operator_profile_id
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user