mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 18:23:12 +00:00
* Add pytest suite and wire it into CI 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 * Add least-privilege permissions block to CI workflow Resolves the CodeQL actions/missing-workflow-permissions alert: the CI workflow now restricts GITHUB_TOKEN to contents: read (it only checks out, lints, and runs tests). * Stop logging extension numbers in 3CX queue updates Resolves 3 high CodeQL py/clear-text-logging-sensitive-data alerts: the queue/ring-group forwarding logs no longer include the routed extension values (closed/holiday/extension). Non-sensitive context (resource id, queue number) is retained.
90 lines
3.6 KiB
Python
90 lines
3.6 KiB
Python
"""Tests for slack-bot _handle_admin."""
|
|
|
|
from freezegun import freeze_time
|
|
|
|
from shared.schedule import FALLBACK_EXTENSION
|
|
|
|
MON = "2026-06-01 12:00:00"
|
|
|
|
|
|
def _admin(slackbot_app, schedule, text, respond, client):
|
|
slackbot_app._handle_admin(respond, schedule, "U_ADMIN", text, True, client, None)
|
|
|
|
|
|
def test_non_admin_rejected(slackbot_app, schedule, respond, client, text_of):
|
|
slackbot_app._handle_admin(
|
|
respond, schedule, "U_USER", "admin open today", False, client, None
|
|
)
|
|
assert "restricted" in text_of(respond).lower()
|
|
|
|
|
|
def test_admin_help(slackbot_app, schedule, respond, client, text_of):
|
|
_admin(slackbot_app, schedule, "admin", respond, client)
|
|
assert "Admin Commands" in text_of(respond)
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_override(slackbot_app, schedule, seed, respond, client, routing_spy, text_of):
|
|
seed.roster("114", "Alice")
|
|
_admin(slackbot_app, schedule, "admin override today 114", respond, client)
|
|
assert schedule.get_override("2026-06-01")["extension"] == "114"
|
|
assert "Override set" in text_of(respond)
|
|
routing_spy.assert_called_once_with("114")
|
|
|
|
|
|
def test_override_unknown_extension(slackbot_app, schedule, respond, client, text_of):
|
|
_admin(slackbot_app, schedule, "admin override today 999", respond, client)
|
|
assert "not found" in text_of(respond).lower()
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_open(slackbot_app, schedule, seed, respond, client, routing_spy, text_of):
|
|
seed.weekly("Monday", "114", "Alice")
|
|
_admin(slackbot_app, schedule, "admin open today", respond, client)
|
|
assert schedule.get_override("2026-06-01")["extension"] == "OPEN"
|
|
assert "marked as open" in text_of(respond).lower()
|
|
routing_spy.assert_called_once_with(FALLBACK_EXTENSION)
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_clear(slackbot_app, schedule, seed, respond, client, routing_spy, text_of):
|
|
seed.override("2026-06-01", "115", "Bob")
|
|
_admin(slackbot_app, schedule, "admin clear today", respond, client)
|
|
assert schedule.get_override("2026-06-01") is None
|
|
assert "cleared" in text_of(respond).lower()
|
|
|
|
|
|
def test_roster_add(slackbot_app, schedule, respond, client, text_of):
|
|
_admin(slackbot_app, schedule, "admin roster add 116 New Person", respond, client)
|
|
assert schedule.get_employee_by_extension("116")["name"] == "New Person"
|
|
assert "Added" in text_of(respond)
|
|
|
|
|
|
def test_roster_add_duplicate(slackbot_app, schedule, seed, respond, client, text_of):
|
|
seed.roster("116", "Existing")
|
|
_admin(slackbot_app, schedule, "admin roster add 116 New Person", respond, client)
|
|
assert "already exists" in text_of(respond).lower()
|
|
|
|
|
|
def test_roster_remove(slackbot_app, schedule, seed, respond, client, text_of):
|
|
seed.roster("114", "Alice")
|
|
_admin(slackbot_app, schedule, "admin roster remove 114", respond, client)
|
|
assert schedule.get_employee_by_extension("114") is None
|
|
assert "Removed" in text_of(respond)
|
|
|
|
|
|
def test_roster_remove_unknown(slackbot_app, schedule, respond, client, text_of):
|
|
_admin(slackbot_app, schedule, "admin roster remove 999", respond, client)
|
|
assert "not found" in text_of(respond).lower()
|
|
|
|
|
|
def test_roster_rename(slackbot_app, schedule, seed, respond, client, text_of):
|
|
seed.roster("114", "Alice")
|
|
_admin(slackbot_app, schedule, "admin roster rename 114 Alicia", respond, client)
|
|
assert schedule.get_employee_by_extension("114")["name"] == "Alicia"
|
|
assert "Renamed" in text_of(respond)
|
|
|
|
|
|
def test_unknown_subcommand(slackbot_app, schedule, respond, client, text_of):
|
|
_admin(slackbot_app, schedule, "admin frobnicate", respond, client)
|
|
assert "Unknown admin command" in text_of(respond)
|