Add tests for all TODOs / implement missing tests #423

Open
opened 2025-03-17 18:31:37 +00:00 by Vylpes · 0 comments
Owner

Epic:
Story Points: 8


There are TODOs in the codebase for missing tests. This issue collects those TODOs and implements the missing tests so the project has reliable unit and integration coverage for Card Drop's core behaviors.

Why

  • Prevent regressions for core functionality (card selection, drop lifecycle, claiming, DB reads/writes).
  • Make future refactors safer and faster to validate.
  • Provide a clear set of test patterns for contributors.

Scope

  • Find all TODO test comments in repo and either implement tests or convert them into tracked follow-up issues if they require broader design work.
  • Add unit tests for the pure logic (weight selection, card picking, timers).
  • Add integration tests for the drop lifecycle and command handlers using mocked Discord.js client and a test DB (in-memory or docker test DB).
  • Add tests for database model behaviors, migrations and seed data where applicable.

Acceptance Criteria

  • All "TODO: test" comments resolved (either implemented or converted to a follow-up issue with details).
  • Unit tests for card-selection / weighting logic exist and cover the probability/edge cases.
  • Tests for the drop lifecycle: create drop, owner 5-minute exclusive claim, expiry to public claim, and re-drop behavior.
  • Tests for claim permissions and edge cases (user already owns card, concurrent claims).
  • Database model tests for create/read/update/delete operations required by drops and user inventory.
  • Tests are runnable with yarn test (or documented command) and pass locally in CI.
  • Test scaffolding / examples included to help contributors write future tests.

Subtasks

  • Search repo for TODO test comments and list them (file + line + short description).
  • Add unit test for weight-based card selection (covering several weight distributions).
  • Add unit tests for the random card generator and card type boundaries (Bronze/Silver/Gold).
  • Add unit tests for timer logic (owner-only 5-minute window → public after expire).
  • Add integration test for drop command handler with mocked Discord.js (simulate message/interaction flows).
  • Add database tests (use sqlite in-memory or test Postgres) for models used by drops and claims.
  • Add CI job (if missing) or update existing CI to run tests and fail on regressions.
  • Update README with test run instructions and conventions.

Notes

  • Test framework: Jest with ts-jest (common for TypeScript + Node). If project already uses a different framework, follow existing conventions.
  • For Discord.js interactions, stub/mocking approaches:
    • Use jest mocks for discord.js Client, Message, Interaction, and MessageEmbed classes.
    • Consider using a test utility to create lightweight fake Interaction/Message objects with only the fields handlers expect.
  • For database:
    • Use sqlite in-memory where possible or a test Postgres instance in CI.
    • If current project uses TypeORM/Sequelize/Prisma, use their recommended testing setup (transaction rollback per test or test DB per run).
  • Test locations: use tests/ or tests directories, mirror source structure (src/commands/drop.test.ts, src/lib/weightSelector.test.ts, etc).
  • Coverage: aim to add tests for the most critical flows first (drop/claim/timer/weights). Increasing overall coverage can be iterative.
Epic: \ Story Points: 8 --- There are TODOs in the codebase for missing tests. This issue collects those TODOs and implements the missing tests so the project has reliable unit and integration coverage for Card Drop's core behaviors. ### Why - Prevent regressions for core functionality (card selection, drop lifecycle, claiming, DB reads/writes). - Make future refactors safer and faster to validate. - Provide a clear set of test patterns for contributors. ### Scope - Find all TODO test comments in repo and either implement tests or convert them into tracked follow-up issues if they require broader design work. - Add unit tests for the pure logic (weight selection, card picking, timers). - Add integration tests for the drop lifecycle and command handlers using mocked Discord.js client and a test DB (in-memory or docker test DB). - Add tests for database model behaviors, migrations and seed data where applicable. ## Acceptance Criteria - [ ] All "TODO: test" comments resolved (either implemented or converted to a follow-up issue with details). - [ ] Unit tests for card-selection / weighting logic exist and cover the probability/edge cases. - [ ] Tests for the drop lifecycle: create drop, owner 5-minute exclusive claim, expiry to public claim, and re-drop behavior. - [ ] Tests for claim permissions and edge cases (user already owns card, concurrent claims). - [ ] Database model tests for create/read/update/delete operations required by drops and user inventory. - [ ] Tests are runnable with yarn test (or documented command) and pass locally in CI. - [ ] Test scaffolding / examples included to help contributors write future tests. ## Subtasks - [ ] Search repo for TODO test comments and list them (file + line + short description). - [ ] Add unit test for weight-based card selection (covering several weight distributions). - [ ] Add unit tests for the random card generator and card type boundaries (Bronze/Silver/Gold). - [ ] Add unit tests for timer logic (owner-only 5-minute window → public after expire). - [ ] Add integration test for drop command handler with mocked Discord.js (simulate message/interaction flows). - [ ] Add database tests (use sqlite in-memory or test Postgres) for models used by drops and claims. - [ ] Add CI job (if missing) or update existing CI to run tests and fail on regressions. - [ ] Update README with test run instructions and conventions. ## Notes - Test framework: Jest with ts-jest (common for TypeScript + Node). If project already uses a different framework, follow existing conventions. - For Discord.js interactions, stub/mocking approaches: - Use jest mocks for discord.js Client, Message, Interaction, and MessageEmbed classes. - Consider using a test utility to create lightweight fake Interaction/Message objects with only the fields handlers expect. - For database: - Use sqlite in-memory where possible or a test Postgres instance in CI. - If current project uses TypeORM/Sequelize/Prisma, use their recommended testing setup (transaction rollback per test or test DB per run). - Test locations: use tests/ or __tests__ directories, mirror source structure (src/commands/drop.test.ts, src/lib/weightSelector.test.ts, etc). - Coverage: aim to add tests for the most critical flows first (drop/claim/timer/weights). Increasing overall coverage can be iterative.
Vylpes changed title from Create missing todo tests to Add tests for all TODOs / implement missing tests 2026-03-28 10:41:34 +00:00
Vylpes added this to the 0.12.0 milestone 2026-03-28 10:45:04 +00:00
Vylpes added this to the 0.10 Sprint 3 project 2026-04-16 19:03:18 +01:00
Vylpes self-assigned this 2026-04-16 19:03:19 +01:00
Vylpes added reference copilot/add-tests-for-todos 2026-05-05 20:35:55 +01:00
Vylpes stopped working 2026-05-05 20:36:14 +01:00
24 minutes 40 seconds
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Total time spent: 24 minutes 40 seconds
Vylpes
24 minutes 40 seconds
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
External/card-drop#423
No description provided.