Adding more API tests
This commit is contained in:
@@ -34,9 +34,9 @@ export default class AICC extends Scorm12API {
|
|||||||
|
|
||||||
if (!newChild) {
|
if (!newChild) {
|
||||||
if (this.stringMatches(CMIElement, 'cmi\\.evaluation\\.comments\\.\\d')) {
|
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')) {
|
} 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);
|
returnValue = this.setCMIValue(CMIElement, value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ValidationError) {
|
if (e instanceof ValidationError) {
|
||||||
|
this.lastErrorCode = e.errorCode;
|
||||||
returnValue = api_constants.SCORM_FALSE;
|
returnValue = api_constants.SCORM_FALSE;
|
||||||
} else {
|
} else {
|
||||||
this.throwSCORMError(this.#error_codes.GENERAL);
|
this.throwSCORMError(this.#error_codes.GENERAL);
|
||||||
@@ -160,7 +161,9 @@ export default class BaseAPI {
|
|||||||
this.processListeners(callbackName, CMIElement, value);
|
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,
|
this.apiLog(callbackName, CMIElement,
|
||||||
': ' + value + ': result: ' + returnValue,
|
': ' + value + ': result: ' + returnValue,
|
||||||
@@ -382,7 +385,8 @@ export default class BaseAPI {
|
|||||||
* @abstract
|
* @abstract
|
||||||
*/
|
*/
|
||||||
getLmsErrorMessageDetails(_errorNumber, _detail) {
|
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)) {
|
} else if (!this._checkObjectHasProperty(refObject, attribute)) {
|
||||||
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||||
} else {
|
} else {
|
||||||
if (this.stringMatches(CMIElement, '.correct_responses')) {
|
if (this.stringMatches(CMIElement, '\\.correct_responses\\.\\d')) {
|
||||||
this.validateCorrectResponse(CMIElement, value);
|
this.validateCorrectResponse(CMIElement, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,12 +475,15 @@ export default class BaseAPI {
|
|||||||
if (item) {
|
if (item) {
|
||||||
refObject = item;
|
refObject = item;
|
||||||
} else {
|
} else {
|
||||||
const newChild = this.getChildElement(CMIElement, value, foundFirstIndex);
|
const newChild = this.getChildElement(CMIElement, value,
|
||||||
|
foundFirstIndex);
|
||||||
foundFirstIndex = true;
|
foundFirstIndex = true;
|
||||||
|
|
||||||
if (!newChild) {
|
if (!newChild) {
|
||||||
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
this.throwSCORMError(invalidErrorCode, invalidErrorMessage);
|
||||||
} else {
|
} else {
|
||||||
|
if (refObject.initialized) newChild.initialize();
|
||||||
|
|
||||||
refObject.childArray.push(newChild);
|
refObject.childArray.push(newChild);
|
||||||
refObject = newChild;
|
refObject = newChild;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,13 +148,13 @@ export default class Scorm12API extends BaseAPI {
|
|||||||
let newChild;
|
let newChild;
|
||||||
|
|
||||||
if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) {
|
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')) {
|
} 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')) {
|
} 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')) {
|
} else if (this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d')) {
|
||||||
newChild = new CMIInteractionsObject(this);
|
newChild = new CMIInteractionsObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
return newChild;
|
return newChild;
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import BaseAPI from './BaseAPI';
|
|||||||
import {
|
import {
|
||||||
ADL,
|
ADL,
|
||||||
CMI,
|
CMI,
|
||||||
CMICommentsFromLearnerObject,
|
CMICommentsObject,
|
||||||
CMICommentsFromLMSObject,
|
|
||||||
CMIInteractionsCorrectResponsesObject,
|
CMIInteractionsCorrectResponsesObject,
|
||||||
CMIInteractionsObject,
|
CMIInteractionsObject,
|
||||||
CMIInteractionsObjectivesObject,
|
CMIInteractionsObjectivesObject,
|
||||||
@@ -128,9 +127,10 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
*
|
*
|
||||||
* @param {string} CMIElement
|
* @param {string} CMIElement
|
||||||
* @param {any} value
|
* @param {any} value
|
||||||
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
setCMIValue(CMIElement, value) {
|
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;
|
let newChild;
|
||||||
|
|
||||||
if (this.stringMatches(CMIElement, 'cmi\\.objectives\\.\\d')) {
|
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')) {
|
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.correct_responses\\.\\d')) {
|
||||||
const parts = CMIElement.split('.');
|
const parts = CMIElement.split('.');
|
||||||
const index = Number(parts[2]);
|
const index = Number(parts[2]);
|
||||||
@@ -181,16 +181,16 @@ export default class Scorm2004API extends BaseAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.lastErrorCode === 0) {
|
if (this.lastErrorCode === 0) {
|
||||||
newChild = new CMIInteractionsCorrectResponsesObject(this);
|
newChild = new CMIInteractionsCorrectResponsesObject();
|
||||||
}
|
}
|
||||||
} else if (foundFirstIndex && this.stringMatches(CMIElement, 'cmi\\.interactions\\.\\d\\.objectives\\.\\d')) {
|
} 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')) {
|
} 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')) {
|
} 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')) {
|
} else if (this.stringMatches(CMIElement, 'cmi\\.comments_from_lms\\.\\d')) {
|
||||||
newChild = new CMICommentsFromLMSObject(this);
|
newChild = new CMICommentsObject(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newChild;
|
return newChild;
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ export function check12ValidRange(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing the cmi object for SCORM 1.2
|
* Class representing the cmi object for SCORM 1.2
|
||||||
* @extends BaseCMI
|
|
||||||
*/
|
*/
|
||||||
export class CMI extends BaseCMI {
|
export class CMI extends BaseCMI {
|
||||||
#_children = '';
|
#_children = '';
|
||||||
|
|||||||
@@ -94,14 +94,14 @@ export class CMI extends BaseCMI {
|
|||||||
constructor(initialized: boolean) {
|
constructor(initialized: boolean) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (initialized) this.initialize();
|
|
||||||
|
|
||||||
this.learner_preference = new CMILearnerPreference();
|
this.learner_preference = new CMILearnerPreference();
|
||||||
this.score = new Scorm2004CMIScore();
|
this.score = new Scorm2004CMIScore();
|
||||||
this.comments_from_learner = new CMICommentsFromLearner();
|
this.comments_from_learner = new CMICommentsFromLearner();
|
||||||
this.comments_from_lms = new CMICommentsFromLMS();
|
this.comments_from_lms = new CMICommentsFromLMS();
|
||||||
this.interactions = new CMIInteractions();
|
this.interactions = new CMIInteractions();
|
||||||
this.objectives = new CMIObjectives();
|
this.objectives = new CMIObjectives();
|
||||||
|
|
||||||
|
if (initialized) this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1150,7 +1150,7 @@ class Scorm2004CMIScore extends CMIScore {
|
|||||||
{
|
{
|
||||||
score_children: constants.score_children,
|
score_children: constants.score_children,
|
||||||
max: '',
|
max: '',
|
||||||
invalidErrorCode: scorm2004_error_codes.INVALID_SET_VALUE,
|
invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
|
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
|
||||||
invalidRangeCode: scorm2004_error_codes.VALUE_OUT_OF_RANGE,
|
invalidRangeCode: scorm2004_error_codes.VALUE_OUT_OF_RANGE,
|
||||||
decimalRegex: scorm2004_regex.CMIDecimal,
|
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 = '';
|
#comment = '';
|
||||||
#location = '';
|
#location = '';
|
||||||
#timestamp = '';
|
#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();
|
super();
|
||||||
this.#comment = '';
|
this.#comment = '';
|
||||||
this.#location = '';
|
this.#location = '';
|
||||||
this.#timestamp = '';
|
this.#timestamp = '';
|
||||||
|
this.#readOnlyAfterInit = readOnlyAfterInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1232,10 +1235,14 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
|||||||
* @param {string} comment
|
* @param {string} comment
|
||||||
*/
|
*/
|
||||||
set comment(comment) {
|
set comment(comment) {
|
||||||
|
if (this.initialized && this.#readOnlyAfterInit) {
|
||||||
|
throwReadOnlyError();
|
||||||
|
} else {
|
||||||
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) {
|
if (check2004ValidFormat(comment, regex.CMILangString4000, true)) {
|
||||||
this.#comment = comment;
|
this.#comment = comment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for #location
|
* Getter for #location
|
||||||
@@ -1250,10 +1257,14 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
|||||||
* @param {string} location
|
* @param {string} location
|
||||||
*/
|
*/
|
||||||
set location(location) {
|
set location(location) {
|
||||||
|
if (this.initialized && this.#readOnlyAfterInit) {
|
||||||
|
throwReadOnlyError();
|
||||||
|
} else {
|
||||||
if (check2004ValidFormat(location, regex.CMIString250)) {
|
if (check2004ValidFormat(location, regex.CMIString250)) {
|
||||||
this.#location = location;
|
this.#location = location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for #timestamp
|
* Getter for #timestamp
|
||||||
@@ -1268,10 +1279,14 @@ export class CMICommentsFromLearnerObject extends BaseCMI {
|
|||||||
* @param {string} timestamp
|
* @param {string} timestamp
|
||||||
*/
|
*/
|
||||||
set timestamp(timestamp) {
|
set timestamp(timestamp) {
|
||||||
|
if (this.initialized && this.#readOnlyAfterInit) {
|
||||||
|
throwReadOnlyError();
|
||||||
|
} else {
|
||||||
if (check2004ValidFormat(timestamp, regex.CMITime)) {
|
if (check2004ValidFormat(timestamp, regex.CMITime)) {
|
||||||
this.#timestamp = timestamp;
|
this.#timestamp = timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toJSON for cmi.comments_from_learner.n object
|
* toJSON for cmi.comments_from_learner.n object
|
||||||
@@ -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
|
* Class representing SCORM 2004's cmi.interactions.n.objectives.n object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export class ValidationError extends Error {
|
|||||||
|
|
||||||
#errorCode;
|
#errorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for #errorCode
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
get errorCode() {
|
||||||
|
return this.#errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trying to override the default Error message
|
* Trying to override the default Error message
|
||||||
* @return {string}
|
* @return {string}
|
||||||
|
|||||||
249
test/AICC.spec.js
Normal file
249
test/AICC.spec.js
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
import {expect} from 'chai';
|
||||||
|
import {describe, it} from 'mocha';
|
||||||
|
import * as h from './api_helpers';
|
||||||
|
import {scorm12_error_codes} from '../src/constants/error_codes';
|
||||||
|
import AICC from '../src/AICC';
|
||||||
|
|
||||||
|
const api = () => {
|
||||||
|
const API = new AICC();
|
||||||
|
API.apiLogLevel = 1;
|
||||||
|
return API;
|
||||||
|
};
|
||||||
|
const apiInitialized = () => {
|
||||||
|
const API = api();
|
||||||
|
API.lmsInitialize();
|
||||||
|
return API;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('AICC API Tests', () => {
|
||||||
|
describe('setCMIValue()', () => {
|
||||||
|
describe('Invalid Sets - Should Always Fail', () => {
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi._version',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi._children',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.core._children',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.core.score._children',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives._children',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives._count',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions._children',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions._count',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.objectives._count',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.correct_responses._count',
|
||||||
|
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Invalid Sets - Should Fail After Initialization', () => {
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.launch_data',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.student_id',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.student_name',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.credit',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.entry',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.total_time',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.lesson_mode',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.student_data.mastery_score',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.student_data.max_time_allowed',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.student_data.time_limit_action',
|
||||||
|
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('LMSGetValue()', () => {
|
||||||
|
describe('Invalid Properties - Should Always Fail', () => {
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.close',
|
||||||
|
expectedError: scorm12_error_codes.GENERAL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.exit',
|
||||||
|
expectedError: scorm12_error_codes.GENERAL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.entry',
|
||||||
|
expectedError: scorm12_error_codes.GENERAL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Write-Only Properties - Should Always Fail', () => {
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.exit',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.session_time',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.id',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: 'AAA',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.time',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: '12:59:59',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.type',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: 'true-false',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.weighting',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: '0',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.student_response',
|
||||||
|
initializeFirst: true,
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.result',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: 'correct',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.latency',
|
||||||
|
initializeFirst: true,
|
||||||
|
initializationValue: '01:59:59.99',
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.correct_responses.0.pattern',
|
||||||
|
initializeFirst: true,
|
||||||
|
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('LMSSetValue()', () => {
|
||||||
|
describe('Uninitialized - Should Fail', () => {
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives.0.id',
|
||||||
|
expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.id',
|
||||||
|
expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Initialized - Should Succeed', () => {
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.objectives.0.id',
|
||||||
|
valueToTest: 'AAA',
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.id',
|
||||||
|
valueToTest: 'AAA',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
290
test/Scorm2004API.spec.js
Normal file
290
test/Scorm2004API.spec.js
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
import {expect} from 'chai';
|
||||||
|
import {describe, it} from 'mocha';
|
||||||
|
import * as h from './api_helpers';
|
||||||
|
import {scorm2004_error_codes} from '../src/constants/error_codes';
|
||||||
|
import Scorm2004API from '../src/Scorm2004API';
|
||||||
|
import {scorm2004_values} from '../src/constants/field_values';
|
||||||
|
|
||||||
|
const api = () => {
|
||||||
|
const API = new Scorm2004API();
|
||||||
|
API.apiLogLevel = 1;
|
||||||
|
return API;
|
||||||
|
};
|
||||||
|
const apiInitialized = () => {
|
||||||
|
const API = api(true);
|
||||||
|
API.lmsInitialize();
|
||||||
|
return API;
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('SCORM 2004 API Tests', () => {
|
||||||
|
describe('setCMIValue()', () => {
|
||||||
|
describe('Invalid Sets - Should Always Fail', () => {
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi._version',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_learner._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_learner._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_lms._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_lms._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.objectives._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.correct_responses._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.learner_preference._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives._count',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives.0.score._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.score._children',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Invalid Sets - Should Fail After Initialization', () => {
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.completion_threshold',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.credit',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.entry',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.launch_data',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.learner_id',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.learner_name',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.max_time_allowed',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.mode',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.scaled_passing_score',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.time_limit_action',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.total_time',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.comment',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.location',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkSetCMIValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.timestamp',
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetValue()', () => {
|
||||||
|
describe('Invalid Properties - Should Always Fail', () => {
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.close',
|
||||||
|
expectedError: scorm2004_error_codes.UNDEFINED_DATA_MODEL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.exit',
|
||||||
|
expectedError: scorm2004_error_codes.UNDEFINED_DATA_MODEL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.core.entry',
|
||||||
|
expectedError: scorm2004_error_codes.UNDEFINED_DATA_MODEL,
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Write-Only Properties - Should Always Fail', () => {
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.exit',
|
||||||
|
expectedError: scorm2004_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSGetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.session_time',
|
||||||
|
expectedError: scorm2004_error_codes.WRITE_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SetValue()', () => {
|
||||||
|
describe('Uninitialized - Should Fail', () => {
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.objectives.0.id',
|
||||||
|
expectedError: scorm2004_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.interactions.0.id',
|
||||||
|
expectedError: scorm2004_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_learner.0.comment',
|
||||||
|
expectedError: scorm2004_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: api(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.comment',
|
||||||
|
expectedError: scorm2004_error_codes.STORE_BEFORE_INIT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Initialized - Should Succeed', () => {
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.objectives.0.id',
|
||||||
|
valueToTest: 'AAA',
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.interactions.0.id',
|
||||||
|
valueToTest: 'AAA',
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_learner.0.comment',
|
||||||
|
valueToTest: 'comment',
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_learner.0.location',
|
||||||
|
valueToTest: 'location',
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_learner.0.timestamp',
|
||||||
|
valueToTest: scorm2004_values.validTimestamps[0],
|
||||||
|
errorThrown: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Initialized - Should Fail', () => {
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.comment',
|
||||||
|
valueToTest: 'comment',
|
||||||
|
errorThrown: false,
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.location',
|
||||||
|
valueToTest: 'location',
|
||||||
|
errorThrown: false,
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
h.checkLMSSetValue({
|
||||||
|
api: apiInitialized(),
|
||||||
|
fieldName: 'cmi.comments_from_lms.0.timestamp',
|
||||||
|
valueToTest: scorm2004_values.validTimestamps[0],
|
||||||
|
errorThrown: false,
|
||||||
|
expectedError: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -12,13 +12,23 @@ export const checkLMSSetValue = (
|
|||||||
describe(`Field: ${fieldName}`, () => {
|
describe(`Field: ${fieldName}`, () => {
|
||||||
const status = expectedError > 0 ? 'fail to' : 'successfully';
|
const status = expectedError > 0 ? 'fail to' : 'successfully';
|
||||||
it(`Should ${status} set value for ${fieldName}`, () => {
|
it(`Should ${status} set value for ${fieldName}`, () => {
|
||||||
|
if (expectedError > 0) {
|
||||||
if (errorThrown) {
|
if (errorThrown) {
|
||||||
expect(() => api.setValue(fieldName, valueToTest)).
|
expect(() => api.lmsSetValue(fieldName, valueToTest)).
|
||||||
to.throw(String(expectedError));
|
to.throw(String(expectedError));
|
||||||
} else {
|
} else {
|
||||||
api.setValue(fieldName, valueToTest);
|
api.lmsSetValue(fieldName, valueToTest);
|
||||||
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
|
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (errorThrown) {
|
||||||
|
expect(() => api.lmsSetValue(fieldName, valueToTest)).
|
||||||
|
to.not.throw();
|
||||||
|
} else {
|
||||||
|
api.lmsSetValue(fieldName, valueToTest);
|
||||||
|
expect(String(api.lmsGetLastError())).to.equal(String(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -76,7 +86,12 @@ export const checkSetCMIValue = (
|
|||||||
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
|
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (errorThrown) {
|
||||||
expect(() => api.setCMIValue(fieldName, valueToTest)).to.not.throw();
|
expect(() => api.setCMIValue(fieldName, valueToTest)).to.not.throw();
|
||||||
|
} else {
|
||||||
|
api.setCMIValue(fieldName, valueToTest);
|
||||||
|
expect(String(api.lmsGetLastError())).to.equal(String(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {scorm2004_constants} from '../../src/constants/api_constants';
|
|||||||
import {
|
import {
|
||||||
ADL,
|
ADL,
|
||||||
CMI,
|
CMI,
|
||||||
CMICommentsFromLearnerObject,
|
CMICommentsObject,
|
||||||
CMICommentsFromLMSObject, CMIInteractionsCorrectResponsesObject,
|
CMICommentsFromLMSObject, CMIInteractionsCorrectResponsesObject,
|
||||||
CMIInteractionsObject,
|
CMIInteractionsObject,
|
||||||
CMIInteractionsObjectivesObject,
|
CMIInteractionsObjectivesObject,
|
||||||
@@ -219,7 +219,7 @@ describe('SCORM 2004 CMI Tests', () => {
|
|||||||
cmi: cmi(),
|
cmi: cmi(),
|
||||||
fieldName: 'cmi.score._children',
|
fieldName: 'cmi.score._children',
|
||||||
expectedValue: scorm2004_constants.score_children,
|
expectedValue: scorm2004_constants.score_children,
|
||||||
expectedError: invalid_set,
|
expectedError: read_only,
|
||||||
});
|
});
|
||||||
h.checkValidValues({
|
h.checkValidValues({
|
||||||
cmi: cmi(),
|
cmi: cmi(),
|
||||||
@@ -535,7 +535,7 @@ describe('SCORM 2004 CMI Tests', () => {
|
|||||||
cmi: cmi(),
|
cmi: cmi(),
|
||||||
fieldName: 'cmi.score._children',
|
fieldName: 'cmi.score._children',
|
||||||
expectedValue: scorm2004_constants.score_children,
|
expectedValue: scorm2004_constants.score_children,
|
||||||
expectedError: invalid_set,
|
expectedError: read_only,
|
||||||
});
|
});
|
||||||
h.checkValidValues({
|
h.checkValidValues({
|
||||||
cmi: cmi(),
|
cmi: cmi(),
|
||||||
@@ -639,9 +639,9 @@ describe('SCORM 2004 CMI Tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('CMICommentsFromLearnerObject Tests', () => {
|
describe('CMICommentsObject Tests', () => {
|
||||||
const comments = () => {
|
const comments = () => {
|
||||||
return new CMICommentsFromLearnerObject();
|
return new CMICommentsObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -683,10 +683,10 @@ describe('SCORM 2004 CMI Tests', () => {
|
|||||||
|
|
||||||
describe('CMICommentsFromLMSObject Tests', () => {
|
describe('CMICommentsFromLMSObject Tests', () => {
|
||||||
const comments = () => {
|
const comments = () => {
|
||||||
return new CMICommentsFromLMSObject();
|
return new CMICommentsObject(true);
|
||||||
};
|
};
|
||||||
const commentsInitialized = () => {
|
const commentsInitialized = () => {
|
||||||
const cmi = new CMICommentsFromLMSObject();
|
const cmi = new CMICommentsObject(true);
|
||||||
cmi.initialize();
|
cmi.initialize();
|
||||||
return cmi;
|
return cmi;
|
||||||
};
|
};
|
||||||
@@ -915,7 +915,7 @@ describe('SCORM 2004 CMI Tests', () => {
|
|||||||
cmi: objective(),
|
cmi: objective(),
|
||||||
fieldName: 'cmi.score._children',
|
fieldName: 'cmi.score._children',
|
||||||
expectedValue: scorm2004_constants.score_children,
|
expectedValue: scorm2004_constants.score_children,
|
||||||
expectedError: invalid_set,
|
expectedError: read_only,
|
||||||
});
|
});
|
||||||
h.checkValidValues({
|
h.checkValidValues({
|
||||||
cmi: objective(),
|
cmi: objective(),
|
||||||
|
|||||||
Reference in New Issue
Block a user