#The MIT License (MIT) # #Copyright (c) 2026 rick barrette # #Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. require File.expand_path('../test_helper', __dir__) class WeekTest < ActiveSupport::TestCase Week = RedmineQboBonus::Week def test_weeks_run_sunday_to_saturday week = Week.containing(Date.new(2026, 11, 18)) assert_equal Date.new(2026, 11, 15), week.start_date assert_equal Date.new(2026, 11, 21), week.end_date assert_equal week, Week.containing(Date.new(2026, 11, 15)) assert_equal week, Week.containing(Date.new(2026, 11, 21)) assert_equal week + 1, Week.containing(Date.new(2026, 11, 22)) end def test_named_by_the_iso_week_of_their_monday assert_equal '2026-47', Week.containing(Date.new(2026, 11, 18)).label assert_equal '2026-46', Week.containing(Date.new(2026, 11, 8)).label assert_equal '2026-53', Week.containing(Date.new(2026, 12, 31)).label assert_equal '2027-01', Week.containing(Date.new(2027, 1, 3)).label end def test_last_completed_week assert_equal Date.new(2026, 11, 8), Week.last_completed(Date.new(2026, 11, 16)).start_date assert_equal Date.new(2026, 11, 8), Week.last_completed(Date.new(2026, 11, 15)).start_date assert_equal Date.new(2026, 11, 15), Week.last_completed(Date.new(2026, 11, 22)).start_date end def test_completed_once_saturday_is_over week = Week.containing(Date.new(2026, 11, 18)) assert_not week.completed?(Date.new(2026, 11, 21)) assert week.completed?(Date.new(2026, 11, 22)) end def test_parse assert_equal Date.new(2026, 11, 15), Week.parse('2026-11-18').start_date assert_equal '2026-11-15', Week.parse('2026-11-15').to_param assert_nil Week.parse('nope') assert_nil Week.parse('2026-13-45') end def test_only_starts_on_sunday assert_raises(ArgumentError) { Week.new(Date.new(2026, 11, 16)) } end end