mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 21:53:11 +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.
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
"""Tests for slack-bot handle_pickup (interactive button)."""
|
|
|
|
from freezegun import freeze_time
|
|
|
|
MON = "2026-06-01 12:00:00"
|
|
|
|
|
|
def _body(action_id, user_id="U_ALICE", channel="C1"):
|
|
return {
|
|
"actions": [{"action_id": action_id}],
|
|
"user": {"id": user_id},
|
|
"channel": {"id": channel},
|
|
}
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_pickup_today_success(
|
|
slackbot_app, schedule, seed, respond, client, routing_spy
|
|
):
|
|
seed.roster("114", "Alice", slack_user_id="U_ALICE")
|
|
slackbot_app.handle_pickup(
|
|
_body("pickup_2026-06-01"), respond, client, schedule, None
|
|
)
|
|
assert schedule.get_override("2026-06-01")["extension"] == "114"
|
|
# Posted to channel and repointed (today + active night).
|
|
assert respond.call_args.kwargs.get("response_type") == "in_channel"
|
|
routing_spy.assert_called_once_with("114")
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_pickup_day_shift_action_id(slackbot_app, schedule, seed, respond, client):
|
|
seed.roster("200", "Alice", slack_user_id="U_ALICE")
|
|
slackbot_app.handle_pickup(
|
|
_body("pickup_2026-06-06_day"), respond, client, schedule, None
|
|
)
|
|
# Saturday day-shift override is stored under the -DAY SK.
|
|
assert schedule.get_override("2026-06-06", "day")["extension"] == "200"
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_pickup_past_shift_rejected(slackbot_app, schedule, seed, respond, client):
|
|
seed.roster("114", "Alice", slack_user_id="U_ALICE")
|
|
slackbot_app.handle_pickup(
|
|
_body("pickup_2026-05-01"), respond, client, schedule, None
|
|
)
|
|
client.chat_postEphemeral.assert_called_once()
|
|
assert "already passed" in client.chat_postEphemeral.call_args.kwargs["text"]
|
|
assert schedule.get_override("2026-05-01") is None
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_pickup_unregistered(slackbot_app, schedule, respond, client):
|
|
slackbot_app.handle_pickup(
|
|
_body("pickup_2026-06-03", user_id="U_NOBODY"), respond, client, schedule, None
|
|
)
|
|
assert (
|
|
"not registered" in client.chat_postEphemeral.call_args.kwargs["text"].lower()
|
|
)
|
|
|
|
|
|
@freeze_time(MON)
|
|
def test_pickup_already_taken(slackbot_app, schedule, seed, respond, client):
|
|
seed.roster("114", "Alice", slack_user_id="U_ALICE")
|
|
seed.override("2026-06-03", "115", "Bob") # already claimed
|
|
slackbot_app.handle_pickup(
|
|
_body("pickup_2026-06-03"), respond, client, schedule, None
|
|
)
|
|
assert (
|
|
"already picked up"
|
|
in client.chat_postEphemeral.call_args.kwargs["text"].lower()
|
|
)
|
|
# Bob keeps the shift.
|
|
assert schedule.get_override("2026-06-03")["extension"] == "115"
|