mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 18:23:12 +00:00
A user can no longer `/oncall drop` a shift inside the 24h window before it starts — inside that window coverage must be handed off via a verified swap (target accepts) or opened by an admin. - app.py: _within_drop_lock(date, shift_type) (24h before _shift_start); guard in _handle_drop after the ownership check. Admin `open` is a separate handler and is unaffected (bypasses the lock). - Removed the now-unreachable 3CX-repoint-on-drop branch: a same-day shift is always inside the lock, so a drop never reaches mark_open for today. - Help text + README note the 24h rule. - tests: rewritten test_handle_drop (outside/inside-24h per shift type, weekend day, admin bypass, plus the existing guard-precedence cases) and direct _shift_start/_shift_started/_within_drop_lock helper tests. 185 passed. Closes #84
91 lines
3.5 KiB
Python
91 lines
3.5 KiB
Python
"""Tests for slack-bot module-level helpers."""
|
|
|
|
from freezegun import freeze_time
|
|
|
|
# Monday 2026-06-01 08:00 ET → weekday, active shift is night.
|
|
MON = "2026-06-01 12:00:00"
|
|
SAT_DATE = "2026-06-06"
|
|
|
|
|
|
class TestShiftTiming:
|
|
def test_shift_start_weekday_night_is_5pm(self, slackbot_app):
|
|
assert slackbot_app._shift_start("2026-06-03", "night").hour == 17
|
|
|
|
def test_shift_start_weekend_day_is_8am(self, slackbot_app):
|
|
assert slackbot_app._shift_start("2026-06-06", "day").hour == 8
|
|
|
|
@freeze_time("2026-06-01 22:00:00") # 18:00 ET
|
|
def test_shift_started_true_after_start(self, slackbot_app):
|
|
assert slackbot_app._shift_started("2026-06-01", "night") is True
|
|
|
|
@freeze_time(MON) # 08:00 ET
|
|
def test_shift_started_false_before_start(self, slackbot_app):
|
|
assert slackbot_app._shift_started("2026-06-01", "night") is False
|
|
|
|
@freeze_time(MON)
|
|
def test_within_drop_lock_for_today(self, slackbot_app):
|
|
assert slackbot_app._within_drop_lock("2026-06-01", "night") is True
|
|
|
|
@freeze_time(MON) # tomorrow 17:00 is ~33h away
|
|
def test_not_within_lock_tomorrow_morning(self, slackbot_app):
|
|
assert slackbot_app._within_drop_lock("2026-06-02", "night") is False
|
|
|
|
@freeze_time("2026-06-01 22:00:00") # 18:00 ET, tomorrow 17:00 now <24h
|
|
def test_within_lock_once_under_24h(self, slackbot_app):
|
|
assert slackbot_app._within_drop_lock("2026-06-02", "night") is True
|
|
|
|
|
|
class TestIsToday:
|
|
@freeze_time(MON)
|
|
def test_true_for_today(self, slackbot_app):
|
|
assert slackbot_app.is_today("2026-06-01") is True
|
|
|
|
@freeze_time(MON)
|
|
def test_false_for_other_day(self, slackbot_app):
|
|
assert slackbot_app.is_today("2026-06-02") is False
|
|
|
|
|
|
class TestIsActiveShiftType:
|
|
@freeze_time(MON)
|
|
def test_weekday_active_is_night(self, slackbot_app):
|
|
assert slackbot_app._is_active_shift_type("night") is True
|
|
assert slackbot_app._is_active_shift_type("day") is False
|
|
|
|
|
|
class TestShiftTypeLabel:
|
|
def test_weekday_has_no_label(self, slackbot_app):
|
|
assert slackbot_app._shift_type_label("Wednesday", "night") == ""
|
|
|
|
def test_weekend_day(self, slackbot_app):
|
|
assert slackbot_app._shift_type_label("Saturday", "day") == " (Day)"
|
|
|
|
def test_weekend_night(self, slackbot_app):
|
|
assert slackbot_app._shift_type_label("Saturday", "night") == " (Night)"
|
|
|
|
|
|
class TestFindEmployeeShift:
|
|
def test_weekday_night_match(self, slackbot_app, schedule, seed):
|
|
seed.weekly("Wednesday", "114", "Alice")
|
|
found = slackbot_app._find_employee_shift(
|
|
schedule, "2026-06-03", "Wednesday", "114"
|
|
)
|
|
assert found == ("114", "Alice", "weekly", "night")
|
|
|
|
def test_weekend_day_match(self, slackbot_app, schedule, seed):
|
|
seed.weekly("Saturday", "200", "Alice", shift_type="day")
|
|
found = slackbot_app._find_employee_shift(schedule, SAT_DATE, "Saturday", "200")
|
|
assert found == ("200", "Alice", "weekly", "day")
|
|
|
|
def test_weekend_night_match(self, slackbot_app, schedule, seed):
|
|
seed.weekly("Saturday", "201", "Bob", shift_type="night")
|
|
found = slackbot_app._find_employee_shift(schedule, SAT_DATE, "Saturday", "201")
|
|
assert found == ("201", "Bob", "weekly", "night")
|
|
|
|
def test_not_assigned_returns_none(self, slackbot_app, schedule, seed):
|
|
seed.weekly("Wednesday", "114", "Alice")
|
|
assert (
|
|
slackbot_app._find_employee_shift(
|
|
schedule, "2026-06-03", "Wednesday", "999"
|
|
)
|
|
is None
|
|
)
|