Skip to content

Commit

Permalink
Change time_promotion_discount column type from decimal to jsonb
Browse files Browse the repository at this point in the history
  • Loading branch information
marlena-b committed Jan 21, 2025
1 parent 911c3b0 commit fd4d273
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def call(event)
return unless event.data.fetch(:type) == Pricing::Discounts::TIME_PROMOTION_DISCOUNT

order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id))
order.time_promotion_discount = event.data.fetch(:amount)
order.time_promotion_discount = { discount_value: event.data.fetch(:amount).to_f, type: Pricing::Discounts::TIME_PROMOTION_DISCOUNT }
order.save!
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def general_discount_row(order)
def time_promotion_row(order)
tr class: "border-t" do
td(class: "py-2", colspan: 3) { "Time promotion discount" }
td(class: "py-2 text-right") { "#{order.time_promotion_discount}%" }
td(class: "py-2 text-right") { "#{order.time_promotion_discount["discount_value"]}%" }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddTimePromotionDiscountToClientOrders < ActiveRecord::Migration[7.2]
def change
add_column :client_orders, :time_promotion_discount, :decimal, precision: 8, scale: 2
add_column :client_orders, :time_promotion_discount, :jsonb
end
end
2 changes: 1 addition & 1 deletion rails_application/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
t.decimal "percentage_discount", precision: 8, scale: 2
t.decimal "total_value", precision: 8, scale: 2
t.decimal "discounted_value", precision: 8, scale: 2
t.decimal "time_promotion_discount", precision: 8, scale: 2
t.jsonb "time_promotion_discount"
end

create_table "clients", force: :cascade do |t|
Expand Down
3 changes: 2 additions & 1 deletion rails_application/test/client_orders/discount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def test_does_not_remove_time_promotion_when_removing_percentage_discount
assert_equal(50, order.total_value)
assert_equal(25, order.discounted_value)
assert_nil(order.percentage_discount)
assert_equal(50, order.time_promotion_discount)
assert_equal(50, order.time_promotion_discount["discount_value"])
assert_equal("time_promotion_discount", order.time_promotion_discount["type"])
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def test_time_promotion_set
order = ClientOrders::Order.find_by(order_uid: order_id)
assert_equal 50, order.total_value
assert_equal 25, order.discounted_value
assert_equal 50, order.time_promotion_discount
assert_equal 50, order.time_promotion_discount["discount_value"]
assert_equal "time_promotion_discount", order.time_promotion_discount["type"]
assert_nil order.percentage_discount
end

Expand Down

0 comments on commit fd4d273

Please sign in to comment.