WHAT WAS DONE: - Migrated Arbiter (discord-oauth-arbiter) code to services/arbiter/ - Migrated Modpack Version Checker code to services/modpack-version-checker/ - Created .env.example for Arbiter with all required environment variables - Moved systemd service file to services/arbiter/deploy/ - Organized directory structure per Gemini monorepo recommendations WHY: - Consolidate all service code in one repository - Prepare for Gemini code review (Panel v1.12 compatibility check) - Enable service-prefixed Git tagging (arbiter-v2.1.0, modpack-v1.0.0) - Support npm workspaces for shared dependencies SERVICES MIGRATED: 1. Arbiter (Discord OAuth bot) - Originally written by Gemini + Claude - Full source code from ops-manual docs/implementation/ - Created comprehensive .env.example - Ready for Panel v1.12 compatibility verification 2. Modpack Version Checker (Python CLI tool) - Full source code from ops-manual docs/tasks/ - Written for Panel v1.11, needs Gemini review for v1.12 - Never had code review before STILL TODO: - Whitelist Manager - Pull from Billing VPS (38.68.14.188) - Currently deployed and running - Needs Panel v1.12 API compatibility fix (Task #86) - Requires SSH access to pull code NEXT STEPS: - Gemini code review for Panel v1.12 API compatibility - Create package.json for each service - Test npm workspaces integration - Deploy after verification FILES: - services/arbiter/ (25 new files, full application) - services/modpack-version-checker/ (21 new files, full application) Signed-off-by: The Golden Chronicler <claude@firefrostgaming.com>
84 lines
2.7 KiB
Python
84 lines
2.7 KiB
Python
"""Tests for notifier.py."""
|
|
|
|
import pytest
|
|
import responses as responses_lib
|
|
|
|
from modpack_checker.notifier import DiscordNotifier, NotificationError
|
|
|
|
WEBHOOK_URL = "https://discord.com/api/webhooks/123456/abcdef"
|
|
|
|
|
|
@pytest.fixture
|
|
def notifier():
|
|
return DiscordNotifier(WEBHOOK_URL, timeout=5)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# send_update
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_send_update_success(notifier):
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
|
# Should not raise
|
|
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_send_update_initial_version(notifier):
|
|
"""old_version=None should be handled gracefully."""
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
|
notifier.send_update("Test Pack", 12345, None, "1.0.0")
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_send_update_bad_response_raises(notifier):
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=400, body="Bad Request")
|
|
with pytest.raises(NotificationError, match="HTTP 400"):
|
|
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_send_update_unauthorized_raises(notifier):
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=401)
|
|
with pytest.raises(NotificationError):
|
|
notifier.send_update("Test Pack", 12345, "1.0.0", "1.1.0")
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# test
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_test_webhook_success(notifier):
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
|
notifier.test() # Should not raise
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_test_webhook_failure_raises(notifier):
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=404)
|
|
with pytest.raises(NotificationError):
|
|
notifier.test()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# embed structure
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@responses_lib.activate
|
|
def test_send_update_embed_contains_modpack_name(notifier):
|
|
"""Verify the correct embed payload is sent to Discord."""
|
|
responses_lib.add(responses_lib.POST, WEBHOOK_URL, status=204)
|
|
notifier.send_update("All The Mods 9", 238222, "0.2.0", "0.3.0")
|
|
|
|
assert len(responses_lib.calls) == 1
|
|
raw_body = responses_lib.calls[0].request.body
|
|
payload = raw_body.decode("utf-8") if isinstance(raw_body, bytes) else raw_body
|
|
assert "All The Mods 9" in payload
|
|
assert "238222" in payload
|
|
assert "0.3.0" in payload
|