Rework of constants and some additional tests

This commit is contained in:
Jonathan Putney
2020-01-15 12:21:57 -05:00
parent eaa80394a7
commit 7882608fb6
23 changed files with 766 additions and 578 deletions
+394 -338
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+13 -13
View File
File diff suppressed because one or more lines are too long
+11 -3
View File
@@ -1,10 +1,13 @@
// @flow // @flow
import {CMIArray} from './cmi/common'; import {CMIArray} from './cmi/common';
import {ValidationError} from './exceptions'; import {ValidationError} from './exceptions';
import {scorm12_error_codes} from './constants/error_codes'; import ErrorCodes from './constants/error_codes';
import {global_constants} from './constants/api_constants'; import APIConstants from './constants/api_constants';
import {unflatten} from './utilities'; import {unflatten} from './utilities';
const global_constants = APIConstants.global;
const scorm12_error_codes = ErrorCodes.scorm12;
/** /**
* Base API class for AICC, SCORM 1.2, and SCORM 2004. Should be considered * Base API class for AICC, SCORM 1.2, and SCORM 2004. Should be considered
* abstract, and never initialized on it's own. * abstract, and never initialized on it's own.
@@ -186,7 +189,11 @@ export default class BaseAPI {
this.lastErrorCode = e.errorCode; this.lastErrorCode = e.errorCode;
returnValue = global_constants.SCORM_FALSE; returnValue = global_constants.SCORM_FALSE;
} else { } else {
console.error(e.getMessage()); if (e.message) {
console.error(e.message);
} else {
console.error(e);
}
this.throwSCORMError(this.#error_codes.GENERAL); this.throwSCORMError(this.#error_codes.GENERAL);
} }
} }
@@ -533,6 +540,7 @@ export default class BaseAPI {
if (item) { if (item) {
refObject = item; refObject = item;
foundFirstIndex = true;
} else { } else {
const newChild = this.getChildElement(CMIElement, value, const newChild = this.getChildElement(CMIElement, value,
foundFirstIndex); foundFirstIndex);
+10 -7
View File
@@ -8,10 +8,12 @@ import {
CMIObjectivesObject, NAV, CMIObjectivesObject, NAV,
} from './cmi/scorm12_cmi'; } from './cmi/scorm12_cmi';
import * as Utilities from './utilities'; import * as Utilities from './utilities';
import {global_constants, scorm12_constants} from './constants/api_constants'; import APIConstants from './constants/api_constants';
import {scorm12_error_codes} from './constants/error_codes'; import ErrorCodes from './constants/error_codes';
const constants = scorm12_constants; const scorm12_constants = APIConstants.scorm12;
const global_constants = APIConstants.global;
const scorm12_error_codes = ErrorCodes.scorm12;
/** /**
* API class for SCORM 1.2 * API class for SCORM 1.2
@@ -177,7 +179,8 @@ export default class Scorm12API extends BaseAPI {
} else if (foundFirstIndex && this.stringMatches(CMIElement, } else if (foundFirstIndex && this.stringMatches(CMIElement,
'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) { 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) {
newChild = new CMIInteractionsObjectivesObject(); newChild = new CMIInteractionsObjectivesObject();
} else if (this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) { } else if (!foundFirstIndex &&
this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) {
newChild = new CMIInteractionsObject(); newChild = new CMIInteractionsObject();
} }
@@ -208,9 +211,9 @@ export default class Scorm12API extends BaseAPI {
// Set error number to string since inconsistent from modules if string or number // Set error number to string since inconsistent from modules if string or number
errorNumber = String(errorNumber); errorNumber = String(errorNumber);
if (constants.error_descriptions[errorNumber]) { if (scorm12_constants.error_descriptions[errorNumber]) {
basicMessage = constants.error_descriptions[errorNumber].basicMessage; basicMessage = scorm12_constants.error_descriptions[errorNumber].basicMessage;
detailMessage = constants.error_descriptions[errorNumber].detailMessage; detailMessage = scorm12_constants.error_descriptions[errorNumber].detailMessage;
} }
return detail ? detailMessage : basicMessage; return detail ? detailMessage : basicMessage;
+35 -25
View File
@@ -10,13 +10,17 @@ import {
CMIObjectivesObject, CMIObjectivesObject,
} from './cmi/scorm2004_cmi'; } from './cmi/scorm2004_cmi';
import * as Utilities from './utilities'; import * as Utilities from './utilities';
import {global_constants, scorm2004_constants} from './constants/api_constants'; import APIConstants from './constants/api_constants';
import {scorm2004_error_codes} from './constants/error_codes'; import ErrorCodes from './constants/error_codes';
import {correct_responses} from './constants/response_constants'; import Responses from './constants/response_constants';
import {valid_languages} from './constants/language_constants'; import ValidLanguages from './constants/language_constants';
import {scorm2004_regex} from './constants/regex'; import Regex from './constants/regex';
const constants = scorm2004_constants; const scorm2004_constants = APIConstants.scorm2004;
const global_constants = APIConstants.global;
const scorm2004_error_codes = ErrorCodes.scorm2004;
const correct_responses = Responses.correct;
const scorm2004_regex = Regex.scorm2004;
/** /**
* API class for SCORM 2004 * API class for SCORM 2004
@@ -190,7 +194,7 @@ export default class Scorm2004API extends BaseAPI {
const parts = CMIElement.split('.'); const parts = CMIElement.split('.');
const index = Number(parts[2]); const index = Number(parts[2]);
const interaction = this.cmi.interactions.childArray[index]; const interaction = this.cmi.interactions.childArray[index];
if (typeof interaction.type === 'undefined') { if (!interaction.type) {
this.throwSCORMError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED); this.throwSCORMError(scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED);
} else { } else {
const interaction_type = interaction.type; const interaction_type = interaction.type;
@@ -206,18 +210,23 @@ export default class Scorm2004API extends BaseAPI {
} }
const response_type = correct_responses[interaction_type]; const response_type = correct_responses[interaction_type];
let nodes = []; if (response_type) {
if (response_type.delimiter !== '') { let nodes = [];
nodes = String(value).split(response_type.delimiter); if (response_type?.delimiter) {
} else { nodes = String(value).split(response_type.delimiter);
nodes[0] = value; } else {
} nodes[0] = value;
}
if (nodes.length > 0 && nodes.length <= response_type.max) { if (nodes.length > 0 && nodes.length <= response_type.max) {
this.checkCorrectResponseValue(interaction_type, nodes, value); this.checkCorrectResponseValue(interaction_type, nodes, value);
} else if (nodes.length > response_type.max) { } else if (nodes.length > response_type.max) {
this.throwSCORMError(scorm2004_error_codes.GENERAL_SET_FAILURE,
'Data Model Element Pattern Too Long');
}
} else {
this.throwSCORMError(scorm2004_error_codes.GENERAL_SET_FAILURE, this.throwSCORMError(scorm2004_error_codes.GENERAL_SET_FAILURE,
'Data Model Element Pattern Too Long'); 'Incorrect Response Type: ' + interaction_type);
} }
} }
if (this.lastErrorCode === 0) { if (this.lastErrorCode === 0) {
@@ -226,7 +235,8 @@ export default class Scorm2004API extends BaseAPI {
} else if (foundFirstIndex && this.stringMatches(CMIElement, } else if (foundFirstIndex && this.stringMatches(CMIElement,
'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) { 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) {
newChild = new CMIInteractionsObjectivesObject(); newChild = new CMIInteractionsObjectivesObject();
} else if (this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) { } else if (!foundFirstIndex &&
this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) {
newChild = new CMIInteractionsObject(); newChild = new CMIInteractionsObject();
} else if (this.stringMatches(CMIElement, } else if (this.stringMatches(CMIElement,
'cmi\\.comments_from_learner\\.\\d')) { 'cmi\\.comments_from_learner\\.\\d')) {
@@ -261,11 +271,11 @@ export default class Scorm2004API extends BaseAPI {
} }
} }
const response_type = scorm2004_constants.correct_responses[interaction_type]; const response_type = correct_responses[interaction_type];
if (typeof response_type.limit !== 'undefined' || interaction_count < if (typeof response_type.limit !== 'undefined' || interaction_count <
response_type.limit) { response_type.limit) {
let nodes = []; let nodes = [];
if (response_type.delimiter !== '') { if (response_type?.delimiter) {
nodes = String(value).split(response_type.delimiter); nodes = String(value).split(response_type.delimiter);
} else { } else {
nodes[0] = value; nodes[0] = value;
@@ -319,9 +329,9 @@ export default class Scorm2004API extends BaseAPI {
// Set error number to string since inconsistent from modules if string or number // Set error number to string since inconsistent from modules if string or number
errorNumber = String(errorNumber); errorNumber = String(errorNumber);
if (constants.error_descriptions[errorNumber]) { if (scorm2004_constants.error_descriptions[errorNumber]) {
basicMessage = constants.error_descriptions[errorNumber].basicMessage; basicMessage = scorm2004_constants.error_descriptions[errorNumber].basicMessage;
detailMessage = constants.error_descriptions[errorNumber].detailMessage; detailMessage = scorm2004_constants.error_descriptions[errorNumber].detailMessage;
} }
return detail ? detailMessage : basicMessage; return detail ? detailMessage : basicMessage;
@@ -360,7 +370,7 @@ export default class Scorm2004API extends BaseAPI {
nodes[i] = this.removeCorrectResponsePrefixes(nodes[i]); nodes[i] = this.removeCorrectResponsePrefixes(nodes[i]);
} }
if (response.delimiter2 !== undefined) { if (response?.delimiter2) {
const values = nodes[i].split(response.delimiter2); const values = nodes[i].split(response.delimiter2);
if (values.length === 2) { if (values.length === 2) {
const matches = values[0].match(formatRegex); const matches = values[0].match(formatRegex);
@@ -419,7 +429,7 @@ export default class Scorm2004API extends BaseAPI {
if (langMatches) { if (langMatches) {
const lang = langMatches[3]; const lang = langMatches[3];
if (lang !== undefined && lang.length > 0) { if (lang !== undefined && lang.length > 0) {
if (valid_languages[lang.toLowerCase()] === undefined) { if (ValidLanguages[lang.toLowerCase()] === undefined) {
this.throwSCORMError(scorm2004_error_codes.TYPE_MISMATCH); this.throwSCORMError(scorm2004_error_codes.TYPE_MISMATCH);
} }
} }
+16 -15
View File
@@ -1,16 +1,17 @@
import * as Scorm12CMI from './scorm12_cmi'; import * as Scorm12CMI from './scorm12_cmi';
import {BaseCMI, CMIArray, CMIScore} from './common'; import {BaseCMI, CMIArray, CMIScore} from './common';
import {aicc_constants} from '../constants/api_constants'; import APIConstants from '../constants/api_constants';
import {aicc_regex} from '../constants/regex'; import Regex from '../constants/regex';
import {scorm12_error_codes} from '../constants/error_codes'; import ErrorCodes from '../constants/error_codes';
import { import {
check12ValidFormat, check12ValidFormat,
throwReadOnlyError, throwReadOnlyError,
throwWriteOnlyError, throwWriteOnlyError,
} from './scorm12_cmi'; } from './scorm12_cmi';
const constants = aicc_constants; const aicc_constants = APIConstants.aicc;
const regex = aicc_regex; const aicc_regex = Regex.aicc;
const scorm12_error_codes = ErrorCodes.scorm12;
/** /**
* CMI Class for AICC * CMI Class for AICC
@@ -21,7 +22,7 @@ export class CMI extends Scorm12CMI.CMI {
* @param {boolean} initialized * @param {boolean} initialized
*/ */
constructor(initialized: boolean) { constructor(initialized: boolean) {
super(constants.cmi_children); super(aicc_constants.cmi_children);
if (initialized) this.initialize(); if (initialized) this.initialize();
@@ -117,7 +118,7 @@ class CMIEvaluationComments extends CMIArray {
* Constructor for AICC Evaluation Comments object * Constructor for AICC Evaluation Comments object
*/ */
constructor() { constructor() {
super(constants.comments_children, super(aicc_constants.comments_children,
scorm12_error_codes.INVALID_SET_VALUE); scorm12_error_codes.INVALID_SET_VALUE);
} }
} }
@@ -130,7 +131,7 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
* Constructor for AICC StudentData object * Constructor for AICC StudentData object
*/ */
constructor() { constructor() {
super(constants.student_data_children); super(aicc_constants.student_data_children);
this.tries = new CMITries(); this.tries = new CMITries();
} }
@@ -212,8 +213,8 @@ export class CMITriesObject extends BaseCMI {
this.score = new CMIScore( this.score = new CMIScore(
{ {
score_children: constants.score_children, score_children: aicc_constants.score_children,
score_range: regex.score_range, score_range: aicc_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE, invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH, invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE, invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -244,7 +245,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} status * @param {string} status
*/ */
set status(status) { set status(status) {
if (check12ValidFormat(status, regex.CMIStatus2)) { if (check12ValidFormat(status, aicc_regex.CMIStatus2)) {
this.#status = status; this.#status = status;
} }
} }
@@ -262,7 +263,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} time * @param {string} time
*/ */
set time(time) { set time(time) {
if (check12ValidFormat(time, regex.CMITime)) { if (check12ValidFormat(time, aicc_regex.CMITime)) {
this.#time = time; this.#time = time;
} }
} }
@@ -317,7 +318,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} content * @param {string} content
*/ */
set content(content) { set content(content) {
if (check12ValidFormat(content, regex.CMIString256)) { if (check12ValidFormat(content, aicc_regex.CMIString256)) {
this.#content = content; this.#content = content;
} }
} }
@@ -335,7 +336,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} location * @param {string} location
*/ */
set location(location) { set location(location) {
if (check12ValidFormat(location, regex.CMIString256)) { if (check12ValidFormat(location, aicc_regex.CMIString256)) {
this.#location = location; this.#location = location;
} }
} }
@@ -353,7 +354,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} time * @param {string} time
*/ */
set time(time) { set time(time) {
if (check12ValidFormat(time, regex.CMITime)) { if (check12ValidFormat(time, aicc_regex.CMITime)) {
this.#time = time; this.#time = time;
} }
} }
+7 -3
View File
@@ -1,8 +1,12 @@
// @flow // @flow
import {scorm12_constants} from '../constants/api_constants'; import APIConstants from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes'; import ErrorCodes from '../constants/error_codes';
import {ValidationError} from '../exceptions'; import {ValidationError} from '../exceptions';
import {scorm12_regex} from '../constants/regex'; import Regex from '../constants/regex';
const scorm12_constants = APIConstants.scorm12;
const scorm12_regex = Regex.scorm12;
const scorm12_error_codes = ErrorCodes.scorm12;
/** /**
* Check if the value matches the proper format. If not, throw proper error code. * Check if the value matches the proper format. If not, throw proper error code.
+44 -43
View File
@@ -6,14 +6,15 @@ import {
CMIArray, CMIArray,
CMIScore, CMIScore,
} from './common'; } from './common';
import {scorm12_constants} from '../constants/api_constants'; import APIConstants from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes'; import ErrorCodes from '../constants/error_codes';
import {scorm12_regex} from '../constants/regex'; import Regex from '../constants/regex';
import {ValidationError} from '../exceptions'; import {ValidationError} from '../exceptions';
import * as Utilities from '../utilities'; import * as Utilities from '../utilities';
const constants = scorm12_constants; const scorm12_constants = APIConstants.scorm12;
const regex = scorm12_regex; const scorm12_regex = Regex.scorm12;
const scorm12_error_codes = ErrorCodes.scorm12;
/** /**
* Helper method for throwing Read Only error * Helper method for throwing Read Only error
@@ -90,7 +91,7 @@ export class CMI extends BaseCMI {
if (initialized) this.initialize(); if (initialized) this.initialize();
this.#_children = cmi_children ? cmi_children : constants.cmi_children; this.#_children = cmi_children ? cmi_children : scorm12_constants.cmi_children;
this.core = new CMICore(); this.core = new CMICore();
this.objectives = new CMIObjectives(); this.objectives = new CMIObjectives();
this.student_data = student_data ? student_data : new CMIStudentData(); this.student_data = student_data ? student_data : new CMIStudentData();
@@ -189,7 +190,7 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data * @param {string} suspend_data
*/ */
set suspend_data(suspend_data) { set suspend_data(suspend_data) {
if (check12ValidFormat(suspend_data, regex.CMIString4096)) { if (check12ValidFormat(suspend_data, scorm12_regex.CMIString4096, true)) {
this.#suspend_data = suspend_data; this.#suspend_data = suspend_data;
} }
} }
@@ -223,7 +224,7 @@ export class CMI extends BaseCMI {
* @param {string} comments * @param {string} comments
*/ */
set comments(comments) { set comments(comments) {
if (check12ValidFormat(comments, regex.CMIString4096)) { if (check12ValidFormat(comments, scorm12_regex.CMIString4096)) {
this.#comments = comments; this.#comments = comments;
} }
} }
@@ -269,8 +270,8 @@ class CMICore extends BaseCMI {
this.score = new CMIScore( this.score = new CMIScore(
{ {
score_children: constants.score_children, score_children: scorm12_constants.score_children,
score_range: regex.score_range, score_range: scorm12_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE, invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH, invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE, invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -285,7 +286,7 @@ class CMICore extends BaseCMI {
this.score?.initialize(); this.score?.initialize();
} }
#_children = constants.core_children; #_children = scorm12_constants.core_children;
#student_id = ''; #student_id = '';
#student_name = ''; #student_name = '';
#lesson_location = ''; #lesson_location = '';
@@ -362,7 +363,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_location * @param {string} lesson_location
*/ */
set lesson_location(lesson_location) { set lesson_location(lesson_location) {
if (check12ValidFormat(lesson_location, regex.CMIString256, true)) { if (check12ValidFormat(lesson_location, scorm12_regex.CMIString256, true)) {
this.#lesson_location = lesson_location; this.#lesson_location = lesson_location;
} }
} }
@@ -396,7 +397,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_status * @param {string} lesson_status
*/ */
set lesson_status(lesson_status) { set lesson_status(lesson_status) {
if (check12ValidFormat(lesson_status, regex.CMIStatus)) { if (check12ValidFormat(lesson_status, scorm12_regex.CMIStatus)) {
this.#lesson_status = lesson_status; this.#lesson_status = lesson_status;
} }
} }
@@ -462,7 +463,7 @@ class CMICore extends BaseCMI {
* @param {string} exit * @param {string} exit
*/ */
set exit(exit) { set exit(exit) {
if (check12ValidFormat(exit, regex.CMIExit, true)) { if (check12ValidFormat(exit, scorm12_regex.CMIExit, true)) {
this.#exit = exit; this.#exit = exit;
} }
} }
@@ -480,7 +481,7 @@ class CMICore extends BaseCMI {
* @param {string} session_time * @param {string} session_time
*/ */
set session_time(session_time) { set session_time(session_time) {
if (check12ValidFormat(session_time, regex.CMITimespan)) { if (check12ValidFormat(session_time, scorm12_regex.CMITimespan)) {
this.#session_time = session_time; this.#session_time = session_time;
} }
} }
@@ -545,7 +546,7 @@ class CMIObjectives extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.objectives_children, children: scorm12_constants.objectives_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE, errorCode: scorm12_error_codes.INVALID_SET_VALUE,
}); });
} }
@@ -570,7 +571,7 @@ export class CMIStudentData extends BaseCMI {
this.#_children = student_data_children ? this.#_children = student_data_children ?
student_data_children : student_data_children :
constants.student_data_children; scorm12_constants.student_data_children;
} }
/** /**
@@ -680,7 +681,7 @@ class CMIStudentPreference extends BaseCMI {
super(); super();
} }
#_children = constants.student_preference_children; #_children = scorm12_constants.student_preference_children;
#audio = ''; #audio = '';
#language = ''; #language = '';
#speed = ''; #speed = '';
@@ -717,8 +718,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} audio * @param {string} audio
*/ */
set audio(audio) { set audio(audio) {
if (check12ValidFormat(audio, regex.CMISInteger) && if (check12ValidFormat(audio, scorm12_regex.CMISInteger) &&
check12ValidRange(audio, regex.audio_range)) { check12ValidRange(audio, scorm12_regex.audio_range)) {
this.#audio = audio; this.#audio = audio;
} }
} }
@@ -736,7 +737,7 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} language * @param {string} language
*/ */
set language(language) { set language(language) {
if (check12ValidFormat(language, regex.CMIString256)) { if (check12ValidFormat(language, scorm12_regex.CMIString256)) {
this.#language = language; this.#language = language;
} }
} }
@@ -754,8 +755,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} speed * @param {string} speed
*/ */
set speed(speed) { set speed(speed) {
if (check12ValidFormat(speed, regex.CMISInteger) && if (check12ValidFormat(speed, scorm12_regex.CMISInteger) &&
check12ValidRange(speed, regex.speed_range)) { check12ValidRange(speed, scorm12_regex.speed_range)) {
this.#speed = speed; this.#speed = speed;
} }
} }
@@ -773,8 +774,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} text * @param {string} text
*/ */
set text(text) { set text(text) {
if (check12ValidFormat(text, regex.CMISInteger) && if (check12ValidFormat(text, scorm12_regex.CMISInteger) &&
check12ValidRange(text, regex.text_range)) { check12ValidRange(text, scorm12_regex.text_range)) {
this.#text = text; this.#text = text;
} }
} }
@@ -814,7 +815,7 @@ class CMIInteractions extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.interactions_children, children: scorm12_constants.interactions_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE, errorCode: scorm12_error_codes.INVALID_SET_VALUE,
}); });
} }
@@ -833,11 +834,11 @@ export class CMIInteractionsObject extends BaseCMI {
this.objectives = new CMIArray({ this.objectives = new CMIArray({
errorCode: scorm12_error_codes.INVALID_SET_VALUE, errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.objectives_children, children: scorm12_constants.objectives_children,
}); });
this.correct_responses = new CMIArray({ this.correct_responses = new CMIArray({
errorCode: scorm12_error_codes.INVALID_SET_VALUE, errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.correct_responses_children, children: scorm12_constants.correct_responses_children,
}); });
} }
@@ -871,7 +872,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) { if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -889,7 +890,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} time * @param {string} time
*/ */
set time(time) { set time(time) {
if (check12ValidFormat(time, regex.CMITime)) { if (check12ValidFormat(time, scorm12_regex.CMITime)) {
this.#time = time; this.#time = time;
} }
} }
@@ -907,7 +908,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} type * @param {string} type
*/ */
set type(type) { set type(type) {
if (check12ValidFormat(type, regex.CMIType)) { if (check12ValidFormat(type, scorm12_regex.CMIType)) {
this.#type = type; this.#type = type;
} }
} }
@@ -927,8 +928,8 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} weighting * @param {string} weighting
*/ */
set weighting(weighting) { set weighting(weighting) {
if (check12ValidFormat(weighting, regex.CMIDecimal) && if (check12ValidFormat(weighting, scorm12_regex.CMIDecimal) &&
check12ValidRange(weighting, regex.weighting_range)) { check12ValidRange(weighting, scorm12_regex.weighting_range)) {
this.#weighting = weighting; this.#weighting = weighting;
} }
} }
@@ -946,7 +947,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} student_response * @param {string} student_response
*/ */
set student_response(student_response) { set student_response(student_response) {
if (check12ValidFormat(student_response, regex.CMIFeedback, true)) { if (check12ValidFormat(student_response, scorm12_regex.CMIFeedback, true)) {
this.#student_response = student_response; this.#student_response = student_response;
} }
} }
@@ -964,7 +965,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} result * @param {string} result
*/ */
set result(result) { set result(result) {
if (check12ValidFormat(result, regex.CMIResult)) { if (check12ValidFormat(result, scorm12_regex.CMIResult)) {
this.#result = result; this.#result = result;
} }
} }
@@ -982,7 +983,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} latency * @param {string} latency
*/ */
set latency(latency) { set latency(latency) {
if (check12ValidFormat(latency, regex.CMITimespan)) { if (check12ValidFormat(latency, scorm12_regex.CMITimespan)) {
this.#latency = latency; this.#latency = latency;
} }
} }
@@ -1035,8 +1036,8 @@ export class CMIObjectivesObject extends BaseCMI {
this.score = new CMIScore( this.score = new CMIScore(
{ {
score_children: constants.score_children, score_children: scorm12_constants.score_children,
score_range: regex.score_range, score_range: scorm12_regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE, invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH, invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE, invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
@@ -1059,7 +1060,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) { if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -1077,7 +1078,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} status * @param {string} status
*/ */
set status(status) { set status(status) {
if (check12ValidFormat(status, regex.CMIStatus2)) { if (check12ValidFormat(status, scorm12_regex.CMIStatus2)) {
this.#status = status; this.#status = status;
} }
} }
@@ -1131,7 +1132,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check12ValidFormat(id, regex.CMIIdentifier)) { if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -1181,7 +1182,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
* @param {string} pattern * @param {string} pattern
*/ */
set pattern(pattern) { set pattern(pattern) {
if (check12ValidFormat(pattern, regex.CMIFeedback, true)) { if (check12ValidFormat(pattern, scorm12_regex.CMIFeedback, true)) {
this.#pattern = pattern; this.#pattern = pattern;
} }
} }
@@ -1230,7 +1231,7 @@ export class NAV extends BaseCMI {
* @param {string} event * @param {string} event
*/ */
set event(event) { set event(event) {
if (check12ValidFormat(event, regex.NAVEvent)) { if (check12ValidFormat(event, scorm12_regex.NAVEvent)) {
this.#event = event; this.#event = event;
} }
} }
+84 -77
View File
@@ -6,15 +6,18 @@ import {
CMIArray, CMIArray,
CMIScore, CMIScore,
} from './common'; } from './common';
import {scorm2004_constants} from '../constants/api_constants'; import APIConstants from '../constants/api_constants';
import {scorm2004_regex} from '../constants/regex'; import Regex from '../constants/regex';
import {scorm2004_error_codes} from '../constants/error_codes'; import ErrorCodes from '../constants/error_codes';
import {learner_responses} from '../constants/response_constants'; import Responses from '../constants/response_constants';
import {ValidationError} from '../exceptions'; import {ValidationError} from '../exceptions';
import * as Util from '../utilities'; import * as Util from '../utilities';
const constants = scorm2004_constants; const scorm2004_constants = APIConstants.scorm2004;
const regex = scorm2004_regex; const scorm2004_error_codes = ErrorCodes.scorm2004;
const learner_responses = Responses.learner;
const scorm2004_regex = Regex.scorm2004;
/** /**
* Helper method for throwing Read Only error * Helper method for throwing Read Only error
@@ -85,7 +88,7 @@ export class CMI extends BaseCMI {
} }
#_version = '1.0'; #_version = '1.0';
#_children = constants.cmi_children; #_children = scorm2004_constants.cmi_children;
#completion_status = 'unknown'; #completion_status = 'unknown';
#completion_threshold = ''; #completion_threshold = '';
#credit = 'credit'; #credit = 'credit';
@@ -167,7 +170,7 @@ export class CMI extends BaseCMI {
* @param {string} completion_status * @param {string} completion_status
*/ */
set completion_status(completion_status) { set completion_status(completion_status) {
if (check2004ValidFormat(completion_status, regex.CMICStatus)) { if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
this.#completion_status = completion_status; this.#completion_status = completion_status;
} }
} }
@@ -235,7 +238,7 @@ export class CMI extends BaseCMI {
* @param {string} exit * @param {string} exit
*/ */
set exit(exit) { set exit(exit) {
if (check2004ValidFormat(exit, regex.CMIExit, true)) { if (check2004ValidFormat(exit, scorm2004_regex.CMIExit, true)) {
this.#exit = exit; this.#exit = exit;
} }
} }
@@ -303,7 +306,7 @@ export class CMI extends BaseCMI {
* @param {string} location * @param {string} location
*/ */
set location(location) { set location(location) {
if (check2004ValidFormat(location, regex.CMIString1000)) { if (check2004ValidFormat(location, scorm2004_regex.CMIString1000)) {
this.#location = location; this.#location = location;
} }
} }
@@ -355,8 +358,8 @@ export class CMI extends BaseCMI {
* @param {string} progress_measure * @param {string} progress_measure
*/ */
set progress_measure(progress_measure) { set progress_measure(progress_measure) {
if (check2004ValidFormat(progress_measure, regex.CMIDecimal) && if (check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(progress_measure, regex.progress_range)) { check2004ValidRange(progress_measure, scorm2004_regex.progress_range)) {
this.#progress_measure = progress_measure; this.#progress_measure = progress_measure;
} }
} }
@@ -392,7 +395,7 @@ export class CMI extends BaseCMI {
* @param {string} session_time * @param {string} session_time
*/ */
set session_time(session_time) { set session_time(session_time) {
if (check2004ValidFormat(session_time, regex.CMITimespan)) { if (check2004ValidFormat(session_time, scorm2004_regex.CMITimespan)) {
this.#session_time = session_time; this.#session_time = session_time;
} }
} }
@@ -410,7 +413,7 @@ export class CMI extends BaseCMI {
* @param {string} success_status * @param {string} success_status
*/ */
set success_status(success_status) { set success_status(success_status) {
if (check2004ValidFormat(success_status, regex.CMISStatus)) { if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
this.#success_status = success_status; this.#success_status = success_status;
} }
} }
@@ -428,7 +431,7 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data * @param {string} suspend_data
*/ */
set suspend_data(suspend_data) { set suspend_data(suspend_data) {
if (check2004ValidFormat(suspend_data, regex.CMIString64000, true)) { if (check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000, true)) {
this.#suspend_data = suspend_data; this.#suspend_data = suspend_data;
} }
} }
@@ -547,7 +550,7 @@ export class CMI extends BaseCMI {
* Class for SCORM 2004's cmi.learner_preference object * Class for SCORM 2004's cmi.learner_preference object
*/ */
class CMILearnerPreference extends BaseCMI { class CMILearnerPreference extends BaseCMI {
#_children = constants.student_preference_children; #_children = scorm2004_constants.student_preference_children;
#audio_level = '1'; #audio_level = '1';
#language = ''; #language = '';
#delivery_speed = '1'; #delivery_speed = '1';
@@ -591,8 +594,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} audio_level * @param {string} audio_level
*/ */
set audio_level(audio_level) { set audio_level(audio_level) {
if (check2004ValidFormat(audio_level, regex.CMIDecimal) && if (check2004ValidFormat(audio_level, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(audio_level, regex.audio_range)) { check2004ValidRange(audio_level, scorm2004_regex.audio_range)) {
this.#audio_level = audio_level; this.#audio_level = audio_level;
} }
} }
@@ -610,7 +613,7 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} language * @param {string} language
*/ */
set language(language) { set language(language) {
if (check2004ValidFormat(language, regex.CMILang)) { if (check2004ValidFormat(language, scorm2004_regex.CMILang)) {
this.#language = language; this.#language = language;
} }
} }
@@ -628,8 +631,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} delivery_speed * @param {string} delivery_speed
*/ */
set delivery_speed(delivery_speed) { set delivery_speed(delivery_speed) {
if (check2004ValidFormat(delivery_speed, regex.CMIDecimal) && if (check2004ValidFormat(delivery_speed, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(delivery_speed, regex.speed_range)) { check2004ValidRange(delivery_speed, scorm2004_regex.speed_range)) {
this.#delivery_speed = delivery_speed; this.#delivery_speed = delivery_speed;
} }
} }
@@ -647,8 +650,8 @@ class CMILearnerPreference extends BaseCMI {
* @param {string} audio_captioning * @param {string} audio_captioning
*/ */
set audio_captioning(audio_captioning) { set audio_captioning(audio_captioning) {
if (check2004ValidFormat(audio_captioning, regex.CMISInteger) && if (check2004ValidFormat(audio_captioning, scorm2004_regex.CMISInteger) &&
check2004ValidRange(audio_captioning, regex.text_range)) { check2004ValidRange(audio_captioning, scorm2004_regex.text_range)) {
this.#audio_captioning = audio_captioning; this.#audio_captioning = audio_captioning;
} }
} }
@@ -687,7 +690,7 @@ class CMIInteractions extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.interactions_children, children: scorm2004_constants.interactions_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
}); });
} }
@@ -702,7 +705,7 @@ class CMIObjectives extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.objectives_children, children: scorm2004_constants.objectives_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
}); });
} }
@@ -717,7 +720,7 @@ class CMICommentsFromLMS extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.comments_children, children: scorm2004_constants.comments_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
}); });
} }
@@ -732,7 +735,7 @@ class CMICommentsFromLearner extends CMIArray {
*/ */
constructor() { constructor() {
super({ super({
children: constants.comments_children, children: scorm2004_constants.comments_children,
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
}); });
} }
@@ -759,11 +762,11 @@ export class CMIInteractionsObject extends BaseCMI {
this.objectives = new CMIArray({ this.objectives = new CMIArray({
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
children: constants.objectives_children, children: scorm2004_constants.objectives_children,
}); });
this.correct_responses = new CMIArray({ this.correct_responses = new CMIArray({
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
children: constants.correct_responses_children, children: scorm2004_constants.correct_responses_children,
}); });
} }
@@ -789,7 +792,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) { if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -807,7 +810,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} type * @param {string} type
*/ */
set type(type) { set type(type) {
if (check2004ValidFormat(type, regex.CMIType)) { if (check2004ValidFormat(type, scorm2004_regex.CMIType)) {
this.#type = type; this.#type = type;
} }
} }
@@ -825,7 +828,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} timestamp * @param {string} timestamp
*/ */
set timestamp(timestamp) { set timestamp(timestamp) {
if (check2004ValidFormat(timestamp, regex.CMITime)) { if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
this.#timestamp = timestamp; this.#timestamp = timestamp;
} }
} }
@@ -843,7 +846,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} weighting * @param {string} weighting
*/ */
set weighting(weighting) { set weighting(weighting) {
if (check2004ValidFormat(weighting, regex.CMIDecimal)) { if (check2004ValidFormat(weighting, scorm2004_regex.CMIDecimal)) {
this.#weighting = weighting; this.#weighting = weighting;
} }
} }
@@ -868,44 +871,48 @@ export class CMIInteractionsObject extends BaseCMI {
} else { } else {
let nodes = []; let nodes = [];
const response_type = learner_responses[this.type]; const response_type = learner_responses[this.type];
if (response_type.delimiter !== '') { if (response_type) {
nodes = learner_response.split(response_type.delimiter); if (response_type?.delimiter) {
} else { nodes = learner_response.split(response_type.delimiter);
nodes[0] = learner_response; } else {
} nodes[0] = learner_response;
}
if ((nodes.length > 0) && (nodes.length <= response_type.max)) { if ((nodes.length > 0) && (nodes.length <= response_type.max)) {
const formatRegex = new RegExp(response_type.format); const formatRegex = new RegExp(response_type.format);
for (let i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
if (typeof response_type.delimiter2 !== 'undefined') { if (response_type?.delimiter2) {
const values = nodes[i].split(response_type.delimiter2); const values = nodes[i].split(response_type.delimiter2);
if (values.length === 2) { if (values.length === 2) {
if (!values[0].match(formatRegex)) { if (!values[0].match(formatRegex)) {
throwTypeMismatchError();
} else {
if (!values[1].match(new RegExp(response_type.format2))) {
throwTypeMismatchError(); throwTypeMismatchError();
} else {
if (!values[1].match(new RegExp(response_type.format2))) {
throwTypeMismatchError();
}
} }
} else {
throwTypeMismatchError();
} }
} else { } else {
throwTypeMismatchError(); if (!nodes[i].match(formatRegex)) {
} throwTypeMismatchError();
} else { } else {
if (!nodes[i].match(formatRegex)) { if (nodes[i] !== '' && response_type.unique) {
throwTypeMismatchError(); for (let j = 0; j < i; j++) {
} else { if (nodes[i] === nodes[j]) {
if (nodes[i] !== '' && response_type.unique) { throwTypeMismatchError();
for (let j = 0; j < i; j++) { }
if (nodes[i] === nodes[j]) {
throwTypeMismatchError();
} }
} }
} }
} }
} }
} else {
throw new ValidationError(scorm2004_error_codes.GENERAL_SET_FAILURE);
} }
} else { } else {
throw new ValidationError(scorm2004_error_codes.GENERAL_SET_FAILURE); throw new ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
} }
} }
} }
@@ -923,7 +930,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} result * @param {string} result
*/ */
set result(result) { set result(result) {
if (check2004ValidFormat(result, regex.CMIResult)) { if (check2004ValidFormat(result, scorm2004_regex.CMIResult)) {
this.#result = result; this.#result = result;
} }
} }
@@ -941,7 +948,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} latency * @param {string} latency
*/ */
set latency(latency) { set latency(latency) {
if (check2004ValidFormat(latency, regex.CMITimespan)) { if (check2004ValidFormat(latency, scorm2004_regex.CMITimespan)) {
this.#latency = latency; this.#latency = latency;
} }
} }
@@ -959,7 +966,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} description * @param {string} description
*/ */
set description(description) { set description(description) {
if (check2004ValidFormat(description, regex.CMILangString250, true)) { if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
this.#description = description; this.#description = description;
} }
} }
@@ -1041,7 +1048,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) { if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -1059,7 +1066,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} success_status * @param {string} success_status
*/ */
set success_status(success_status) { set success_status(success_status) {
if (check2004ValidFormat(success_status, regex.CMISStatus)) { if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
this.#success_status = success_status; this.#success_status = success_status;
} }
} }
@@ -1077,7 +1084,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} completion_status * @param {string} completion_status
*/ */
set completion_status(completion_status) { set completion_status(completion_status) {
if (check2004ValidFormat(completion_status, regex.CMICStatus)) { if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
this.#completion_status = completion_status; this.#completion_status = completion_status;
} }
} }
@@ -1095,8 +1102,8 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} progress_measure * @param {string} progress_measure
*/ */
set progress_measure(progress_measure) { set progress_measure(progress_measure) {
if (check2004ValidFormat(progress_measure, regex.CMIDecimal) && if (check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(progress_measure, regex.progress_range)) { check2004ValidRange(progress_measure, scorm2004_regex.progress_range)) {
this.#progress_measure = progress_measure; this.#progress_measure = progress_measure;
} }
} }
@@ -1114,7 +1121,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} description * @param {string} description
*/ */
set description(description) { set description(description) {
if (check2004ValidFormat(description, regex.CMILangString250, true)) { if (check2004ValidFormat(description, scorm2004_regex.CMILangString250, true)) {
this.#description = description; this.#description = description;
} }
} }
@@ -1160,7 +1167,7 @@ class Scorm2004CMIScore extends CMIScore {
constructor() { constructor() {
super( super(
{ {
score_children: constants.score_children, score_children: scorm2004_constants.score_children,
max: '', max: '',
invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT, invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH, invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
@@ -1182,8 +1189,8 @@ class Scorm2004CMIScore extends CMIScore {
* @param {string} scaled * @param {string} scaled
*/ */
set scaled(scaled) { set scaled(scaled) {
if (check2004ValidFormat(scaled, regex.CMIDecimal) && if (check2004ValidFormat(scaled, scorm2004_regex.CMIDecimal) &&
check2004ValidRange(scaled, regex.scaled_range)) { check2004ValidRange(scaled, scorm2004_regex.scaled_range)) {
this.#scaled = scaled; this.#scaled = scaled;
} }
} }
@@ -1250,7 +1257,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) { if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError(); throwReadOnlyError();
} else { } else {
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) { if (check2004ValidFormat(comment, scorm2004_regex.CMILangString4000, true)) {
this.#comment = comment; this.#comment = comment;
} }
} }
@@ -1272,7 +1279,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) { if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError(); throwReadOnlyError();
} else { } else {
if (check2004ValidFormat(location, regex.CMIString250)) { if (check2004ValidFormat(location, scorm2004_regex.CMIString250)) {
this.#location = location; this.#location = location;
} }
} }
@@ -1294,7 +1301,7 @@ export class CMICommentsObject extends BaseCMI {
if (this.initialized && this.#readOnlyAfterInit) { if (this.initialized && this.#readOnlyAfterInit) {
throwReadOnlyError(); throwReadOnlyError();
} else { } else {
if (check2004ValidFormat(timestamp, regex.CMITime)) { if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
this.#timestamp = timestamp; this.#timestamp = timestamp;
} }
} }
@@ -1348,7 +1355,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
* @param {string} id * @param {string} id
*/ */
set id(id) { set id(id) {
if (check2004ValidFormat(id, regex.CMILongIdentifier)) { if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
this.#id = id; this.#id = id;
} }
} }
@@ -1397,7 +1404,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
* @param {string} pattern * @param {string} pattern
*/ */
set pattern(pattern) { set pattern(pattern) {
if (check2004ValidFormat(pattern, regex.CMIFeedback)) { if (check2004ValidFormat(pattern, scorm2004_regex.CMIFeedback)) {
this.#pattern = pattern; this.#pattern = pattern;
} }
} }
@@ -1497,7 +1504,7 @@ class ADLNav extends BaseCMI {
* @param {string} request * @param {string} request
*/ */
set request(request) { set request(request) {
if (check2004ValidFormat(request, regex.NAVEvent)) { if (check2004ValidFormat(request, scorm2004_regex.NAVEvent)) {
this.#request = request; this.#request = request;
} }
} }
+14 -5
View File
@@ -1,6 +1,6 @@
// @flow // @flow
export const global_constants = { const global = {
SCORM_TRUE: 'true', SCORM_TRUE: 'true',
SCORM_FALSE: 'false', SCORM_FALSE: 'false',
STATE_NOT_INITIALIZED: 0, STATE_NOT_INITIALIZED: 0,
@@ -13,7 +13,7 @@ export const global_constants = {
LOG_LEVEL_NONE: 5, LOG_LEVEL_NONE: 5,
}; };
export const scorm12_constants = { const scorm12 = {
// Children lists // Children lists
cmi_children: 'core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions', cmi_children: 'core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions',
core_children: 'student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,lesson_mode,exit,session_time', core_children: 'student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,lesson_mode,exit,session_time',
@@ -69,15 +69,15 @@ export const scorm12_constants = {
}, },
}; };
export const aicc_constants = { const aicc = {
...scorm12_constants, ...{ ...scorm12, ...{
cmi_children: 'core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions,evaluation', cmi_children: 'core,suspend_data,launch_data,comments,objectives,student_data,student_preference,interactions,evaluation',
student_data_children: 'attempt_number,tries,mastery_score,max_time_allowed,time_limit_action', student_data_children: 'attempt_number,tries,mastery_score,max_time_allowed,time_limit_action',
tries_children: 'time,status,score', tries_children: 'time,status,score',
}, },
}; };
export const scorm2004_constants = { const scorm2004 = {
// Children lists // Children lists
cmi_children: '_version,comments_from_learner,comments_from_lms,completion_status,credit,entry,exit,interactions,launch_data,learner_id,learner_name,learner_preference,location,max_time_allowed,mode,objectives,progress_measure,scaled_passing_score,score,session_time,success_status,suspend_data,time_limit_action,total_time', cmi_children: '_version,comments_from_learner,comments_from_lms,completion_status,credit,entry,exit,interactions,launch_data,learner_id,learner_name,learner_preference,location,max_time_allowed,mode,objectives,progress_measure,scaled_passing_score,score,session_time,success_status,suspend_data,time_limit_action,total_time',
comments_children: 'comment,timestamp,location', comments_children: 'comment,timestamp,location',
@@ -195,3 +195,12 @@ export const scorm2004_constants = {
}, },
}, },
}; };
const APIConstants = {
global: global,
scorm12: scorm12,
aicc: aicc,
scorm2004: scorm2004,
};
export default APIConstants;
+12 -5
View File
@@ -1,5 +1,5 @@
// @flow // @flow
export const error_codes = { const global = {
GENERAL: 101, GENERAL: 101,
INITIALIZATION_FAILED: 101, INITIALIZATION_FAILED: 101,
INITIALIZED: 101, INITIALIZED: 101,
@@ -30,8 +30,8 @@ export const error_codes = {
DEPENDENCY_NOT_ESTABLISHED: 101, DEPENDENCY_NOT_ESTABLISHED: 101,
}; };
export const scorm12_error_codes = { const scorm12 = {
...error_codes, ...{ ...global, ...{
RETRIEVE_BEFORE_INIT: 301, RETRIEVE_BEFORE_INIT: 301,
STORE_BEFORE_INIT: 301, STORE_BEFORE_INIT: 301,
COMMIT_BEFORE_INIT: 301, COMMIT_BEFORE_INIT: 301,
@@ -50,8 +50,8 @@ export const scorm12_error_codes = {
}, },
}; };
export const scorm2004_error_codes = { const scorm2004 = {
...error_codes, ...{ ...global, ...{
INITIALIZATION_FAILED: 102, INITIALIZATION_FAILED: 102,
INITIALIZED: 103, INITIALIZED: 103,
TERMINATED: 104, TERMINATED: 104,
@@ -78,3 +78,10 @@ export const scorm2004_error_codes = {
DEPENDENCY_NOT_ESTABLISHED: 408, DEPENDENCY_NOT_ESTABLISHED: 408,
}, },
}; };
const ErrorCodes = {
scorm12: scorm12,
scorm2004: scorm2004,
};
export default ErrorCodes;
+3 -1
View File
@@ -1,4 +1,4 @@
export const valid_languages = { const ValidLanguages = {
'aa': 'aa', 'ab': 'ab', 'ae': 'ae', 'af': 'af', 'ak': 'ak', 'am': 'am', 'aa': 'aa', 'ab': 'ab', 'ae': 'ae', 'af': 'af', 'ak': 'ak', 'am': 'am',
'an': 'an', 'ar': 'ar', 'as': 'as', 'av': 'av', 'ay': 'ay', 'az': 'az', 'an': 'an', 'ar': 'ar', 'as': 'as', 'av': 'av', 'ay': 'ay', 'az': 'az',
'ba': 'ba', 'be': 'be', 'bg': 'bg', 'bh': 'bh', 'bi': 'bi', 'bm': 'bm', 'ba': 'ba', 'be': 'be', 'bg': 'bg', 'bh': 'bh', 'bi': 'bi', 'bm': 'bm',
@@ -72,3 +72,5 @@ export const valid_languages = {
'vol': 'vol', 'wln': 'wln', 'wol': 'wol', 'xho': 'xho', 'yid': 'yid', 'vol': 'vol', 'wln': 'wln', 'wol': 'wol', 'xho': 'xho', 'yid': 'yid',
'yor': 'yor', 'zha': 'zha', 'chi': 'chi', 'zho': 'zho', 'zul': 'zul', 'yor': 'yor', 'zha': 'zha', 'chi': 'chi', 'zho': 'zho', 'zul': 'zul',
}; };
export default ValidLanguages;
+12 -4
View File
@@ -1,6 +1,6 @@
// @flow // @flow
export const scorm12_regex = { const scorm12 = {
CMIString256: '^.{0,255}$', CMIString256: '^.{0,255}$',
CMIString4096: '^.{0,4096}$', CMIString4096: '^.{0,4096}$',
CMITime: '^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$', // eslint-disable-line CMITime: '^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$', // eslint-disable-line
@@ -28,13 +28,13 @@ export const scorm12_regex = {
text_range: '-1#1', text_range: '-1#1',
}; };
export const aicc_regex = { const aicc = {
...scorm12_regex, ...{ ...scorm12, ...{
CMIIdentifier: '^\\w{1,255}$', CMIIdentifier: '^\\w{1,255}$',
}, },
}; };
export const scorm2004_regex = { const scorm2004 = {
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$', CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$', CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$', CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
@@ -74,3 +74,11 @@ export const scorm2004_regex = {
text_range: '-1#1', text_range: '-1#1',
progress_range: '0#1', progress_range: '0#1',
}; };
const Regex = {
aicc: aicc,
scorm12: scorm12,
scorm2004: scorm2004,
};
export default Regex;
+12 -3
View File
@@ -1,7 +1,9 @@
// @flow // @flow
import {scorm2004_regex} from './regex'; import Regex from './regex';
export const learner_responses = { const scorm2004_regex = Regex.scorm2004;
const learner = {
'true-false': { 'true-false': {
format: '^true$|^false$', format: '^true$|^false$',
max: 1, max: 1,
@@ -69,7 +71,7 @@ export const learner_responses = {
}, },
}; };
export const correct_responses = { const correct = {
'true-false': { 'true-false': {
max: 1, max: 1,
delimiter: '', delimiter: '',
@@ -150,3 +152,10 @@ export const correct_responses = {
limit: 1, limit: 1,
}, },
}; };
const Responses = {
learner: learner,
correct: correct,
};
export default Responses;
+9 -7
View File
@@ -143,10 +143,10 @@ export function addTwoDurations(
first: String, first: String,
second: String, second: String,
durationRegex: RegExp) { durationRegex: RegExp) {
const firstSeconds = getDurationAsSeconds(first, durationRegex); return getSecondsAsISODuration(
const secondSeconds = getDurationAsSeconds(second, durationRegex); getDurationAsSeconds(first, durationRegex) +
getDurationAsSeconds(second, durationRegex),
return getSecondsAsISODuration(firstSeconds + secondSeconds); );
} }
/** /**
@@ -161,9 +161,11 @@ export function addHHMMSSTimeStrings(
first: String, first: String,
second: String, second: String,
timeRegex: RegExp) { timeRegex: RegExp) {
const firstSeconds = getTimeAsSeconds(first, timeRegex); return getSecondsAsHHMMSS(
const secondSeconds = getTimeAsSeconds(second, timeRegex); getTimeAsSeconds(first, timeRegex) +
return getSecondsAsHHMMSS(firstSeconds + secondSeconds); getTimeAsSeconds(
second, timeRegex),
);
} }
/** /**
+3 -1
View File
@@ -1,9 +1,11 @@
import {expect} from 'chai'; import {expect} from 'chai';
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import * as h from './api_helpers'; import * as h from './api_helpers';
import {scorm12_error_codes} from '../src/constants/error_codes'; import ErrorCodes from '../src/constants/error_codes';
import AICC from '../src/AICC'; import AICC from '../src/AICC';
const scorm12_error_codes = ErrorCodes.scorm12;
const api = () => { const api = () => {
const API = new AICC(); const API = new AICC();
API.apiLogLevel = 1; API.apiLogLevel = 1;
+26 -1
View File
@@ -2,9 +2,11 @@ import {expect} from 'chai';
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import Scorm12API from '../src/Scorm12API'; import Scorm12API from '../src/Scorm12API';
import * as h from './api_helpers'; import * as h from './api_helpers';
import {scorm12_error_codes} from '../src/constants/error_codes'; import ErrorCodes from '../src/constants/error_codes';
import {scorm12_values} from './field_values'; import {scorm12_values} from './field_values';
const scorm12_error_codes = ErrorCodes.scorm12;
const api = (settings = {}) => { const api = (settings = {}) => {
const API = new Scorm12API(settings); const API = new Scorm12API(settings);
API.apiLogLevel = 1; API.apiLogLevel = 1;
@@ -278,6 +280,11 @@ describe('SCORM 1.2 API Tests', () => {
fieldName: 'cmi.interactions.0.id', fieldName: 'cmi.interactions.0.id',
valueToTest: 'AAA', valueToTest: 'AAA',
}); });
h.checkLMSSetValue({
api: apiInitialized(),
fieldName: 'cmi.interactions.0.correct_responses.0.pattern',
valueToTest: 't',
});
}); });
}); });
@@ -307,6 +314,24 @@ describe('SCORM 1.2 API Tests', () => {
}); });
}); });
describe('renderCommitCMI()', () => {
it('if the user passes, should calculate total time when terminateCommit passed',
() => {
const scorm12API = api();
scorm12API.cmi.core.score.max = '100';
scorm12API.cmi.core.score.min = '0';
scorm12API.cmi.core.score.raw = '100';
scorm12API.cmi.core.exit = 'suspend';
scorm12API.cmi.core.lesson_status = 'completed';
scorm12API.cmi.core.total_time = '0000:00:00';
scorm12API.cmi.core.session_time = '23:59:59';
const cmiExport = scorm12API.renderCommitCMI(true);
expect(
cmiExport.cmi.core.total_time,
).to.equal('23:59:59');
});
});
describe('storeData()', () => { describe('storeData()', () => {
it('should set cmi.core.lesson_status to "completed"', () => { it('should set cmi.core.lesson_status to "completed"', () => {
const scorm12API = api(); const scorm12API = api();
+21 -4
View File
@@ -1,17 +1,25 @@
import {expect} from 'chai'; import {expect} from 'chai';
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import * as h from './api_helpers'; import * as h from './api_helpers';
import {scorm2004_error_codes} from '../src/constants/error_codes'; import ErrorCodes from '../src/constants/error_codes';
import Scorm2004API from '../src/Scorm2004API'; import Scorm2004API from '../src/Scorm2004API';
import {scorm2004_values} from './field_values'; import {scorm2004_values} from './field_values';
const api = () => { const scorm2004_error_codes = ErrorCodes.scorm2004;
const api = (startingData) => {
const API = new Scorm2004API(); const API = new Scorm2004API();
API.apiLogLevel = 1; API.apiLogLevel = 1;
if (startingData) {
API.startingData = startingData;
}
return API; return API;
}; };
const apiInitialized = () => { const apiInitialized = (startingData) => {
const API = api(); const API = api();
if (startingData) {
API.startingData = startingData;
}
API.lmsInitialize(); API.lmsInitialize();
return API; return API;
}; };
@@ -288,6 +296,15 @@ describe('SCORM 2004 API Tests', () => {
valueToTest: scorm2004_values.validTimestamps[0], valueToTest: scorm2004_values.validTimestamps[0],
errorThrown: false, errorThrown: false,
}); });
it('should allow cmi.interactions.0.correct_responses.0.pattern to be set',
() => {
const scorm2004API = apiInitialized();
scorm2004API.setCMIValue('cmi.interactions.0.type', 'true-false');
scorm2004API.setCMIValue('cmi.interactions.0.correct_responses.0.pattern', 'true');
expect(
String(scorm2004API.lmsGetLastError())
).to.equal(String(0));
});
}); });
describe('Initialized - Should Fail', () => { describe('Initialized - Should Fail', () => {
@@ -323,7 +340,7 @@ describe('SCORM 2004 API Tests', () => {
scorm2004API.cmi.session_time = 'PT23H59M59S'; scorm2004API.cmi.session_time = 'PT23H59M59S';
const cmiExport = scorm2004API.renderCommitCMI(true); const cmiExport = scorm2004API.renderCommitCMI(true);
expect( expect(
cmiExport.cmi.total_time cmiExport.cmi.total_time,
).to.equal('P1DT12H34M55S'); ).to.equal('P1DT12H34M55S');
}); });
}); });
+5 -2
View File
@@ -1,6 +1,6 @@
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import {aicc_constants} from '../../src/constants/api_constants'; import APIConstants from '../../src/constants/api_constants';
import {scorm12_error_codes} from '../../src/constants/error_codes'; import ErrorCodes from '../../src/constants/error_codes';
import { import {
CMI, CMI,
CMIEvaluationCommentsObject, CMIEvaluationCommentsObject,
@@ -15,6 +15,9 @@ import {
import {expect} from 'chai'; import {expect} from 'chai';
import {scorm12_values} from '../field_values'; import {scorm12_values} from '../field_values';
const aicc_constants = APIConstants.aicc;
const scorm12_error_codes = ErrorCodes.scorm12;
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE; const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm12_error_codes.TYPE_MISMATCH; const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT; const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
+25 -17
View File
@@ -1,7 +1,7 @@
import {expect} from 'chai'; import {expect} from 'chai';
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import {scorm12_constants} from '../../src/constants/api_constants'; import APIConstants from '../../src/constants/api_constants';
import {scorm12_error_codes} from '../../src/constants/error_codes'; import ErrorCodes from '../../src/constants/error_codes';
import { import {
CMI, CMI,
CMIInteractionsCorrectResponsesObject, CMIInteractionsCorrectResponsesObject,
@@ -12,6 +12,9 @@ import {
import * as h from '../cmi_helpers'; import * as h from '../cmi_helpers';
import {scorm12_values} from '../field_values'; import {scorm12_values} from '../field_values';
const scorm12 = APIConstants.scorm12;
const scorm12_error_codes = ErrorCodes.scorm12;
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE; const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm12_error_codes.TYPE_MISMATCH; const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT; const write_only = scorm12_error_codes.WRITE_ONLY_ELEMENT;
@@ -101,7 +104,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi._children', fieldName: 'cmi._children',
expectedValue: scorm12_constants.cmi_children, expectedValue: scorm12.cmi_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
@@ -131,7 +134,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.core._children', fieldName: 'cmi.core._children',
expectedValue: scorm12_constants.core_children, expectedValue: scorm12.core_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadAndWrite({ h.checkReadAndWrite({
@@ -206,7 +209,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.core.score._children', fieldName: 'cmi.core.score._children',
expectedValue: scorm12_constants.score_children, expectedValue: scorm12.score_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkRead({ h.checkRead({
@@ -247,7 +250,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.objectives._children', fieldName: 'cmi.objectives._children',
expectedValue: scorm12_constants.objectives_children, expectedValue: scorm12.objectives_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -263,7 +266,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.student_data._children', fieldName: 'cmi.student_data._children',
expectedValue: scorm12_constants.student_data_children, expectedValue: scorm12.student_data_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadAndWrite({ h.checkReadAndWrite({
@@ -285,7 +288,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.student_preference._children', fieldName: 'cmi.student_preference._children',
expectedValue: scorm12_constants.student_preference_children, expectedValue: scorm12.student_preference_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkRead({ h.checkRead({
@@ -333,7 +336,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmi(), cmi: cmi(),
fieldName: 'cmi.interactions._children', fieldName: 'cmi.interactions._children',
expectedValue: scorm12_constants.interactions_children, expectedValue: scorm12.interactions_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -357,7 +360,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi._children', fieldName: 'cmi._children',
expectedValue: scorm12_constants.cmi_children, expectedValue: scorm12.cmi_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkFieldConstraintSize({ h.checkFieldConstraintSize({
@@ -366,6 +369,11 @@ describe('SCORM 1.2 CMI Tests', () => {
limit: 4096, limit: 4096,
expectedError: type_mismatch, expectedError: type_mismatch,
}); });
h.checkWrite({
cmi: cmiInitialized(),
fieldName: 'cmi.suspend_data',
valueToTest: '',
});
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.launch_data', fieldName: 'cmi.launch_data',
@@ -389,7 +397,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.core._children', fieldName: 'cmi.core._children',
expectedValue: scorm12_constants.core_children, expectedValue: scorm12.core_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -470,7 +478,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.core.score._children', fieldName: 'cmi.core.score._children',
expectedValue: scorm12_constants.score_children, expectedValue: scorm12.score_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkValidValues({ h.checkValidValues({
@@ -498,7 +506,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.objectives._children', fieldName: 'cmi.objectives._children',
expectedValue: scorm12_constants.objectives_children, expectedValue: scorm12.objectives_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -514,7 +522,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.student_data._children', fieldName: 'cmi.student_data._children',
expectedValue: scorm12_constants.student_data_children, expectedValue: scorm12.student_data_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -539,7 +547,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.student_preference._children', fieldName: 'cmi.student_preference._children',
expectedValue: scorm12_constants.student_preference_children, expectedValue: scorm12.student_preference_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkValidValues({ h.checkValidValues({
@@ -573,7 +581,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: cmiInitialized(), cmi: cmiInitialized(),
fieldName: 'cmi.interactions._children', fieldName: 'cmi.interactions._children',
expectedValue: scorm12_constants.interactions_children, expectedValue: scorm12.interactions_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkReadOnly({ h.checkReadOnly({
@@ -768,7 +776,7 @@ describe('SCORM 1.2 CMI Tests', () => {
h.checkReadOnly({ h.checkReadOnly({
cmi: objective(), cmi: objective(),
fieldName: 'cmi.score._children', fieldName: 'cmi.score._children',
expectedValue: scorm12_constants.score_children, expectedValue: scorm12.score_children,
expectedError: invalid_set, expectedError: invalid_set,
}); });
h.checkRead({ h.checkRead({
+5 -2
View File
@@ -1,6 +1,6 @@
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import {scorm2004_error_codes} from '../../src/constants/error_codes'; import ErrorCodes from '../../src/constants/error_codes';
import {scorm2004_constants} from '../../src/constants/api_constants'; import APIConstants from '../../src/constants/api_constants';
import { import {
ADL, ADL,
CMI, CMI,
@@ -14,6 +14,9 @@ import * as h from '../cmi_helpers';
import {expect} from 'chai'; import {expect} from 'chai';
import {scorm2004_values} from '../field_values'; import {scorm2004_values} from '../field_values';
const scorm2004_constants = APIConstants.scorm2004;
const scorm2004_error_codes = ErrorCodes.scorm2004;
const read_only = scorm2004_error_codes.READ_ONLY_ELEMENT; const read_only = scorm2004_error_codes.READ_ONLY_ELEMENT;
const write_only = scorm2004_error_codes.WRITE_ONLY_ELEMENT; const write_only = scorm2004_error_codes.WRITE_ONLY_ELEMENT;
const type_mismatch = scorm2004_error_codes.TYPE_MISMATCH; const type_mismatch = scorm2004_error_codes.TYPE_MISMATCH;
+4 -1
View File
@@ -1,7 +1,10 @@
import {expect} from 'chai'; import {expect} from 'chai';
import {describe, it} from 'mocha'; import {describe, it} from 'mocha';
import * as Utilities from '../src/utilities'; import * as Utilities from '../src/utilities';
import {scorm12_regex, scorm2004_regex} from '../src/constants/regex'; import Regex from '../src/constants/regex';
const scorm12_regex = Regex.scorm12;
const scorm2004_regex = Regex.scorm2004;
describe('Utility Tests', () => { describe('Utility Tests', () => {
describe('getSecondsAsHHMMSS()', () => { describe('getSecondsAsHHMMSS()', () => {