Add comprehensive unit tests for all command handlers:
- TestHelperFunctions: is_group, get_group_id, get_user_id, get_room_id
- TestCmdBounty: lists bounties, handles empty
- TestCmdMy: shows tracked in groups, personal in DM
- TestCmdAdd: add bounty success, validation
- TestCmdUpdate: update bounty, permission denied, invalid ID
- TestCmdDelete: delete bounty, invalid ID
- TestCmdTrack: track in group, reject in DM
- TestCmdUntrack: untrack in group, reject in DM
- TestCmdStart: group vs DM behavior
- TestCmdHelp: shows all commands
Also fix conftest.py to remove obsolete fresh_db fixture
that referenced non-existent db module.
All 55 tests pass.
Addresses han's feedback on PR #33
- Add tests/test_json_file.py with unit tests for JsonFileRoomStorage and JsonFileTrackingStorage
- Reorganize data directories per han's feedback:
- Rooms: ~/.jigaido/data/room/<room_id>.json (was ~/.jigaido/data/<room_id>.json)
- Tracking: ~/.jigaido/data/tracking/<room_id>_<user_id>.json (was ~/.jigaido/tracking/...)
- Note: duplicate tracking is handled at TrackingService layer (returns False if already tracking), adapter allows duplicates by design
Implements RoomStorage and TrackingStorage ports using JSON file persistence:
- JsonFileRoomStorage: Stores room data at ~/.jigaido/data/<room_id>.json
- JsonFileTrackingStorage: Stores tracking data at ~/.jigaido/tracking/<room_id>_<user_id>.json
Features:
- Atomic writes using tempfile + rename for data safety
- Automatic directory creation
- Implements all methods from ports.py protocols
- Add BountyService for room bounty operations (group and personal)
- Add TrackingService for tracking bounty operations
- Uses RoomStorage and TrackingStorage ports
- PermissionError raised when non-creator edits/deletes
- ValueError raised when bounty not found in tracking
Add JsonFileRoomStorage and JsonFileTrackingStorage implementations
that implement the RoomStorage and TrackingStorage ports.
- Stores room data at ~/.jigaido/data/<room_id>.json
- Stores tracking data at ~/.jigaido/tracking/<room_id>_<user_id>.json
- Implements all port methods: load, save, add_bounty, update_bounty,
delete_bounty, get_bounty for rooms; load, save, track_bounty,
untrack_bounty for tracking
Fixes#9
Tests with SimpleRoomStorage and SimpleTrackingStorage (without ensure_*)
show that add_bounty() and track_bounty() work fine without explicit
ensure methods - they create rooms/tracking internally.
This simplifies the Protocol to only essential methods.
- Removed PersonalStorage (redundant - RoomStorage handles both via room_id)
- Added ensure_room() and ensure_tracking() methods for explicit creation
- Added @runtime_checkable to Protocols for isinstance checks
- Added tests/test_ports.py with 11 unit tests for storage protocols
- Bounty.created_by_user_id is now non-optional (always required)
- Removed is_group from RoomData (negative room_id is self-documenting)
- Added room_id to TrackedBounty to track which room bounty was tracked from
- Added clarifying docstrings explaining TrackingData vs TrackedBounty
- Updated tests to match new model structure
- Remove GroupBounty/PersonalBounty subclasses, use Bounty with optional created_by_user_id
- Combine UserData/GroupData into RoomData with room_id and is_group fields
- Add group_id field to TrackingData (supports negative Telegram group IDs)
- Add test_bounty_comparison_not_equal for verifying different bounties are not equal
- Update core/__init__.py exports
- Storage: Change from per-user to per-group JSON files
- Data location: ~/.jigaido/ instead of apps/telegram-bot/data/
- Group bounties: data/{group_id}/group.json
- User tracking: data/{group_id}/{user_id}.json
- Personal bounties: data/{user_id}/user.json
- Update commands.py for new storage model
- Update bot.py to remove admin handlers
- Update tests to reflect created_by_user_id field
- Update SPEC.md with new design
Addresses user feedback from issue #2
Changed from per-user flat files to group/DM directory structure:
- data/{group_id}/group.json — group bounties
- data/{group_id}/{user_id}.json — user tracking in group
- data/{user_id}/user.json — user personal bounties (DM)
- Groups isolated, no cross-group access
- Tracking is per-group-per-user
- Add storage.py with load_user(), save_user(), next_bounty_id()
- Rewrite commands.py to use JSON storage (simplified)
- Remove db.py, schema.sql, cron.py, test_db.py
- Update SPEC.md to reflect new architecture
- Admin model removed (anyone can add, creator only can edit/delete)
- No reminders in v1
db.py:
- Add conn.isolation_level = None to get_conn() — fixes row_factory +
autocommit conflict. row_factory disables implicit transactions,
so we need explicit autocommit mode.
- Remove all conn.commit() calls (unnecessary with autocommit)
pyproject.toml:
- Move pytest + pytest-asyncio to main dependencies (uv run pytest
uses ephemeral env with main deps only)
tests/test_db.py:
- Fix test_upsert_user_updates_username to not chain upsert_user()
calls in assert expressions (test isolation issue)
JIGAIDO is now a platform with apps/ as the container.
All telegram-bot files moved to apps/telegram-bot/:
- bot.py, commands.py, cron.py, db.py, schema.sql
- requirements.txt, .env.example, README.md
- Root now holds SPEC.md, README.md, CONTRIBUTING.md only.
Structure:
jigaido/
├── apps/
│ └── telegram-bot/
└── SPEC.md, README.md, CONTRIBUTING.md