mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
61 lines
2.1 KiB
Ruby
61 lines
2.1 KiB
Ruby
require "test_helper"
|
|
|
|
class PeriodTest < ActiveSupport::TestCase
|
|
test "raises validation error when start_date or end_date is missing" do
|
|
error = assert_raises(ActiveModel::ValidationError) do
|
|
Period.new(start_date: nil, end_date: nil)
|
|
end
|
|
|
|
assert_includes error.message, "Start date can't be blank"
|
|
assert_includes error.message, "End date can't be blank"
|
|
end
|
|
|
|
test "raises validation error when start_date is not before end_date" do
|
|
error = assert_raises(ActiveModel::ValidationError) do
|
|
Period.new(start_date: Date.current, end_date: Date.current - 1.day)
|
|
end
|
|
|
|
assert_includes error.message, "Start date must be before end date"
|
|
end
|
|
|
|
test "from_key returns period for valid key" do
|
|
period = Period.from_key("last_30_days")
|
|
assert_equal 30.days.ago.to_date, period.start_date
|
|
assert_equal Date.current, period.end_date
|
|
end
|
|
|
|
test "from_key with invalid key and fallback returns default period" do
|
|
period = Period.from_key("invalid_key", fallback: true)
|
|
assert_equal 30.days.ago.to_date, period.start_date
|
|
assert_equal Date.current, period.end_date
|
|
end
|
|
|
|
test "from_key with invalid key and no fallback raises error" do
|
|
assert_raises ArgumentError do
|
|
Period.from_key("invalid_key")
|
|
end
|
|
end
|
|
|
|
test "label returns correct label for known period" do
|
|
period = Period.from_key("last_30_days")
|
|
assert_equal "Last 30 Days", period.label
|
|
end
|
|
|
|
test "label returns Custom Period for unknown period" do
|
|
period = Period.new(start_date: Date.current - 15.days, end_date: Date.current)
|
|
assert_equal "Custom Period", period.label
|
|
end
|
|
|
|
test "comparison_label returns correct label for known period" do
|
|
period = Period.from_key("last_30_days")
|
|
assert_equal "vs. last month", period.comparison_label
|
|
end
|
|
|
|
test "comparison_label returns date range for unknown period" do
|
|
start_date = Date.current - 15.days
|
|
end_date = Date.current
|
|
period = Period.new(start_date: start_date, end_date: end_date)
|
|
expected = "#{start_date.strftime("%b %d, %Y")} to #{end_date.strftime("%b %d, %Y")}"
|
|
assert_equal expected, period.comparison_label
|
|
end
|
|
end
|