mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 14:53:12 +00:00
Stands up the first automated tests for the repo (151 tests) and turns on the CI test step. - Lift slack-bot handlers out of create_app() closures to module level so they're unit-testable; create_app is now a thin Bolt-wiring layer. No behavior change (handler entrypoints and create_app signature unchanged). - tests/ mirrors src/: shared layer (schedule, blocks, 3CX client, ring_scheduler, secrets) + all four Lambdas (pay math, drop/swap/pick/ admin/register/rate, pickup button, roster sync, queue scheduler). - All boundaries mocked: DynamoDB/SES/Secrets via moto, 3CX HTTP via responses, Slack via fakes, time via freezegun. No real network/AWS. - pyproject.toml pytest config (pythonpath=src/shared, importlib mode); per-package conftest loads each app.py under a unique name to avoid the four-app.py collision. tests/requirements.txt for test-only deps. - ci.yaml: run-tests: true (reusable workflow auto-installs deps) and lint the tests dir too. - README Testing section. Closes #85
63 lines
2.3 KiB
Python
63 lines
2.3 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 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
|
|
)
|