Adding more API tests

This commit is contained in:
Jonathan Putney
2019-11-14 14:50:49 -05:00
parent 360d30bdf0
commit ce503a25cb
11 changed files with 630 additions and 121 deletions

249
test/AICC.spec.js Normal file
View 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
View 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,
});
});
});
});

View File

@@ -12,12 +12,22 @@ export const checkLMSSetValue = (
describe(`Field: ${fieldName}`, () => {
const status = expectedError > 0 ? 'fail to' : 'successfully';
it(`Should ${status} set value for ${fieldName}`, () => {
if (errorThrown) {
expect(() => api.setValue(fieldName, valueToTest)).
to.throw(String(expectedError));
if (expectedError > 0) {
if (errorThrown) {
expect(() => api.lmsSetValue(fieldName, valueToTest)).
to.throw(String(expectedError));
} else {
api.lmsSetValue(fieldName, valueToTest);
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
}
} else {
api.setValue(fieldName, valueToTest);
expect(String(api.lmsGetLastError())).to.equal(String(expectedError));
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));
}
} else {
expect(() => api.setCMIValue(fieldName, valueToTest)).to.not.throw();
if (errorThrown) {
expect(() => api.setCMIValue(fieldName, valueToTest)).to.not.throw();
} else {
api.setCMIValue(fieldName, valueToTest);
expect(String(api.lmsGetLastError())).to.equal(String(0));
}
}
});
});

View File

@@ -4,7 +4,7 @@ import {scorm2004_constants} from '../../src/constants/api_constants';
import {
ADL,
CMI,
CMICommentsFromLearnerObject,
CMICommentsObject,
CMICommentsFromLMSObject, CMIInteractionsCorrectResponsesObject,
CMIInteractionsObject,
CMIInteractionsObjectivesObject,
@@ -219,7 +219,7 @@ describe('SCORM 2004 CMI Tests', () => {
cmi: cmi(),
fieldName: 'cmi.score._children',
expectedValue: scorm2004_constants.score_children,
expectedError: invalid_set,
expectedError: read_only,
});
h.checkValidValues({
cmi: cmi(),
@@ -535,7 +535,7 @@ describe('SCORM 2004 CMI Tests', () => {
cmi: cmi(),
fieldName: 'cmi.score._children',
expectedValue: scorm2004_constants.score_children,
expectedError: invalid_set,
expectedError: read_only,
});
h.checkValidValues({
cmi: cmi(),
@@ -639,9 +639,9 @@ describe('SCORM 2004 CMI Tests', () => {
});
});
describe('CMICommentsFromLearnerObject Tests', () => {
describe('CMICommentsObject Tests', () => {
const comments = () => {
return new CMICommentsFromLearnerObject();
return new CMICommentsObject();
};
/**
@@ -683,10 +683,10 @@ describe('SCORM 2004 CMI Tests', () => {
describe('CMICommentsFromLMSObject Tests', () => {
const comments = () => {
return new CMICommentsFromLMSObject();
return new CMICommentsObject(true);
};
const commentsInitialized = () => {
const cmi = new CMICommentsFromLMSObject();
const cmi = new CMICommentsObject(true);
cmi.initialize();
return cmi;
};
@@ -915,7 +915,7 @@ describe('SCORM 2004 CMI Tests', () => {
cmi: objective(),
fieldName: 'cmi.score._children',
expectedValue: scorm2004_constants.score_children,
expectedError: invalid_set,
expectedError: read_only,
});
h.checkValidValues({
cmi: objective(),