Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order Discount Breakdown #193

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ commands:
sudo apt-get update
sudo apt-get install -yq libvips-dev
- solidusio_extensions/test-branch:
branch: master
branch: main
command: |
export FRONTEND=starter
sudo gem update --system
Expand All @@ -33,26 +33,28 @@ jobs:
run-specs-with-postgres:
executor:
name: solidusio_extensions/postgres
ruby_version: '3.1'
ruby_version: '3.2'
steps:
- test-with-starter-frontend

run-specs-with-mysql:
executor:
name: solidusio_extensions/mysql
ruby_version: '3.0'
ruby_version: '3.1'
steps:
- test-with-starter-frontend

run-specs-with-sqlite:
executor:
name: solidusio_extensions/sqlite
ruby_version: '2.7'
ruby_version: '3.0'
steps:
- test-with-starter-frontend

lint-code:
executor: solidusio_extensions/sqlite-memory
executor:
name: solidusio_extensions/sqlite-memory
ruby_version: '3.0'
steps:
- solidusio_extensions/lint-code

Expand All @@ -64,14 +66,14 @@ workflows:
- run-specs-with-sqlite
- lint-code

"Weekly run specs against master":
"Weekly run specs against main":
triggers:
- schedule:
cron: "0 0 * * 4" # every Thursday
filters:
branches:
only:
- master
- main
jobs:
- run-specs-with-postgres
- run-specs-with-mysql
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:

AllCops:
NewCops: disable
TargetRubyVersion: '2.7'
TargetRubyVersion: '3.0'
Exclude:
- sandbox/**/*
- dummy-app/**/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def breakdown
item_total: price(@order.item_total),
shipping: price(@order.shipment_total),
tax_total: price(@order.additional_tax_total),
discount: price(@order.all_adjustments.promotion.sum(&:amount).abs)
discount: price(@order.promo_total.abs)
}
end

Expand Down
2 changes: 1 addition & 1 deletion bin/dummy-app
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ ! -d "dummy-app" ]; then
fi

cd ./dummy-app
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a'
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a'
unbundled bundle exec rake db:drop db:create
unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample "$@"
unbundled bundle add $extension_name --path ..
Expand Down
4 changes: 2 additions & 2 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ ! -z $SOLIDUS_BRANCH ]
then
BRANCH=$SOLIDUS_BRANCH
else
BRANCH="master"
BRANCH="main"
fi

extension_name="solidus_paypal_commerce_platform"
Expand All @@ -47,7 +47,7 @@ if [ ! -d "sandbox" ]; then
fi

cd ./sandbox
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a'
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a'
unbundled bundle exec rake db:drop db:create
unbundled bundle exec rails generate solidus:install --payment-method=none --auto-accept "$@"
unbundled bundle add ${extension_name} --path '../'
Expand Down
2 changes: 1 addition & 1 deletion solidus_paypal_commerce_platform.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_paypal_commerce_platform/releases'
spec.metadata['rubygems_mfa_required'] = 'true'

spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand Down
38 changes: 38 additions & 0 deletions spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@
)
end
end

context 'when an order has an inapplicable promo adjustment' do
let(:best_promotion) {
create(:promotion,
:with_line_item_adjustment,
:with_item_total_rule, adjustment_rate: 2.5, item_total_threshold_amount: 10,
apply_automatically: true,
promotion_actions: [
Spree::Promotion::Actions::CreateItemAdjustments.new(
calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
)
])
}

let(:worst_promotion) {
create(:promotion,
:with_line_item_adjustment,
:with_item_total_rule, adjustment_rate: 2.5, item_total_threshold_amount: 10,
apply_automatically: true,
promotion_actions: [
Spree::Promotion::Actions::CreateItemAdjustments.new(
calculator: Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 5)
)
])
}

before do
best_promotion.activate(order: order)
worst_promotion.activate(order: order)
order.recalculate
end

it 'does not include it in the paypal order breakdown' do
expect(to_json.dig(:purchase_units, 0).dig(:amount, :breakdown)).to match hash_including(
discount: { currency_code: "USD", value: "2.50" }
)
end
end
end

private
Expand Down