"""Tests for slack-bot _handle_drop.""" from freezegun import freeze_time from shared.schedule import FALLBACK_EXTENSION # Monday 2026-06-01 08:00 ET — weekday, active shift is night. MON = "2026-06-01 12:00:00" def _register_on_monday(seed): """Alice (114) is registered and assigned the Monday night shift.""" seed.roster("114", "Alice", slack_user_id="U_ALICE") seed.weekly("Monday", "114", "Alice") @freeze_time(MON) def test_drop_today_marks_open_and_repoints_3cx( slackbot_app, schedule, seed, respond, client, routing_spy, text_of ): _register_on_monday(seed) slackbot_app._handle_drop( respond, schedule, "U_ALICE", "drop today", "C1", client, None ) assert schedule.get_override("2026-06-01")["extension"] == "OPEN" assert "dropped" in text_of(respond) # Today + active night shift → queue falls back. routing_spy.assert_called_once_with(FALLBACK_EXTENSION) client.chat_postMessage.assert_called_once() @freeze_time(MON) def test_drop_future_does_not_repoint_3cx( slackbot_app, schedule, seed, respond, client, routing_spy ): seed.roster("114", "Alice", slack_user_id="U_ALICE") seed.weekly("Tuesday", "114", "Alice") slackbot_app._handle_drop( respond, schedule, "U_ALICE", "drop tomorrow", "C1", client, None ) assert schedule.get_override("2026-06-02")["extension"] == "OPEN" routing_spy.assert_not_called() @freeze_time(MON) def test_drop_not_your_shift( slackbot_app, schedule, seed, respond, client, routing_spy, text_of ): seed.roster("114", "Alice", slack_user_id="U_ALICE") seed.weekly("Monday", "115", "Bob") # Bob is on shift, not Alice slackbot_app._handle_drop( respond, schedule, "U_ALICE", "drop today", "C1", client, None ) assert "not your shift" in text_of(respond).lower() routing_spy.assert_not_called() @freeze_time(MON) def test_drop_past_date(slackbot_app, schedule, seed, respond, client, text_of): _register_on_monday(seed) slackbot_app._handle_drop( respond, schedule, "U_ALICE", "drop 2026-05-01", "C1", client, None ) assert "past" in text_of(respond).lower() @freeze_time(MON) def test_drop_unregistered(slackbot_app, schedule, respond, client, text_of): slackbot_app._handle_drop( respond, schedule, "U_NOBODY", "drop today", "C1", client, None ) assert "not registered" in text_of(respond).lower() @freeze_time(MON) def test_drop_bad_date(slackbot_app, schedule, seed, respond, client, text_of): _register_on_monday(seed) slackbot_app._handle_drop( respond, schedule, "U_ALICE", "drop notaday", "C1", client, None ) assert "couldn't parse" in text_of(respond).lower() @freeze_time(MON) def test_drop_usage(slackbot_app, schedule, respond, client, text_of): slackbot_app._handle_drop(respond, schedule, "U_ALICE", "drop", "C1", client, None) assert "Usage" in text_of(respond)