Skip to content

Commit

Permalink
Add spec file for additional tax display. Add new trait for enterpris…
Browse files Browse the repository at this point in the history
…e fee and calculator factory #11680
  • Loading branch information
abdulazizali77 committed Jun 2, 2024
1 parent 54387a4 commit 1755726
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
transient { amount { 1 } }
calculator { build(:calculator_per_item, preferred_amount: amount) }
end

trait :flat_percent_per_item do
transient { amount { 1 } }
calculator { build(:calculator_flat_percent_per_item, preferred_flat_percent: amount) }
end
end

factory :adjustment_metadata, class: AdjustmentMetadata do
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/calculator_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
preferred_amount { generate(:calculator_amount) }
end

factory :calculator_flat_percent_per_item, class: Calculator::FlatPercentPerItem do
preferred_flat_percent { generate(:calculator_amount) }
end

factory :weight_calculator, class: Calculator::Weight do
after(:build) { |c|
c.set_preference(:per_unit, 0.5)
Expand Down
51 changes: 51 additions & 0 deletions spec/helpers/admin/orders_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,56 @@
expect(fake_adjustment.amount).to eq(-0.5)
end
end

context "with additional tax total" do
let!(:shipping_method){ create(:free_shipping_method) }
let!(:enterprise){
create(:distributor_enterprise_with_tax, name: 'Enterprise', charges_sales_tax: true,
shipping_methods: [shipping_method])
}
let!(:country_zone){ create(:zone_with_member) }
let!(:tax_category){ create(:tax_category, name: 'tax_category') }
let!(:tax_rate){
create(:tax_rate, zone: country_zone, tax_category:, name: 'Tax Rate', amount: 0.13,
included_in_price: false)
}
let!(:ship_address){ create(:ship_address) }
let!(:product) {
create(:simple_product, supplier: enterprise, price: 10, tax_category_id: tax_category.id)
}
let!(:variant){
create(:variant, :with_order_cycle, product:, distributor: enterprise, order_cycle:,
tax_category:)
}
let!(:coordinator_fees){
create(:enterprise_fee, :flat_percent_per_item, enterprise:, amount: 20,
name: 'Adminstration',
fee_type: 'sales',
tax_category:)
}
let!(:order_cycle){
create(:simple_order_cycle, name: "oc1", suppliers: [enterprise],
distributors: [enterprise],
coordinator_fees: [coordinator_fees])
}
let!(:order){
create(:order_with_distributor, distributor: enterprise, order_cycle:, ship_address:)
}
let!(:line_item) { create(:line_item, variant:, quantity: 1, price: 10, order:) }

before do
order_cycle.variants << [product.variants.first]
order_cycle.exchanges.outgoing.first.variants << product.variants.first

order.recreate_all_fees!
Orders::WorkflowService.new(order).complete!
end

it "includes tax for product and order" do
adjustment = order_adjustments_for_display(order).first
expect(adjustment.label).to eq("Tax Category")
expect(adjustment.amount).to eq(0.26)
end
end
end
end

0 comments on commit 1755726

Please sign in to comment.