More CMI tests

This commit is contained in:
Jonathan Putney
2019-11-12 21:41:39 -05:00
parent b427943036
commit d2cc923f94
6 changed files with 793 additions and 68 deletions

View File

@@ -1,8 +1,18 @@
import {describe} from 'mocha';
import {describe, it} from 'mocha';
import {aicc_constants} from '../../src/constants/api_constants';
import {scorm12_error_codes} from '../../src/constants/error_codes';
import {CMI} from '../../src/cmi/aicc_cmi';
import {
CMI,
CMIEvaluationCommentsObject,
CMITriesObject, NAV,
} from '../../src/cmi/aicc_cmi';
import * as h from '../helpers';
import {
CMIInteractionsCorrectResponsesObject,
CMIInteractionsObject,
CMIObjectivesObject,
} from '../../src/cmi/scorm12_cmi';
import {expect} from 'chai';
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
const type_mismatch = scorm12_error_codes.TYPE_MISMATCH;
@@ -707,6 +717,229 @@ describe('AICC CMI Tests', () => {
fieldName: 'cmi.interactions._count', expectedValue: 0,
expectedError: invalid_set,
});
it('should export JSON', () => {
const cmiObj = cmi();
cmiObj.objectives.childArray.push(new CMIObjectivesObject());
cmiObj.interactions.childArray.push(new CMIInteractionsObject());
cmiObj.evaluation.comments.childArray.push(
new CMIEvaluationCommentsObject());
cmiObj.student_data.tries.childArray.push(new CMITriesObject());
expect(
JSON.stringify(cmiObj),
).
to.
equal(
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"","entry":"","total_time":"","lesson_mode":"normal","exit":"","session_time":"00:00:00","score":{"raw":"","min":"","max":"100"}},"objectives":{"0":{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}},"student_data":{"mastery_score":"","max_time_allowed":"","time_limit_action":"","tries":{"0":{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}}},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}},"evaluation":{"comments":{"0":{"content":"","location":"","time":""}}}}');
});
});
describe('CMITriesObject Tests', () => {
const triesObject = () => {
return new CMITriesObject();
};
const triesInitialized = () => {
const cmi = new CMITriesObject();
cmi.initialize();
return cmi;
};
/**
* cmi.interactions.n.objectives.n object
*/
h.checkRead({
cmi: triesObject(),
fieldName: 'cmi.status',
});
h.checkRead({
cmi: triesInitialized(),
fieldName: 'cmi.status',
});
h.checkValidValues({
cmi: triesObject(),
fieldName: 'cmi.status',
validValues: [
'passed',
'completed',
'failed',
'incomplete',
'browsed',
'not attempted',
],
invalidValues: [
'P',
'f',
'complete',
'started',
'in progress',
],
});
h.checkReadAndWrite({
cmi: triesObject(),
fieldName: 'cmi.time',
expectedError: write_only,
valueToTest: '23:59:59',
});
h.checkValidValues({
cmi: triesObject(),
fieldName: 'cmi.time',
validValues: [
'15:00:30',
'00:50:30',
'23:00:30',
],
invalidValues: [
'-00:00:30',
'0:50:30',
'23:00:30.',
],
});
/**
* cmi.student_data.tries.n.score Properties
*/
h.checkInvalidSet({
cmi: triesObject(),
fieldName: 'cmi.score._children',
expectedValue: aicc_constants.score_children,
expectedError: invalid_set,
});
h.checkValidValues({
cmi: triesObject(),
fieldName: 'cmi.score.raw',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
h.checkValidValues({
cmi: triesObject(),
fieldName: 'cmi.score.min',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
h.checkValidValues({
cmi: triesObject(),
fieldName: 'cmi.score.max',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
it('should export JSON', () => {
const cmi = triesObject();
expect(
JSON.stringify(cmi),
).
to.
equal(
'{"status":"","time":"","score":{"raw":"","min":"","max":"100"}}');
});
});
describe('CMIEvaluationCommentsObject Tests', () => {
const evaluationComment = () => {
return new CMIEvaluationCommentsObject();
};
/**
* cmi.evaluation.comments.n object
*/
h.checkFieldConstraintSize({
cmi: evaluationComment(),
fieldName: 'cmi.content',
expectedError: type_mismatch,
limit: 255,
});
h.checkFieldConstraintSize({
cmi: evaluationComment(),
fieldName: 'cmi.location',
expectedError: type_mismatch,
limit: 255,
});
h.checkReadAndWrite({
cmi: evaluationComment(),
fieldName: 'cmi.time',
expectedError: write_only,
valueToTest: '23:59:59',
});
h.checkValidValues({
cmi: evaluationComment(),
fieldName: 'cmi.time',
validValues: [
'15:00:30',
'00:50:30',
'23:00:30',
],
invalidValues: [
'-00:00:30',
'0:50:30',
'23:00:30.',
],
});
it('should export JSON', () => {
const cmi = evaluationComment();
expect(
JSON.stringify(cmi),
).to.equal('{"content":"","location":"","time":""}');
});
});
describe('NAV Tests', () => {
const nav = () => {
return new NAV();
};
/**
* cmi.interactions.n.correct_responses.n object
*/
h.checkValidValues({
cmi: nav(),
fieldName: 'cmi.event',
validValues: [
'previous',
'continue',
],
invalidValues: [
'P',
'f',
'complete',
'started',
'in progress',
],
});
it('should export JSON', () => {
const cmi = nav();
expect(
JSON.stringify(cmi),
).to.equal('{"event":""}');
});
});
});
});

View File

@@ -1,7 +1,14 @@
import {describe, beforeEach, afterEach} from 'mocha';
import {expect} from 'chai';
import {describe, it} from 'mocha';
import {scorm12_constants} from '../../src/constants/api_constants';
import {scorm12_error_codes} from '../../src/constants/error_codes';
import {CMI} from '../../src/cmi/scorm12_cmi';
import {
CMI,
CMIInteractionsCorrectResponsesObject,
CMIInteractionsObject,
CMIInteractionsObjectivesObject,
CMIObjectivesObject,
} from '../../src/cmi/scorm12_cmi';
import * as h from '../helpers';
const invalid_set = scorm12_error_codes.INVALID_SET_VALUE;
@@ -164,6 +171,10 @@ describe('SCORM 1.2 CMI Tests', () => {
expectedValue: scorm12_constants.score_children,
expectedError: invalid_set,
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.core.score.raw',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.core.score.raw',
@@ -179,6 +190,10 @@ describe('SCORM 1.2 CMI Tests', () => {
'101',
],
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.core.score.min',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.core.score.min',
@@ -194,6 +209,11 @@ describe('SCORM 1.2 CMI Tests', () => {
'101',
],
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.core.score.max',
expectedValue: '100',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.core.score.max',
@@ -257,6 +277,10 @@ describe('SCORM 1.2 CMI Tests', () => {
expectedValue: scorm12_constants.student_preference_children,
expectedError: invalid_set,
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.student_preference.audio',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.student_preference.audio',
@@ -269,13 +293,6 @@ describe('SCORM 1.2 CMI Tests', () => {
invalidValues: [
'invalid',
'a100',
],
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.student_preference.audio',
validValues: [],
invalidValues: [
'101',
'5000000',
'-500',
@@ -287,6 +304,10 @@ describe('SCORM 1.2 CMI Tests', () => {
limit: 255,
expectedError: type_mismatch,
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.student_preference.speed',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.student_preference.speed',
@@ -299,19 +320,16 @@ describe('SCORM 1.2 CMI Tests', () => {
invalidValues: [
'invalid',
'a100',
],
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.student_preference.speed',
validValues: [],
invalidValues: [
'101',
'-101',
'5000000',
'-500',
],
});
h.checkRead({
cmi: cmi(),
fieldName: 'cmi.student_preference.text',
});
h.checkValidValues({
cmi: cmi(),
fieldName: 'cmi.student_preference.text',
@@ -702,6 +720,332 @@ describe('SCORM 1.2 CMI Tests', () => {
expectedValue: 0,
expectedError: invalid_set,
});
it('should export JSON', () => {
const cmiObj = cmi();
cmiObj.objectives.childArray.push(new CMIObjectivesObject());
cmiObj.interactions.childArray.push(new CMIInteractionsObject());
expect(
JSON.stringify(cmiObj),
).to.equal('{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"","entry":"","total_time":"","lesson_mode":"normal","exit":"","session_time":"00:00:00","score":{"raw":"","min":"","max":"100"}},"objectives":{"0":{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}},"student_data":{"mastery_score":"","max_time_allowed":"","time_limit_action":""},"student_preference":{"audio":"","language":"","speed":"","text":""},"interactions":{"0":{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{},"correct_responses":{}}}}');
});
});
describe('CMIInteractionsObject Tests', () => {
const interaction = () => {
return new CMIInteractionsObject();
};
const interactionInitialized = () => {
const cmi = new CMIInteractionsObject();
cmi.initialize();
return cmi;
};
/**
* cmi.interactions.n object
*/
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.id',
expectedError: write_only,
});
h.checkWriteOnly({
cmi: interactionInitialized(),
fieldName: 'cmi.id',
expectedError: write_only,
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.time',
expectedError: write_only,
valueToTest: '23:59:59',
});
h.checkValidValues({
cmi: interaction(),
fieldName: 'cmi.time',
validValues: [
'15:00:30',
'00:50:30',
'23:00:30',
],
invalidValues: [
'-00:00:30',
'0:50:30',
'23:00:30.',
],
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.type',
expectedError: write_only,
valueToTest: 'true-false',
});
h.checkValidValues({
cmi: interaction(),
fieldName: 'cmi.type',
validValues: [
'true-false',
'choice',
'fill-in',
'matching',
'performance',
'sequencing',
'likert',
'numeric',
],
invalidValues: [
'correct',
'wrong',
'logout',
],
});
h.checkReadOnly({
cmi: interaction(),
fieldName: 'cmi.objectives._count',
expectedValue: 0,
expectedError: invalid_set,
});
h.checkReadOnly({
cmi: interaction(),
fieldName: 'cmi.correct_responses._count',
expectedValue: 0,
expectedError: invalid_set,
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.weighting',
expectedError: write_only,
valueToTest: '0',
});
h.checkValidValues({
cmi: interaction(),
fieldName: 'cmi.weighting',
validValues: [
'-100',
'-1',
'1',
'100',
],
invalidValues: [
'-101',
'101',
'invalid',
],
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.student_response',
expectedError: write_only,
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.result',
expectedError: write_only,
valueToTest: 'correct',
});
h.checkValidValues({
cmi: interaction(),
fieldName: 'cmi.result',
validValues: [
'correct',
'wrong',
'unanticipated',
'neutral',
'1',
'999',
'999.99999',
],
invalidValues: [
'-1',
'10000',
'invalid',
],
});
h.checkWriteOnly({
cmi: interaction(),
fieldName: 'cmi.latency',
valueToTest: '00:00:00',
expectedError: write_only,
});
h.checkValidValues({
cmi: interaction(),
fieldName: 'cmi.latency',
validValues: [
'10:06:57',
'00:00:01.56',
'23:59:59',
'47:59:59',
],
invalidValues: [
'06:5:13',
'23:59:59.123',
'P1DT23H59M59S',
],
});
it('should export JSON', () => {
const cmi = interaction();
cmi.objectives.childArray.push(new CMIInteractionsObjectivesObject());
cmi.correct_responses.childArray.push(new CMIInteractionsCorrectResponsesObject());
expect(
JSON.stringify(cmi),
).to.equal('{"id":"","time":"","type":"","weighting":"","student_response":"","result":"","latency":"","objectives":{"0":{"id":""}},"correct_responses":{"0":{"pattern":""}}}');
});
});
describe('CMIInteractionsObjectivesObject Tests', () => {
const interactionObjective = () => {
return new CMIInteractionsObjectivesObject();
};
/**
* cmi.interactions.n.objectives.n object
*/
h.checkReadAndWrite({
cmi: interactionObjective(),
fieldName: 'cmi.id',
});
it('should export JSON', () => {
const cmi = interactionObjective();
expect(
JSON.stringify(cmi),
).to.equal('{"id":""}');
});
});
describe('CMIInteractionsCorrectResponsesObject Tests', () => {
const correctResponse = () => {
return new CMIInteractionsCorrectResponsesObject();
};
/**
* cmi.interactions.n.correct_responses.n object
*/
h.checkWriteOnly({
cmi: correctResponse(),
fieldName: 'cmi.pattern',
expectedError: write_only,
});
it('should export JSON', () => {
const cmi = correctResponse();
expect(
JSON.stringify(cmi),
).to.equal('{"pattern":""}');
});
});
describe('CMIObjectivesObject Tests', () => {
const objective = () => {
return new CMIObjectivesObject();
};
/**
* cmi.objectives.n object
*/
h.checkReadAndWrite({
cmi: objective(),
fieldName: 'cmi.id',
});
h.checkRead({
cmi: objective(),
fieldName: 'cmi.status',
});
h.checkValidValues({
cmi: objective(),
fieldName: 'cmi.status',
validValues: [
'passed',
'completed',
'failed',
'incomplete',
'browsed',
'not attempted',
],
invalidValues: [
'P',
'f',
'complete',
'started',
'in progress',
],
});
/**
* cmi.objectives.n.score Properties
*/
h.checkInvalidSet({
cmi: objective(),
fieldName: 'cmi.score._children',
expectedValue: scorm12_constants.score_children,
expectedError: invalid_set,
});
h.checkRead({
cmi: objective(),
fieldName: 'cmi.score.raw',
});
h.checkValidValues({
cmi: objective(),
fieldName: 'cmi.score.raw',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
h.checkRead({
cmi: objective(),
fieldName: 'cmi.score.min',
});
h.checkValidValues({
cmi: objective(),
fieldName: 'cmi.score.min',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
h.checkRead({
cmi: objective(),
fieldName: 'cmi.score.max',
expectedValue: '100',
});
h.checkValidValues({
cmi: objective(),
fieldName: 'cmi.score.max',
validValues: [
'0',
'25.1',
'50.5',
'75',
'100',
],
invalidValues: [
'-1',
'101',
],
});
it('should export JSON', () => {
const cmi = objective();
expect(
JSON.stringify(cmi),
).to.equal('{"id":"","status":"","score":{"raw":"","min":"","max":"100"}}');
});
});
});
});