Adding more API tests
This commit is contained in:
@@ -34,9 +34,9 @@ export default class AICC extends Scorm12API {
|
||||
|
||||
if (!newChild) {
|
||||
if (this.stringMatches(CMIElement, 'cmi\\.evaluation\\.comments\\.\\d')) {
|
||||
newChild = new CMIEvaluationCommentsObject(this);
|
||||
newChild = new CMIEvaluationCommentsObject();
|
||||
} else if (this.stringMatches(CMIElement, 'cmi\\.student_data\\.tries\\.\\d')) {
|
||||
newChild = new CMITriesObject(this);
|
||||
newChild = new CMITriesObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ export default class BaseAPI {
|
||||
returnValue = this.setCMIValue(CMIElement, value);
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) {
|
||||
this.lastErrorCode = e.errorCode;
|
||||
returnValue = api_constants.SCORM_FALSE;
|
||||
} else {
|
||||
this.throwSCORMError(this.#error_codes.GENERAL);
|
||||
@@ -160,7 +161,9 @@ export default class BaseAPI {
|
||||
this.processListeners(callbackName, CMIElement, value);
|
||||
}
|
||||
|
||||
if (returnValue === undefined) returnValue = api_constants.SCORM_FALSE;
|
||||
if (returnValue === undefined) {
|
||||
returnValue = api_constants.SCORM_FALSE;
|
||||
}
|
||||
|
||||
this.apiLog(callbackName, CMIElement,
|
||||
': ' + value + ': result: ' + returnValue,
|
||||
@@ -382,7 +385,8 @@ export default class BaseAPI {
|
||||
* @abstract
|
||||
*/
|
||||
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
||||
throw new Error('The getLmsErrorMessageDetails method has not been implemented');
|
||||
throw new Error(
|
||||
'The getLmsErrorMessageDetails method has not been implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,7 +449,7 @@ export default class BaseAPI {
|
||||
} else if (!this._checkObjectHasProperty(refObject, attribute)) {
|
||||
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||
} else {
|
||||
if (this.stringMatches(CMIElement, '.correct_responses')) {
|
||||
if (this.stringMatches(CMIElement, '\\.correct_responses\\.\\d')) {
|
||||
this.validateCorrectResponse(CMIElement, value);
|
||||
}
|
||||
|
||||
@@ -471,12 +475,15 @@ export default class BaseAPI {
|
||||
if (item) {
|
||||
refObject = item;
|
||||
} else {
|
||||
const newChild = this.getChildElement(CMIElement, value, foundFirstIndex);
|
||||
const newChild = this.getChildElement(CMIElement, value,
|
||||
foundFirstIndex);
|
||||
foundFirstIndex = true;
|
||||
|
||||
if (!newChild) {
|
||||
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||
} else {
|
||||
if (refObject.initialized) newChild.initialize();
|
||||
|
||||
refObject.childArray.push(newChild);
|
||||
refObject = newChild;
|
||||
}
|
||||
|
||||
@@ -148,13 +148,13 @@ export default class Scorm12API extends BaseAPI {
|
||||
let newChild;
|
||||
|
||||
if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) {
|
||||
newChild = new CMIObjectivesObject(this);
|
||||
newChild = new CMIObjectivesObject();
|
||||
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.correct_responses\\.\\d')) {
|
||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
||||
newChild = new CMIInteractionsCorrectResponsesObject();
|
||||
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) {
|
||||
newChild = new CMIInteractionsObjectivesObject(this);
|
||||
newChild = new CMIInteractionsObjectivesObject();
|
||||
} else if (this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) {
|
||||
newChild = new CMIInteractionsObject(this);
|
||||
newChild = new CMIInteractionsObject();
|
||||
}
|
||||
|
||||
return newChild;
|
||||
|
||||
@@ -3,8 +3,7 @@ import BaseAPI from './BaseAPI';
|
||||
import {
|
||||
ADL,
|
||||
CMI,
|
||||
CMICommentsFromLearnerObject,
|
||||
CMICommentsFromLMSObject,
|
||||
CMICommentsObject,
|
||||
CMIInteractionsCorrectResponsesObject,
|
||||
CMIInteractionsObject,
|
||||
CMIInteractionsObjectivesObject,
|
||||
@@ -128,9 +127,10 @@ export default class Scorm2004API extends BaseAPI {
|
||||
*
|
||||
* @param {string} CMIElement
|
||||
* @param {any} value
|
||||
* @return {string}
|
||||
*/
|
||||
setCMIValue(CMIElement, value) {
|
||||
this._commonSetCMIValue('SetValue', true, CMIElement, value);
|
||||
return this._commonSetCMIValue('SetValue', true, CMIElement, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ export default class Scorm2004API extends BaseAPI {
|
||||
let newChild;
|
||||
|
||||
if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) {
|
||||
newChild = new CMIObjectivesObject(this);
|
||||
newChild = new CMIObjectivesObject();
|
||||
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.correct_responses\\.\\d')) {
|
||||
const parts = CMIElement.split('.');
|
||||
const index = Number(parts[2]);
|
||||
@@ -181,16 +181,16 @@ export default class Scorm2004API extends BaseAPI {
|
||||
}
|
||||
}
|
||||
if (this.lastErrorCode === 0) {
|
||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
||||
newChild = new CMIInteractionsCorrectResponsesObject();
|
||||
}
|
||||
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) {
|
||||
newChild = new CMIInteractionsObjectivesObject(this);
|
||||
newChild = new CMIInteractionsObjectivesObject();
|
||||
} else if (this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) {
|
||||
newChild = new CMIInteractionsObject(this);
|
||||
newChild = new CMIInteractionsObject();
|
||||
} else if (this.stringMatches(CMIElement, 'cmi\\.comments_from_learner\\.\\d')) {
|
||||
newChild = new CMICommentsFromLearnerObject(this);
|
||||
newChild = new CMICommentsObject();
|
||||
} else if (this.stringMatches(CMIElement, 'cmi\\.comments_from_lms\\.\\d')) {
|
||||
newChild = new CMICommentsFromLMSObject(this);
|
||||
newChild = new CMICommentsObject(true);
|
||||
}
|
||||
|
||||
return newChild;
|
||||
|
||||
@@ -67,7 +67,6 @@ export function check12ValidRange(
|
||||
|
||||
/**
|
||||
* Class representing the cmi object for SCORM 1.2
|
||||
* @extends BaseCMI
|
||||
*/
|
||||
export class CMI extends BaseCMI {
|
||||
#_children = '';
|
||||
|
||||
@@ -94,14 +94,14 @@ export class CMI extends BaseCMI {
|
||||
constructor(initialized: boolean) {
|
||||
super();
|
||||
|
||||
if (initialized) this.initialize();
|
||||
|
||||
this.learner_preference = new CMILearnerPreference();
|
||||
this.score = new Scorm2004CMIScore();
|
||||
this.comments_from_learner = new CMICommentsFromLearner();
|
||||
this.comments_from_lms = new CMICommentsFromLMS();
|
||||
this.interactions = new CMIInteractions();
|
||||
this.objectives = new CMIObjectives();
|
||||
|
||||
if (initialized) this.initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1150,7 +1150,7 @@ class Scorm2004CMIScore extends CMIScore {
|
||||
{
|
||||
score_children: constants.score_children,
|
||||
max: '',
|
||||
invalidErrorCode: scorm2004_error_codes.INVALID_SET_VALUE,
|
||||
invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
|
||||
invalidRangeCode: scorm2004_error_codes.VALUE_OUT_OF_RANGE,
|
||||
decimalRegex: scorm2004_regex.CMIDecimal,
|
||||
@@ -1202,21 +1202,24 @@ class Scorm2004CMIScore extends CMIScore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing SCORM 2004's cmi.comments_from_learner.n object
|
||||
* Class representing SCORM 2004's cmi.comments_from_learner.n and cmi.comments_from_lms.n object
|
||||
*/
|
||||
export class CMICommentsFromLearnerObject extends BaseCMI {
|
||||
export class CMICommentsObject extends BaseCMI {
|
||||
#comment = '';
|
||||
#location = '';
|
||||
#timestamp = '';
|
||||
#readOnlyAfterInit;
|
||||
|
||||
/**
|
||||
* Constructor for cmi.comments_from_learner.n
|
||||
* Constructor for cmi.comments_from_learner.n and cmi.comments_from_lms.n
|
||||
* @param {boolean} readOnlyAfterInit
|
||||
*/
|
||||
constructor() {
|
||||
constructor(readOnlyAfterInit = false) {
|
||||
super();
|
||||
this.#comment = '';
|
||||
this.#location = '';
|
||||
this.#timestamp = '';
|
||||
this.#readOnlyAfterInit = readOnlyAfterInit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1232,8 +1235,12 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
||||
* @param {string} comment
|
||||
*/
|
||||
set comment(comment) {
|
||||
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) {
|
||||
this.#comment = comment;
|
||||
if (this.initialized && this.#readOnlyAfterInit) {
|
||||
throwReadOnlyError();
|
||||
} else {
|
||||
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) {
|
||||
this.#comment = comment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1250,8 +1257,12 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
||||
* @param {string} location
|
||||
*/
|
||||
set location(location) {
|
||||
if (check2004ValidFormat(location, regex.CMIString250)) {
|
||||
this.#location = location;
|
||||
if (this.initialized && this.#readOnlyAfterInit) {
|
||||
throwReadOnlyError();
|
||||
} else {
|
||||
if (check2004ValidFormat(location, regex.CMIString250)) {
|
||||
this.#location = location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1268,8 +1279,12 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
||||
* @param {string} timestamp
|
||||
*/
|
||||
set timestamp(timestamp) {
|
||||
if (check2004ValidFormat(timestamp, regex.CMITime)) {
|
||||
this.#timestamp = timestamp;
|
||||
if (this.initialized && this.#readOnlyAfterInit) {
|
||||
throwReadOnlyError();
|
||||
} else {
|
||||
if (check2004ValidFormat(timestamp, regex.CMITime)) {
|
||||
this.#timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,80 +1310,6 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing SCORM 2004's cmi.comments_from_lms.n object
|
||||
*/
|
||||
export class CMICommentsFromLMSObject extends CMICommentsFromLearnerObject {
|
||||
/**
|
||||
* Constructor for cmi.comments_from_lms.n
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #comment
|
||||
* @return {string}
|
||||
*/
|
||||
get comment() {
|
||||
return super.comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #comment. Can only be called before initialization.
|
||||
* @param {string} comment
|
||||
*/
|
||||
set comment(comment) {
|
||||
!this.initialized ? super.comment = comment : throwReadOnlyError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #location
|
||||
* @return {string}
|
||||
*/
|
||||
get location() {
|
||||
return super.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #location. Can only be called before initialization.
|
||||
* @param {string} location
|
||||
*/
|
||||
set location(location) {
|
||||
!this.initialized ? super.location = location : throwReadOnlyError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for #timestamp
|
||||
* @return {string}
|
||||
*/
|
||||
get timestamp() {
|
||||
return super.timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for #timestamp. Can only be called before initialization.
|
||||
* @param {string} timestamp
|
||||
*/
|
||||
set timestamp(timestamp) {
|
||||
!this.initialized ? super.timestamp = timestamp : throwReadOnlyError();
|
||||
}
|
||||
|
||||
/**
|
||||
* toJSON for cmi.comments_from_lms.n
|
||||
* @return {
|
||||
* {
|
||||
* comment: string,
|
||||
* location: string,
|
||||
* timestamp: string
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
toJSON() {
|
||||
return super.toJSON();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class representing SCORM 2004's cmi.interactions.n.objectives.n object
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,14 @@ export class ValidationError extends Error {
|
||||
|
||||
#errorCode;
|
||||
|
||||
/**
|
||||
* Getter for #errorCode
|
||||
* @return {number}
|
||||
*/
|
||||
get errorCode() {
|
||||
return this.#errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to override the default Error message
|
||||
* @return {string}
|
||||
|
||||
Reference in New Issue
Block a user