do not override existing market records

pull/2345/head
Ayrat Badykov 5 years ago
parent 68a1409997
commit 380dd87fa3
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 2
      apps/explorer/lib/explorer/market/market.ex
  2. 10
      apps/explorer/test/explorer/market/market_test.exs

@ -45,7 +45,7 @@ defmodule Explorer.Market do
Decimal.equal?(item.closing_price, 0) && Decimal.equal?(item.opening_price, 0)
end)
Repo.insert_all(MarketHistory, records_without_zeroes, on_conflict: :replace_all, conflict_target: [:date])
Repo.insert_all(MarketHistory, records_without_zeroes, on_conflict: :nothing, conflict_target: [:date])
end
def add_price(%{symbol: symbol} = token) do

@ -91,9 +91,11 @@ defmodule Explorer.MarketTest do
assert fetched_record.opening_price == old_record.opening_price
end
test "overrides existing records on date conflict" do
test "does not override existing records on date conflict" do
date = ~D[2018-04-01]
Repo.insert(%MarketHistory{date: date})
{:ok, old_record} =
Repo.insert(%MarketHistory{date: date, closing_price: Decimal.new(2), opening_price: Decimal.new(2)})
new_record = %{
date: date,
@ -104,8 +106,8 @@ defmodule Explorer.MarketTest do
Market.bulk_insert_history([new_record])
fetched_record = Repo.get_by(MarketHistory, date: date)
assert fetched_record.closing_price == new_record.closing_price
assert fetched_record.opening_price == new_record.opening_price
assert fetched_record.closing_price == old_record.closing_price
assert fetched_record.opening_price == old_record.opening_price
end
end
end

Loading…
Cancel
Save