1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00

Fix timezones in tests

This commit is contained in:
Zach Gollwitzer 2025-05-14 21:19:53 -04:00
parent 246343a4bf
commit 7d32423d8e
4 changed files with 47 additions and 47 deletions

View file

@ -15,8 +15,7 @@ class Balance::ForwardCalculatorTest < ActiveSupport::TestCase
test "balance generation respects user timezone and last generated date is current user date" do
# Simulate user in EST timezone
Time.zone = "America/New_York"
Time.use_zone("America/New_York") do
# Set current time to 1am UTC on Jan 5, 2025
# This would be 8pm EST on Jan 4, 2025 (user's time, and the last date we should generate balances for)
travel_to Time.utc(2025, 01, 05, 1, 0, 0)
@ -29,6 +28,7 @@ class Balance::ForwardCalculatorTest < ActiveSupport::TestCase
assert_equal expected, calculated.map { |b| [ b.date.to_s, b.balance ] }
end
end
# When syncing forwards, we don't care about the account balance. We generate everything based on entries, starting from 0.
test "no entries sync" do

View file

@ -25,8 +25,7 @@ class Balance::ReverseCalculatorTest < ActiveSupport::TestCase
test "balance generation respects user timezone and last generated date is current user date" do
# Simulate user in EST timezone
Time.zone = "America/New_York"
Time.use_zone("America/New_York") do
# Set current time to 1am UTC on Jan 5, 2025
# This would be 8pm EST on Jan 4, 2025 (user's time, and the last date we should generate balances for)
travel_to Time.utc(2025, 01, 05, 1, 0, 0)
@ -38,6 +37,7 @@ class Balance::ReverseCalculatorTest < ActiveSupport::TestCase
assert_equal expected, calculated.sort_by(&:date).map { |b| [ b.date.to_s, b.balance ] }
end
end
test "valuations sync" do
create_valuation(account: @account, date: 4.days.ago.to_date, amount: 17000)

View file

@ -20,8 +20,7 @@ class Holding::ForwardCalculatorTest < ActiveSupport::TestCase
test "holding generation respects user timezone and last generated date is current user date" do
# Simulate user in EST timezone
Time.zone = "America/New_York"
Time.use_zone("America/New_York") do
# Set current time to 1am UTC on Jan 5, 2025
# This would be 8pm EST on Jan 4, 2025 (user's time, and the last date we should generate holdings for)
travel_to Time.utc(2025, 01, 05, 1, 0, 0)
@ -37,6 +36,7 @@ class Holding::ForwardCalculatorTest < ActiveSupport::TestCase
assert_equal expected, calculated.map { |b| [ b.date.to_s, b.amount ] }
end
end
test "forward portfolio calculation" do
load_prices

View file

@ -20,8 +20,7 @@ class Holding::ReverseCalculatorTest < ActiveSupport::TestCase
test "holding generation respects user timezone and last generated date is current user date" do
# Simulate user in EST timezone
Time.zone = "America/New_York"
Time.use_zone("America/New_York") do
# Set current time to 1am UTC on Jan 5, 2025
# This would be 8pm EST on Jan 4, 2025 (user's time, and the last date we should generate holdings for)
travel_to Time.utc(2025, 01, 05, 1, 0, 0)
@ -41,6 +40,7 @@ class Holding::ReverseCalculatorTest < ActiveSupport::TestCase
assert_equal expected, calculated.sort_by(&:date).map { |b| [ b.date.to_s, b.amount ] }
end
end
# Should be able to handle this case, although we should not be reverse-syncing an account without provided current day holdings
test "reverse portfolio with trades but without current day holdings" do