Handling non-string values being passed to SetValue/LMSSetValue

This commit is contained in:
Jonathan Putney
2019-12-30 11:33:08 -05:00
parent 7b780c4c39
commit a1d94eef97
5 changed files with 90 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import {describe, it} from 'mocha';
import Scorm12API from '../src/Scorm12API';
import * as h from './api_helpers';
import {scorm12_error_codes} from '../src/constants/error_codes';
import {scorm12_values} from '../src/constants/field_values';
const api = (settings = {}) => {
const API = new Scorm12API(settings);
@@ -16,6 +17,27 @@ const apiInitialized = (settings = {}) => {
};
describe('SCORM 1.2 API Tests', () => {
describe('LMSSetValue()', () => {
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.core.score.raw',
validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange,
});
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.core.score.min',
validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange,
});
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.core.score.max',
validValues: scorm12_values.validScoreRange,
invalidValues: scorm12_values.invalidScoreRange,
});
});
describe('setCMIValue()', () => {
describe('Invalid Sets - Should Always Fail', () => {
h.checkSetCMIValue({
@@ -280,7 +302,7 @@ describe('SCORM 1.2 API Tests', () => {
scorm12API.cmi.core.session_time = '23:59:59';
const cmiExport = scorm12API.renderCommitCMI(true);
expect(
cmiExport.cmi.core.total_time
cmiExport.cmi.core.total_time,
).to.equal('36:34:55');
});
});

View File

@@ -3,7 +3,7 @@ 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';
import {scorm12_values, scorm2004_values} from '../src/constants/field_values';
const api = () => {
const API = new Scorm2004API();
@@ -17,6 +17,33 @@ const apiInitialized = () => {
};
describe('SCORM 2004 API Tests', () => {
describe('SetValue()', () => {
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.score.scaled',
validValues: scorm2004_values.validScaledRange,
invalidValues: scorm2004_values.invalidScaledRange,
});
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.score.raw',
validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange,
});
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.score.min',
validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange,
});
h.checkValidValues({
api: apiInitialized(),
fieldName: 'cmi.score.max',
validValues: scorm2004_values.validScoreRange,
invalidValues: scorm2004_values.invalidScoreRange,
});
});
describe('setCMIValue()', () => {
describe('Invalid Sets - Should Always Fail', () => {
h.checkSetCMIValue({

View File

@@ -1,6 +1,36 @@
import {describe, it} from 'mocha';
import {expect} from 'chai';
export const checkValidValues = (
{
api,
fieldName,
validValues,
invalidValues,
}) => {
describe(`Field: ${fieldName}`, () => {
for (const idx in validValues) {
if ({}.hasOwnProperty.call(validValues, idx)) {
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`,
() => {
expect(api.lmsSetValue(fieldName, validValues[idx])).
to.equal('true');
});
}
}
for (const idx in invalidValues) {
if ({}.hasOwnProperty.call(invalidValues, idx)) {
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`,
() => {
expect(api.lmsSetValue(fieldName, invalidValues[idx])).
to.equal('false');
});
}
}
});
};
export const checkLMSSetValue = (
{
api,