Files
firefrost-services/services/modpack-version-checker/tests/test_database.py
Claude (The Golden Chronicler #50) 04e9b407d5 feat: Migrate Arbiter and Modpack Version Checker to monorepo
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>
2026-03-31 21:52:42 +00:00

175 lines
5.1 KiB
Python

"""Tests for database.py."""
from datetime import datetime
import pytest
from modpack_checker.database import Database
# ---------------------------------------------------------------------------
# add_modpack
# ---------------------------------------------------------------------------
def test_add_modpack_returns_correct_fields(db):
mp = db.add_modpack(12345, "Test Pack")
assert mp.curseforge_id == 12345
assert mp.name == "Test Pack"
assert mp.current_version is None
assert mp.last_checked is None
assert mp.notification_enabled is True
def test_add_modpack_duplicate_raises(db):
db.add_modpack(12345, "Test Pack")
with pytest.raises(ValueError, match="already being tracked"):
db.add_modpack(12345, "Test Pack Again")
# ---------------------------------------------------------------------------
# remove_modpack
# ---------------------------------------------------------------------------
def test_remove_modpack_returns_true(db):
db.add_modpack(12345, "Test Pack")
assert db.remove_modpack(12345) is True
def test_remove_modpack_missing_returns_false(db):
assert db.remove_modpack(99999) is False
def test_remove_modpack_deletes_record(db):
db.add_modpack(12345, "Test Pack")
db.remove_modpack(12345)
assert db.get_modpack(12345) is None
# ---------------------------------------------------------------------------
# get_modpack
# ---------------------------------------------------------------------------
def test_get_modpack_found(db):
db.add_modpack(111, "Pack A")
mp = db.get_modpack(111)
assert mp is not None
assert mp.name == "Pack A"
def test_get_modpack_not_found(db):
assert db.get_modpack(999) is None
# ---------------------------------------------------------------------------
# get_all_modpacks
# ---------------------------------------------------------------------------
def test_get_all_modpacks_empty(db):
assert db.get_all_modpacks() == []
def test_get_all_modpacks_multiple(db):
db.add_modpack(1, "Pack A")
db.add_modpack(2, "Pack B")
db.add_modpack(3, "Pack C")
modpacks = db.get_all_modpacks()
assert len(modpacks) == 3
ids = {mp.curseforge_id for mp in modpacks}
assert ids == {1, 2, 3}
# ---------------------------------------------------------------------------
# update_version
# ---------------------------------------------------------------------------
def test_update_version_sets_fields(db):
db.add_modpack(12345, "Test Pack")
db.update_version(12345, "1.2.3", notification_sent=True)
mp = db.get_modpack(12345)
assert mp.current_version == "1.2.3"
assert mp.last_checked is not None
def test_update_version_nonexistent_raises(db):
with pytest.raises(ValueError, match="not found"):
db.update_version(99999, "1.0.0")
def test_update_version_multiple_times(db):
db.add_modpack(12345, "Test Pack")
db.update_version(12345, "1.0.0")
db.update_version(12345, "1.1.0")
mp = db.get_modpack(12345)
assert mp.current_version == "1.1.0"
# ---------------------------------------------------------------------------
# get_check_history
# ---------------------------------------------------------------------------
def test_check_history_newest_first(db):
db.add_modpack(12345, "Test Pack")
db.update_version(12345, "1.0.0", notification_sent=False)
db.update_version(12345, "1.1.0", notification_sent=True)
history = db.get_check_history(12345, limit=10)
assert len(history) == 2
assert history[0].version_found == "1.1.0"
assert history[0].notification_sent is True
assert history[1].version_found == "1.0.0"
def test_check_history_limit(db):
db.add_modpack(12345, "Test Pack")
for i in range(5):
db.update_version(12345, f"1.{i}.0")
history = db.get_check_history(12345, limit=3)
assert len(history) == 3
def test_check_history_missing_modpack(db):
assert db.get_check_history(99999) == []
# ---------------------------------------------------------------------------
# toggle_notifications
# ---------------------------------------------------------------------------
def test_toggle_notifications_disable(db):
db.add_modpack(12345, "Test Pack")
result = db.toggle_notifications(12345, False)
assert result is True
mp = db.get_modpack(12345)
assert mp.notification_enabled is False
def test_toggle_notifications_re_enable(db):
db.add_modpack(12345, "Test Pack")
db.toggle_notifications(12345, False)
db.toggle_notifications(12345, True)
assert db.get_modpack(12345).notification_enabled is True
def test_toggle_notifications_missing(db):
assert db.toggle_notifications(99999, True) is False
# ---------------------------------------------------------------------------
# cascade delete
# ---------------------------------------------------------------------------
def test_remove_modpack_also_removes_history(db):
db.add_modpack(12345, "Test Pack")
db.update_version(12345, "1.0.0")
db.update_version(12345, "1.1.0")
db.remove_modpack(12345)
# History should be gone (cascade delete)
assert db.get_check_history(12345) == []