Add #vouchers, return an array of voucher adjustments

This commit is contained in:
Gaetan Craig-Riou
2023-03-15 14:07:21 +11:00
committed by Maikel Linke
parent 9b680e1a92
commit 3ec58d8791
2 changed files with 21 additions and 0 deletions

View File

@@ -618,6 +618,10 @@ module Spree
end
end
def vouchers
adjustments.where(originator_type: 'Voucher')
end
private
def fee_handler

View File

@@ -1430,4 +1430,21 @@ describe Spree::Order do
end
end
end
describe "#vouchers" do
let(:voucher) { Voucher.create(code: 'new_code', enterprise: order.distributor) }
context "when no voucher adjustment" do
it 'returns an empty array' do
expect(order.vouchers).to eq([])
end
end
it "returns an array of voucher adjusment" do
order.save!
expected_adjustments = Array.new(2) { voucher.create_adjustment(voucher.code, order) }
expect(order.vouchers).to eq(expected_adjustments)
end
end
end