This assessment is created with Ruby 3 and Rails 6.1.
Seed files are created to populate initial data for testing purposes
rails db:create db:migrate db:seed
rspec spec/
- The code was designed to record computed discount amounts instead of subtracting it from the regular price of products. Considering that a storefront needs this data to:
- Generate reports for total discount given to customers
- Record sales discount entry for accounting purposes.
- Needed data to come up with the Cost of Goods Sold in order for the store front to know their income for a processed order.
-
'gem money-rails' was used to handle all money calculations
-
Service Objects area created to implement the complex discounting rules and calculation of discount amount.
The following models area created to represent the different discounting rules.
Enable bulk discount rules for products. When customers reach a certain minimum purchase quantity, a bulk discount rule will effect on their purchase.
To run the test for this rule:
rspec spec/services/checkout/discounts/apply_bulk_discount_spec.rb
A free item can be bundled to a product during a purchase.
To run the test for this rule:
rspec spec/services/checkout/discounts/apply_freebie_spec.rb
Example. 3 for 2 deal on Apple TVs.
To run the test for this rule:
rspec spec/services/checkout/discounts/apply_x_for_y_discount_spec.rb