Working on the saving of data
This commit is contained in:
@@ -4,13 +4,13 @@ import Scorm12API from '../src/Scorm12API';
|
||||
import * as h from './api_helpers';
|
||||
import {scorm12_error_codes} from '../src/constants/error_codes';
|
||||
|
||||
const api = () => {
|
||||
const API = new Scorm12API();
|
||||
const api = (settings = {}) => {
|
||||
const API = new Scorm12API(settings);
|
||||
API.apiLogLevel = 1;
|
||||
return API;
|
||||
};
|
||||
const apiInitialized = () => {
|
||||
const API = api();
|
||||
const apiInitialized = (settings = {}) => {
|
||||
const API = api(settings);
|
||||
API.lmsInitialize();
|
||||
return API;
|
||||
};
|
||||
@@ -271,4 +271,64 @@ describe('SCORM 1.2 API Tests', () => {
|
||||
firstAPI.cmi.core.student_id,
|
||||
).to.equal('student_2');
|
||||
});
|
||||
|
||||
describe('storeData()', () => {
|
||||
it('should set cmi.core.lesson_status to "completed"', () => {
|
||||
const scorm12API = api();
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('completed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "browsed"', () => {
|
||||
const scorm12API = api();
|
||||
scorm12API.cmi.core.lesson_mode = 'browse';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('browsed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "browsed" - Initial Status',
|
||||
() => {
|
||||
const scorm12API = api();
|
||||
scorm12API.startingData = {'cmi': {'core': {'lesson_status': ''}}};
|
||||
scorm12API.cmi.core.lesson_mode = 'browse';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('browsed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "passed" - mastery_override: true',
|
||||
() => {
|
||||
const scorm12API = api({mastery_override: true});
|
||||
scorm12API.cmi.core.credit = 'credit';
|
||||
scorm12API.cmi.student_data.mastery_score = '60.0';
|
||||
scorm12API.cmi.core.score.raw = '75.0';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('passed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "failed" - mastery_override: true',
|
||||
() => {
|
||||
const scorm12API = api({mastery_override: true});
|
||||
scorm12API.cmi.core.credit = 'credit';
|
||||
scorm12API.cmi.student_data.mastery_score = '60.0';
|
||||
scorm12API.cmi.core.score.raw = '55.0';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('failed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "passed" - mastery_override: false',
|
||||
() => {
|
||||
const scorm12API = api({mastery_override: false});
|
||||
scorm12API.cmi.core.lesson_status = 'failed'; // module author wanted the user to pass, so we don't override
|
||||
scorm12API.cmi.core.credit = 'credit';
|
||||
scorm12API.cmi.student_data.mastery_score = '60.0';
|
||||
scorm12API.cmi.core.score.raw = '75.0';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('failed');
|
||||
});
|
||||
it('should set cmi.core.lesson_status to "failed" - mastery_override: false',
|
||||
() => {
|
||||
const scorm12API = api({mastery_override: false});
|
||||
scorm12API.cmi.core.lesson_status = 'passed'; // module author wanted the user to pass, so we don't override
|
||||
scorm12API.cmi.core.credit = 'credit';
|
||||
scorm12API.cmi.student_data.mastery_score = '60.0';
|
||||
scorm12API.cmi.core.score.raw = '55.0';
|
||||
scorm12API.storeData(true);
|
||||
expect(scorm12API.cmi.core.lesson_status).to.equal('passed');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,6 +91,7 @@ describe('AICC CMI Tests', () => {
|
||||
h.checkRead({
|
||||
cmi: cmi(),
|
||||
fieldName: 'cmi.core.lesson_status',
|
||||
expectedValue: 'not attempted',
|
||||
});
|
||||
h.checkValidValues({
|
||||
cmi: cmi(),
|
||||
@@ -334,6 +335,7 @@ describe('AICC CMI Tests', () => {
|
||||
h.checkRead({
|
||||
cmi: cmi(),
|
||||
fieldName: 'cmi.core.lesson_status',
|
||||
expectedValue: 'not attempted',
|
||||
});
|
||||
h.checkValidValues({
|
||||
cmi: cmi(),
|
||||
@@ -517,7 +519,7 @@ describe('AICC CMI Tests', () => {
|
||||
).
|
||||
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":""}}}}');
|
||||
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","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":""}}}}');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ describe('SCORM 1.2 CMI Tests', () => {
|
||||
h.checkRead({
|
||||
cmi: cmi(),
|
||||
fieldName: 'cmi.core.lesson_status',
|
||||
expectedValue: 'not attempted',
|
||||
});
|
||||
h.checkValidValues({
|
||||
cmi: cmi(),
|
||||
@@ -415,6 +416,7 @@ describe('SCORM 1.2 CMI Tests', () => {
|
||||
h.checkRead({
|
||||
cmi: cmiInitialized(),
|
||||
fieldName: 'cmi.core.lesson_status',
|
||||
expectedValue: 'not attempted',
|
||||
});
|
||||
h.checkValidValues({
|
||||
cmi: cmiInitialized(),
|
||||
@@ -590,7 +592,7 @@ describe('SCORM 1.2 CMI Tests', () => {
|
||||
).
|
||||
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":{}}}}');
|
||||
'{"suspend_data":"","launch_data":"","comments":"","comments_from_lms":"","core":{"student_id":"","student_name":"","lesson_location":"","credit":"","lesson_status":"not attempted","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":{}}}}');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -274,4 +274,60 @@ describe('Utility Tests', () => {
|
||||
).to.equal('01:05:30.5');
|
||||
});
|
||||
});
|
||||
|
||||
describe('flatten()', () => {
|
||||
it('Should return flattened object', () => {
|
||||
expect(
|
||||
Utilities.flatten({
|
||||
'cmi': {
|
||||
'core': {
|
||||
'learner_id': 'jputney',
|
||||
'learner_name': 'Jonathan',
|
||||
},
|
||||
'objectives': {
|
||||
'0': {
|
||||
'id': 'AAA',
|
||||
},
|
||||
'1': {
|
||||
'id': 'BBB',
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).to.eql({
|
||||
'cmi.core.learner_id': 'jputney',
|
||||
'cmi.core.learner_name': 'Jonathan',
|
||||
'cmi.objectives.0.id': 'AAA',
|
||||
'cmi.objectives.1.id': 'BBB',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unflatten()', () => {
|
||||
it('Should return flattened object', () => {
|
||||
expect(
|
||||
Utilities.unflatten({
|
||||
'cmi.core.learner_id': 'jputney',
|
||||
'cmi.core.learner_name': 'Jonathan',
|
||||
'cmi.objectives.0.id': 'AAA',
|
||||
'cmi.objectives.1.id': 'BBB',
|
||||
}),
|
||||
).to.eql({
|
||||
'cmi': {
|
||||
'core': {
|
||||
'learner_id': 'jputney',
|
||||
'learner_name': 'Jonathan',
|
||||
},
|
||||
'objectives': {
|
||||
'0': {
|
||||
'id': 'AAA',
|
||||
},
|
||||
'1': {
|
||||
'id': 'BBB',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user