Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Logging instances of question bank misuse #174

Merged
merged 7 commits into from
Sep 5, 2022
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A sentence describing each fix

### Update
* A sentence describing each udpate
* A sentence describing each update

### New
* A sentence describing each new feature
Expand Down
9 changes: 9 additions & 0 deletions js/adapt-assessmentArticleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ const AssessmentModel = {
_setupBanks() {
const assessmentConfig = this.getConfig();
const bankSplits = assessmentConfig._banks._split.split(',');

this.findDescendantModels('block')
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
.filter(block => block.get('_isAvailable') && block.findDescendantModels('question').length > 0)).forEach(block => {
const isInvalidNumber = (isNaN(block._quizBankId) || block._quizBankId < 1);
const isOutOfBounds = (block._quizBankId > bankSplits.length);
if (isInvalidNumber) logging.warn(`Bank ID ${block._quizBankId} is not a valid number`);
if (isOutOfBounds) logging.warn(`Bank ID ${block._quizBankId} exceeds the number of available splits (${bankSplits.length})`);
});

const hasBankSplitsChanged = (bankSplits.length !== this._questionBanks?.length);
if (hasBankSplitsChanged) {
// Generate new question banks if the split has changed
Expand Down
6 changes: 6 additions & 0 deletions js/adapt-assessmentQuestionBank.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import data from 'core/js/data';
import logging from 'core/js/logging';

class QuestionBank {

Expand Down Expand Up @@ -26,8 +27,13 @@ class QuestionBank {
}

getRandomQuestionBlocks() {
if (this._count > this.unusedQuestionBlocks.length) {
logging.warn(`Bank ID ${this._bankId}: Attempting to display ${this._count} question(s), but only ${this.unusedQuestionBlocks.length} available`);
}

const questionBlocks = [];
let i = 0;

while (i++ < this._count) {
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
const nextBlock = this.unusedQuestionBlocks.shift();
questionBlocks.push(nextBlock);
Expand Down