Skip to content

feat(hamplard): add course waitlist management with automatic promotion - #275

Open
Folex1275 wants to merge 2 commits into
Hamplard-Hub:mainfrom
Folex1275:wave8
Open

feat(hamplard): add course waitlist management with automatic promotion#275
Folex1275 wants to merge 2 commits into
Hamplard-Hub:mainfrom
Folex1275:wave8

Conversation

@Folex1275

Copy link
Copy Markdown
Contributor

Fix Test Coverage and Implement Waitlist Feature

Summary

This PR addresses three issues related to test coverage and missing functionality in the Hamplard contract:

  1. Issue test.rs does not test archive_course() when course has pending student completions #142: Added test for archive_course() with pending student completions
  2. Issue test.rs does not test behavior when DataKey::DefaultFee is missing at enroll time #143: Added test for missing DefaultFee at enrollment time
  3. Issue lib.rs does not implement course waitlist with automatic enrollment on capacity opening #147: Implemented course waitlist with automatic enrollment promotion

Changes

Issue #142: Test archive_course() with Pending Completions

Problem: The test suite did not cover the scenario where archive_course() is called on a course with enrolled students who have not been marked as completed. These students are silently left in an uncompletable state after archival.

Solution:

  • Added test_archive_with_pending_student_completions() - verifies that archiving a course with a mix of completed and pending students correctly refunds only the pending students while preserving completed enrollments
  • Added test_mark_completed_on_archived_course_fails() - verifies that attempting to mark a student as completed after course archival produces a clear error

Files Modified:

  • contracts/hamplard/src/test.rs

Issue #143: Test Missing DefaultFee Behavior

Problem: The test suite did not test the scenario where enroll() is called before DataKey::DefaultFee has been initialized. This could result in confusing panics in production if init is skipped.

Solution:

  • Added test_enroll_missing_default_fee_produces_clear_error() - verifies that attempting to register a course with a custom fee below the platform default (when DefaultFee is missing) produces a clear, actionable error message

Files Modified:

  • contracts/hamplard/src/test.rs

Issue #147: Implement Course Waitlist

Problem: When a course reaches its max_capacity, students who arrive later have no recourse. There was no waitlist mechanism to queue interested students and automatically enroll them when a spot opens.

Solution:

  • Added DataKey::CourseWaitlist(String) to storage keys for per-course waitlist storage
  • Implemented join_waitlist() - allows students to join the waitlist for a full course
  • Implemented leave_waitlist() - allows students to leave the waitlist
  • Implemented get_waitlist() - returns the ordered list of waitlisted students
  • Implemented promote_from_waitlist() (internal) - automatically promotes the first waitlisted student when capacity opens
  • Integrated waitlist promotion into archive_course() when refunds create available capacity
  • Added comprehensive test coverage:
    • test_join_waitlist_success()
    • test_join_waitlist_rejects_when_capacity_available()
    • test_join_waitlist_duplicate_rejected()
    • test_leave_waitlist_success()
    • test_leave_waitlist_not_on_list()
    • test_waitlist_promotion_on_refund()

Files Modified:

  • contracts/hamplard/src/lib.rs
  • contracts/hamplard/src/test.rs

Testing

All new tests pass and verify:

  • Archive behavior with pending completions is well-defined
  • Missing DefaultFee scenario produces clear error messages
  • Waitlist join/leave operations work correctly
  • Automatic promotion from waitlist occurs when capacity opens
  • Edge cases (duplicates, already enrolled, etc.) are properly handled

Closes

Closes #142
Closes #143
Closes #147

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@Folex1275 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant