test(progress-tracker): cover learner stats, completion percentage, and quiz retakes - #367
Merged
Conversation
…nd quiz retakes get_learner_stats, get_completion_percentage, and retake_quiz were merged with production code but no test coverage, leaving their edge cases (zero-quiz averages, aggregation across courses, retake score validation, event emission, eligibility flips) unverified. Adds unit tests for: - get_completion_percentage: matches stored overall_progress, panics when not enrolled. - get_learner_courses / get_learner_stats: empty/zero results for a new learner, aggregation across multiple courses, and an average that divides by quizzes submitted rather than courses enrolled. - retake_quiz: replaces a score without double-counting it, emits quiz_retaken (and credential_eligible on a flip to eligible), and rejects a non-improving score, an unsubmitted quiz, an out-of-range score, or an unenrolled learner. Closes ChainLearnOfficial#247, Closes ChainLearnOfficial#248, Closes ChainLearnOfficial#249
|
@meshackyaro 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issues #247, #248, and #249 ask for
get_learner_stats,get_completion_percentage, andretake_quizon the progress-tracker contract. These are duplicates of already-closed issues #232, #233, and #234, and the functions themselves already exist onmain(added in #364/8716288). That commit, however, only touched the test file to fix a struct literal for the compiler — it added zero test coverage for any of the five new functions it introduced.This PR adds the missing unit test coverage for the three functions these issues ask about, in
tests/unit/progress_tests.rs:get_completion_percentage(. Add course completion percentage query #248, . Add course completion percentage query #233): returns the same value asget_progress(..).overall_progress; panics when the learner isn't enrolled.get_learner_courses/get_learner_stats(. Add learner statistics aggregation #247, . Add learner statistics aggregation #232): empty/all-zero result for a learner who never enrolled; aggregation ofcourses_enrolled,courses_completed,total_quizzes_submitted,total_quiz_score,average_score, andtotal_rewards_earnedacross multiple courses; the average divides by quizzes submitted, not courses enrolled, so an untouched enrollment doesn't drag it down.retake_quiz(. Add quiz retake support #249, . Add quiz retake support #234): replaces a quiz's score without double-counting it inquizzes_submitted; emitsquiz_retakenwith the previous and new score; emitscredential_eligiblewhen a retake flips eligibility; panics on a non-improving score, an unsubmitted quiz, a score above the max, or an unenrolled learner.All 45 tests in the
progress_testsbinary pass (30 existing + 15 new).Note:
cargo testonmaincurrently fails to build at all becausecontracts/learn-token/src/storage.rsdefinesis_paused/set_pausedtwice (lines 248 and 736, from #366) — unrelated to this PR's scope, so it isn't touched here, but it blocks running the full workspace test suite until it's fixed separately.Test plan
cargo test --test progress_tests— 45 passed, 0 failed (verified locally with the unrelatedlearn-tokenduplicate-definition build error worked around; not part of this diff)Closes #247, Closes #248, Closes #249