scorm-again 1.7.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/Mocha Unit Tests.run.xml +5 -2
- package/CONTRIBUTING.md +1 -1
- package/README.md +14 -1
- package/dist/aicc.js +3661 -7170
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5671 -10695
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +2871 -5433
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +3868 -6797
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +73 -35
- package/results.json +34254 -0
- package/src/{AICC.js → AICC.ts} +27 -21
- package/src/BaseAPI.ts +1449 -0
- package/src/Scorm12API.ts +360 -0
- package/src/{Scorm2004API.js → Scorm2004API.ts} +245 -163
- package/src/cmi/aicc_cmi.ts +1248 -0
- package/src/cmi/common.ts +411 -0
- package/src/cmi/scorm12_cmi.ts +1426 -0
- package/src/cmi/scorm2004_cmi.ts +1874 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +67 -62
- package/src/exceptions.ts +133 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/{utilities.js → utilities.ts} +114 -74
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +70 -72
- package/test/Scorm12API.spec.ts +580 -0
- package/test/Scorm2004API.spec.ts +812 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/{aicc_cmi.spec.js → aicc_cmi.spec.ts} +193 -209
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +251 -269
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { expect } from "expect";
|
|
2
|
+
import { after, before, describe, it } from "mocha";
|
|
3
|
+
import Scorm12API from "../src/Scorm12API";
|
|
4
|
+
import * as h from "./api_helpers";
|
|
5
|
+
import ErrorCodes from "../src/constants/error_codes";
|
|
6
|
+
import { scorm12Values } from "./field_values";
|
|
7
|
+
import * as sinon from "sinon";
|
|
8
|
+
import Pretender from "fetch-pretender";
|
|
9
|
+
import { RefObject, Settings, DefaultSettings } from "../src/BaseAPI";
|
|
10
|
+
|
|
11
|
+
const scorm12_error_codes = ErrorCodes.scorm12;
|
|
12
|
+
|
|
13
|
+
let clock: sinon.SinonFakeTimers;
|
|
14
|
+
const api = (settings?: Settings) => {
|
|
15
|
+
const API = new Scorm12API(settings);
|
|
16
|
+
API.apiLogLevel = 5;
|
|
17
|
+
return API;
|
|
18
|
+
};
|
|
19
|
+
const apiInitialized = (settings?: Settings) => {
|
|
20
|
+
const API = api(settings);
|
|
21
|
+
API.lmsInitialize();
|
|
22
|
+
return API;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe("SCORM 1.2 API Tests", () => {
|
|
26
|
+
before(() => {
|
|
27
|
+
clock = sinon.useFakeTimers();
|
|
28
|
+
|
|
29
|
+
const server = new Pretender();
|
|
30
|
+
server.post(
|
|
31
|
+
"/scorm12",
|
|
32
|
+
() => {
|
|
33
|
+
return [200, { "Content-Type": "application/json" }, "{}"];
|
|
34
|
+
},
|
|
35
|
+
false,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
server.post(
|
|
39
|
+
"/scorm12/error",
|
|
40
|
+
() => {
|
|
41
|
+
return [500, { "Content-Type": "application/json" }, "{}"];
|
|
42
|
+
},
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
after(() => {
|
|
48
|
+
clock.restore();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("LMSSetValue()", () => {
|
|
52
|
+
h.checkValidValues({
|
|
53
|
+
api: apiInitialized(),
|
|
54
|
+
fieldName: "cmi.core.score.raw",
|
|
55
|
+
validValues: scorm12Values.validScoreRange,
|
|
56
|
+
invalidValues: scorm12Values.invalidScoreRange,
|
|
57
|
+
});
|
|
58
|
+
h.checkValidValues({
|
|
59
|
+
api: apiInitialized(),
|
|
60
|
+
fieldName: "cmi.core.score.min",
|
|
61
|
+
validValues: scorm12Values.validScoreRange,
|
|
62
|
+
invalidValues: scorm12Values.invalidScoreRange,
|
|
63
|
+
});
|
|
64
|
+
h.checkValidValues({
|
|
65
|
+
api: apiInitialized(),
|
|
66
|
+
fieldName: "cmi.core.score.max",
|
|
67
|
+
validValues: scorm12Values.validScoreRange,
|
|
68
|
+
invalidValues: scorm12Values.invalidScoreRange,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("setCMIValue()", () => {
|
|
73
|
+
describe("Invalid Sets - Should Always Fail", () => {
|
|
74
|
+
h.checkSetCMIValue({
|
|
75
|
+
api: api(),
|
|
76
|
+
fieldName: "cmi._version",
|
|
77
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
78
|
+
});
|
|
79
|
+
h.checkSetCMIValue({
|
|
80
|
+
api: api(),
|
|
81
|
+
fieldName: "cmi._children",
|
|
82
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
83
|
+
});
|
|
84
|
+
h.checkSetCMIValue({
|
|
85
|
+
api: api(),
|
|
86
|
+
fieldName: "cmi.core._children",
|
|
87
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
88
|
+
});
|
|
89
|
+
h.checkSetCMIValue({
|
|
90
|
+
api: api(),
|
|
91
|
+
fieldName: "cmi.core.score._children",
|
|
92
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
93
|
+
});
|
|
94
|
+
h.checkSetCMIValue({
|
|
95
|
+
api: api(),
|
|
96
|
+
fieldName: "cmi.objectives._children",
|
|
97
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
98
|
+
});
|
|
99
|
+
h.checkSetCMIValue({
|
|
100
|
+
api: api(),
|
|
101
|
+
fieldName: "cmi.objectives._count",
|
|
102
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
103
|
+
});
|
|
104
|
+
h.checkSetCMIValue({
|
|
105
|
+
api: api(),
|
|
106
|
+
fieldName: "cmi.interactions._children",
|
|
107
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
108
|
+
});
|
|
109
|
+
h.checkSetCMIValue({
|
|
110
|
+
api: api(),
|
|
111
|
+
fieldName: "cmi.interactions._count",
|
|
112
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
113
|
+
});
|
|
114
|
+
h.checkSetCMIValue({
|
|
115
|
+
api: api(),
|
|
116
|
+
fieldName: "cmi.interactions.0.objectives._count",
|
|
117
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
118
|
+
});
|
|
119
|
+
h.checkSetCMIValue({
|
|
120
|
+
api: api(),
|
|
121
|
+
fieldName: "cmi.interactions.0.correct_responses._count",
|
|
122
|
+
expectedError: scorm12_error_codes.INVALID_SET_VALUE,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("Invalid Sets - Should Fail After Initialization", () => {
|
|
127
|
+
h.checkSetCMIValue({
|
|
128
|
+
api: apiInitialized(),
|
|
129
|
+
fieldName: "cmi.launch_data",
|
|
130
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
131
|
+
});
|
|
132
|
+
h.checkSetCMIValue({
|
|
133
|
+
api: apiInitialized(),
|
|
134
|
+
fieldName: "cmi.comments_from_lms",
|
|
135
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
136
|
+
});
|
|
137
|
+
h.checkSetCMIValue({
|
|
138
|
+
api: apiInitialized(),
|
|
139
|
+
fieldName: "cmi.core.student_id",
|
|
140
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
141
|
+
});
|
|
142
|
+
h.checkSetCMIValue({
|
|
143
|
+
api: apiInitialized(),
|
|
144
|
+
fieldName: "cmi.core.student_name",
|
|
145
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
146
|
+
});
|
|
147
|
+
h.checkSetCMIValue({
|
|
148
|
+
api: apiInitialized(),
|
|
149
|
+
fieldName: "cmi.core.credit",
|
|
150
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
151
|
+
});
|
|
152
|
+
h.checkSetCMIValue({
|
|
153
|
+
api: apiInitialized(),
|
|
154
|
+
fieldName: "cmi.core.entry",
|
|
155
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
156
|
+
});
|
|
157
|
+
h.checkSetCMIValue({
|
|
158
|
+
api: apiInitialized(),
|
|
159
|
+
fieldName: "cmi.core.total_time",
|
|
160
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
161
|
+
});
|
|
162
|
+
h.checkSetCMIValue({
|
|
163
|
+
api: apiInitialized(),
|
|
164
|
+
fieldName: "cmi.core.lesson_mode",
|
|
165
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
166
|
+
});
|
|
167
|
+
h.checkSetCMIValue({
|
|
168
|
+
api: apiInitialized(),
|
|
169
|
+
fieldName: "cmi.student_data.mastery_score",
|
|
170
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
171
|
+
});
|
|
172
|
+
h.checkSetCMIValue({
|
|
173
|
+
api: apiInitialized(),
|
|
174
|
+
fieldName: "cmi.student_data.max_time_allowed",
|
|
175
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
176
|
+
});
|
|
177
|
+
h.checkSetCMIValue({
|
|
178
|
+
api: apiInitialized(),
|
|
179
|
+
fieldName: "cmi.student_data.time_limit_action",
|
|
180
|
+
expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("LMSGetValue()", () => {
|
|
186
|
+
describe("Invalid Properties - Should Always Fail", () => {
|
|
187
|
+
h.checkLMSGetValue({
|
|
188
|
+
api: apiInitialized(),
|
|
189
|
+
fieldName: "cmi.core.close",
|
|
190
|
+
expectedError: scorm12_error_codes.GENERAL,
|
|
191
|
+
errorThrown: false,
|
|
192
|
+
});
|
|
193
|
+
h.checkLMSGetValue({
|
|
194
|
+
api: apiInitialized(),
|
|
195
|
+
fieldName: "cmi.exit",
|
|
196
|
+
expectedError: scorm12_error_codes.GENERAL,
|
|
197
|
+
errorThrown: false,
|
|
198
|
+
});
|
|
199
|
+
h.checkLMSGetValue({
|
|
200
|
+
api: apiInitialized(),
|
|
201
|
+
fieldName: "cmi.entry",
|
|
202
|
+
expectedError: scorm12_error_codes.GENERAL,
|
|
203
|
+
errorThrown: false,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("Read and Write Properties - Should Success", () => {
|
|
208
|
+
h.checkLMSGetValue({
|
|
209
|
+
api: apiInitialized(),
|
|
210
|
+
fieldName: "cmi.interactions.0.objectives.0.id",
|
|
211
|
+
initializeFirst: true,
|
|
212
|
+
initializationValue: "AAA",
|
|
213
|
+
expectedValue: "AAA",
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe("Write-Only Properties - Should Always Fail", () => {
|
|
218
|
+
h.checkLMSGetValue({
|
|
219
|
+
api: apiInitialized(),
|
|
220
|
+
fieldName: "cmi.core.exit",
|
|
221
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
222
|
+
});
|
|
223
|
+
h.checkLMSGetValue({
|
|
224
|
+
api: apiInitialized(),
|
|
225
|
+
fieldName: "cmi.core.session_time",
|
|
226
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
227
|
+
});
|
|
228
|
+
h.checkLMSGetValue({
|
|
229
|
+
api: apiInitialized(),
|
|
230
|
+
fieldName: "cmi.interactions.0.id",
|
|
231
|
+
initializeFirst: true,
|
|
232
|
+
initializationValue: "AAA",
|
|
233
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
234
|
+
});
|
|
235
|
+
h.checkLMSGetValue({
|
|
236
|
+
api: apiInitialized(),
|
|
237
|
+
fieldName: "cmi.interactions.0.time",
|
|
238
|
+
initializeFirst: true,
|
|
239
|
+
initializationValue: "12:59:59",
|
|
240
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
241
|
+
});
|
|
242
|
+
h.checkLMSGetValue({
|
|
243
|
+
api: apiInitialized(),
|
|
244
|
+
fieldName: "cmi.interactions.0.type",
|
|
245
|
+
initializeFirst: true,
|
|
246
|
+
initializationValue: "true-false",
|
|
247
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
248
|
+
});
|
|
249
|
+
h.checkLMSGetValue({
|
|
250
|
+
api: apiInitialized(),
|
|
251
|
+
fieldName: "cmi.interactions.0.weighting",
|
|
252
|
+
initializeFirst: true,
|
|
253
|
+
initializationValue: "0",
|
|
254
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
255
|
+
});
|
|
256
|
+
h.checkLMSGetValue({
|
|
257
|
+
api: apiInitialized(),
|
|
258
|
+
fieldName: "cmi.interactions.0.student_response",
|
|
259
|
+
initializeFirst: true,
|
|
260
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
261
|
+
});
|
|
262
|
+
h.checkLMSGetValue({
|
|
263
|
+
api: apiInitialized(),
|
|
264
|
+
fieldName: "cmi.interactions.0.result",
|
|
265
|
+
initializeFirst: true,
|
|
266
|
+
initializationValue: "correct",
|
|
267
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
268
|
+
});
|
|
269
|
+
h.checkLMSGetValue({
|
|
270
|
+
api: apiInitialized(),
|
|
271
|
+
fieldName: "cmi.interactions.0.latency",
|
|
272
|
+
initializeFirst: true,
|
|
273
|
+
initializationValue: "01:59:59.99",
|
|
274
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
275
|
+
});
|
|
276
|
+
h.checkLMSGetValue({
|
|
277
|
+
api: apiInitialized(),
|
|
278
|
+
fieldName: "cmi.interactions.0.correct_responses.0.pattern",
|
|
279
|
+
initializeFirst: true,
|
|
280
|
+
initializationValue: "AAA",
|
|
281
|
+
expectedValue: "AAA",
|
|
282
|
+
expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe("LMSSetValue()", () => {
|
|
288
|
+
describe("Uninitialized - Should Fail", () => {
|
|
289
|
+
h.checkLMSSetValue({
|
|
290
|
+
api: api(),
|
|
291
|
+
fieldName: "cmi.objectives.0.id",
|
|
292
|
+
expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
|
|
293
|
+
});
|
|
294
|
+
h.checkLMSSetValue({
|
|
295
|
+
api: api(),
|
|
296
|
+
fieldName: "cmi.interactions.0.id",
|
|
297
|
+
expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
describe("Initialized - Should Succeed", () => {
|
|
302
|
+
h.checkLMSSetValue({
|
|
303
|
+
api: apiInitialized(),
|
|
304
|
+
fieldName: "cmi.objectives.0.id",
|
|
305
|
+
valueToTest: "AAA",
|
|
306
|
+
});
|
|
307
|
+
h.checkLMSSetValue({
|
|
308
|
+
api: apiInitialized(),
|
|
309
|
+
fieldName: "cmi.interactions.0.id",
|
|
310
|
+
valueToTest: "AAA",
|
|
311
|
+
});
|
|
312
|
+
h.checkLMSSetValue({
|
|
313
|
+
api: apiInitialized(),
|
|
314
|
+
fieldName: "cmi.interactions.0.objectives.0.id",
|
|
315
|
+
valueToTest: "AAA",
|
|
316
|
+
});
|
|
317
|
+
h.checkLMSSetValue({
|
|
318
|
+
api: apiInitialized(),
|
|
319
|
+
fieldName: "cmi.interactions.10.correct_responses.0.pattern",
|
|
320
|
+
valueToTest: "t",
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe("replaceWithAnotherScormAPI()", () => {
|
|
326
|
+
const firstAPI = api();
|
|
327
|
+
const secondAPI = api();
|
|
328
|
+
|
|
329
|
+
firstAPI.cmi.core.student_id = "student_1";
|
|
330
|
+
secondAPI.cmi.core.student_id = "student_2";
|
|
331
|
+
|
|
332
|
+
firstAPI.replaceWithAnotherScormAPI(secondAPI);
|
|
333
|
+
expect(firstAPI.cmi.core.student_id).toEqual("student_2");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe("renderCommitCMI()", () => {
|
|
337
|
+
it("should calculate total time when terminateCommit passed", () => {
|
|
338
|
+
const scorm12API = api();
|
|
339
|
+
scorm12API.cmi.core.total_time = "12:34:56";
|
|
340
|
+
scorm12API.cmi.core.session_time = "23:59:59";
|
|
341
|
+
const cmiExport: RefObject = scorm12API.renderCommitCMI(true);
|
|
342
|
+
expect(cmiExport.cmi.core.total_time).toEqual("36:34:55");
|
|
343
|
+
});
|
|
344
|
+
it("if the user passes, should calculate total time when terminateCommit passed", () => {
|
|
345
|
+
const scorm12API = api();
|
|
346
|
+
scorm12API.cmi.core.score.max = "100";
|
|
347
|
+
scorm12API.cmi.core.score.min = "0";
|
|
348
|
+
scorm12API.cmi.core.score.raw = "100";
|
|
349
|
+
scorm12API.cmi.core.exit = "suspend";
|
|
350
|
+
scorm12API.cmi.core.lesson_status = "completed";
|
|
351
|
+
scorm12API.cmi.core.total_time = "0000:00:00";
|
|
352
|
+
scorm12API.cmi.core.session_time = "23:59:59";
|
|
353
|
+
const cmiExport: RefObject = scorm12API.renderCommitCMI(true);
|
|
354
|
+
expect(cmiExport.cmi.core.total_time).toEqual("23:59:59");
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe("storeData()", () => {
|
|
359
|
+
it('should set cmi.core.lesson_status to "completed"', () => {
|
|
360
|
+
const scorm12API = api();
|
|
361
|
+
scorm12API.storeData(true);
|
|
362
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("completed");
|
|
363
|
+
});
|
|
364
|
+
it('should set cmi.core.lesson_status to "browsed"', () => {
|
|
365
|
+
const scorm12API = api();
|
|
366
|
+
scorm12API.cmi.core.lesson_mode = "browse";
|
|
367
|
+
scorm12API.storeData(true);
|
|
368
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("browsed");
|
|
369
|
+
});
|
|
370
|
+
it('should set cmi.core.lesson_status to "browsed" - Initial Status', () => {
|
|
371
|
+
const scorm12API = api();
|
|
372
|
+
scorm12API.startingData = { cmi: { core: { lesson_status: "" } } };
|
|
373
|
+
scorm12API.cmi.core.lesson_mode = "browse";
|
|
374
|
+
scorm12API.storeData(true);
|
|
375
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("browsed");
|
|
376
|
+
});
|
|
377
|
+
it('should set cmi.core.lesson_status to "passed" - mastery_override: true', () => {
|
|
378
|
+
const scorm12API = api({
|
|
379
|
+
...DefaultSettings,
|
|
380
|
+
...{ mastery_override: true },
|
|
381
|
+
});
|
|
382
|
+
scorm12API.cmi.core.credit = "credit";
|
|
383
|
+
scorm12API.cmi.student_data.mastery_score = "60.0";
|
|
384
|
+
scorm12API.cmi.core.score.raw = "75.0";
|
|
385
|
+
scorm12API.storeData(true);
|
|
386
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("passed");
|
|
387
|
+
});
|
|
388
|
+
it('should set cmi.core.lesson_status to "failed" - mastery_override: true', () => {
|
|
389
|
+
const scorm12API = api({
|
|
390
|
+
...DefaultSettings,
|
|
391
|
+
...{ mastery_override: true },
|
|
392
|
+
});
|
|
393
|
+
scorm12API.cmi.core.credit = "credit";
|
|
394
|
+
scorm12API.cmi.student_data.mastery_score = "60.0";
|
|
395
|
+
scorm12API.cmi.core.score.raw = "55.0";
|
|
396
|
+
scorm12API.storeData(true);
|
|
397
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("failed");
|
|
398
|
+
});
|
|
399
|
+
it('should set cmi.core.lesson_status to "passed" - mastery_override: false', () => {
|
|
400
|
+
const scorm12API = api({
|
|
401
|
+
...DefaultSettings,
|
|
402
|
+
...{ mastery_override: false },
|
|
403
|
+
});
|
|
404
|
+
scorm12API.cmi.core.lesson_status = "failed"; // module author wanted the user to pass, so we don't override
|
|
405
|
+
scorm12API.cmi.core.credit = "credit";
|
|
406
|
+
scorm12API.cmi.student_data.mastery_score = "60.0";
|
|
407
|
+
scorm12API.cmi.core.score.raw = "75.0";
|
|
408
|
+
scorm12API.storeData(true);
|
|
409
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("failed");
|
|
410
|
+
});
|
|
411
|
+
it('should set cmi.core.lesson_status to "failed" - mastery_override: false', () => {
|
|
412
|
+
const scorm12API = api({
|
|
413
|
+
...DefaultSettings,
|
|
414
|
+
...{ mastery_override: false },
|
|
415
|
+
});
|
|
416
|
+
scorm12API.cmi.core.lesson_status = "passed"; // module author wanted the user to pass, so we don't override
|
|
417
|
+
scorm12API.cmi.core.credit = "credit";
|
|
418
|
+
scorm12API.cmi.student_data.mastery_score = "60.0";
|
|
419
|
+
scorm12API.cmi.core.score.raw = "55.0";
|
|
420
|
+
scorm12API.storeData(true);
|
|
421
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("passed");
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
describe("Event Handlers", () => {
|
|
426
|
+
it("Should handle SetValue.cmi.core.student_name event", () => {
|
|
427
|
+
const scorm12API = apiInitialized();
|
|
428
|
+
const callback = sinon.spy();
|
|
429
|
+
scorm12API.on("LMSSetValue.cmi.core.student_name", callback);
|
|
430
|
+
scorm12API.lmsSetValue("cmi.core.student_name", "@jcputney");
|
|
431
|
+
expect(callback.called).toBe(true);
|
|
432
|
+
});
|
|
433
|
+
it("Should handle SetValue.cmi.* event", () => {
|
|
434
|
+
const scorm12API = apiInitialized();
|
|
435
|
+
const callback = sinon.spy();
|
|
436
|
+
scorm12API.on("LMSSetValue.cmi.*", callback);
|
|
437
|
+
scorm12API.lmsSetValue("cmi.core.student_name", "@jcputney");
|
|
438
|
+
expect(callback.called).toBe(true);
|
|
439
|
+
});
|
|
440
|
+
it("Should handle CommitSuccess event", async () => {
|
|
441
|
+
const scorm12API = api({
|
|
442
|
+
...DefaultSettings,
|
|
443
|
+
...{
|
|
444
|
+
lmsCommitUrl: "/scorm12",
|
|
445
|
+
autocommit: true,
|
|
446
|
+
autocommitSeconds: 1,
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
scorm12API.lmsInitialize();
|
|
450
|
+
|
|
451
|
+
const callback = sinon.spy();
|
|
452
|
+
scorm12API.on("CommitSuccess", callback);
|
|
453
|
+
|
|
454
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
455
|
+
clock.tick(2000);
|
|
456
|
+
|
|
457
|
+
await clock.runAllAsync();
|
|
458
|
+
|
|
459
|
+
expect(callback.called).toBe(true);
|
|
460
|
+
});
|
|
461
|
+
it("Should clear all event listeners for CommitSuccess", async () => {
|
|
462
|
+
const scorm12API = api({
|
|
463
|
+
...DefaultSettings,
|
|
464
|
+
...{
|
|
465
|
+
lmsCommitUrl: "/scorm12",
|
|
466
|
+
autocommit: true,
|
|
467
|
+
autocommitSeconds: 1,
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
scorm12API.lmsInitialize();
|
|
471
|
+
|
|
472
|
+
const callback = sinon.spy();
|
|
473
|
+
const callback2 = sinon.spy();
|
|
474
|
+
scorm12API.on("CommitSuccess", callback);
|
|
475
|
+
scorm12API.on("CommitSuccess", callback2);
|
|
476
|
+
|
|
477
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
478
|
+
clock.tick(2000);
|
|
479
|
+
|
|
480
|
+
await clock.runAllAsync();
|
|
481
|
+
|
|
482
|
+
expect(callback.calledOnce).toBe(true);
|
|
483
|
+
expect(callback2.calledOnce).toBe(true);
|
|
484
|
+
|
|
485
|
+
scorm12API.clear("CommitSuccess");
|
|
486
|
+
|
|
487
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
488
|
+
clock.tick(2000);
|
|
489
|
+
|
|
490
|
+
await clock.runAllAsync();
|
|
491
|
+
|
|
492
|
+
expect(callback.calledTwice).toBe(false);
|
|
493
|
+
expect(callback2.calledTwice).toBe(false);
|
|
494
|
+
});
|
|
495
|
+
it("Should clear only the specific event listener for CommitSuccess", async () => {
|
|
496
|
+
const scorm12API = api({
|
|
497
|
+
...DefaultSettings,
|
|
498
|
+
...{
|
|
499
|
+
lmsCommitUrl: "/scorm12",
|
|
500
|
+
autocommit: true,
|
|
501
|
+
autocommitSeconds: 1,
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
scorm12API.lmsInitialize();
|
|
505
|
+
|
|
506
|
+
const callback = sinon.spy(() => 1);
|
|
507
|
+
const callback2 = sinon.spy(() => 2);
|
|
508
|
+
const callback3 = sinon.spy(() => 3);
|
|
509
|
+
const callback4 = sinon.spy(() => 4);
|
|
510
|
+
scorm12API.on("CommitSuccess", callback);
|
|
511
|
+
scorm12API.on("CommitSuccess", callback2);
|
|
512
|
+
scorm12API.on("LMSCommit", callback3);
|
|
513
|
+
scorm12API.on("LMSSetValue", callback4);
|
|
514
|
+
|
|
515
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
516
|
+
clock.tick(2000);
|
|
517
|
+
|
|
518
|
+
await clock.runAllAsync();
|
|
519
|
+
|
|
520
|
+
expect(callback.calledOnce).toBe(true);
|
|
521
|
+
expect(callback2.calledOnce).toBe(true);
|
|
522
|
+
expect(callback3.calledOnce).toBe(true);
|
|
523
|
+
expect(callback4.calledOnce).toBe(true);
|
|
524
|
+
|
|
525
|
+
scorm12API.off("CommitSuccess", callback);
|
|
526
|
+
|
|
527
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
528
|
+
clock.tick(2000);
|
|
529
|
+
|
|
530
|
+
await clock.runAllAsync();
|
|
531
|
+
|
|
532
|
+
expect(callback.calledTwice).toBe(false); // removed callback should not be called a second time
|
|
533
|
+
expect(callback2.calledTwice).toBe(true);
|
|
534
|
+
expect(callback3.calledTwice).toBe(true);
|
|
535
|
+
expect(callback4.calledTwice).toBe(true);
|
|
536
|
+
});
|
|
537
|
+
it("Should handle CommitError event", async () => {
|
|
538
|
+
const scorm12API = api({
|
|
539
|
+
...DefaultSettings,
|
|
540
|
+
...{
|
|
541
|
+
lmsCommitUrl: "/scorm12/error",
|
|
542
|
+
autocommit: true,
|
|
543
|
+
autocommitSeconds: 1,
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
scorm12API.lmsInitialize();
|
|
547
|
+
|
|
548
|
+
const callback = sinon.spy();
|
|
549
|
+
scorm12API.on("CommitError", callback);
|
|
550
|
+
|
|
551
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
552
|
+
clock.tick(2000);
|
|
553
|
+
|
|
554
|
+
await clock.runAllAsync();
|
|
555
|
+
|
|
556
|
+
expect(callback.called).toBe(true);
|
|
557
|
+
});
|
|
558
|
+
it("Should handle CommitError event when offline", async () => {
|
|
559
|
+
const scorm2004API = api({
|
|
560
|
+
...DefaultSettings,
|
|
561
|
+
...{
|
|
562
|
+
lmsCommitUrl: "/scorm12/does_not_exist",
|
|
563
|
+
autocommit: true,
|
|
564
|
+
autocommitSeconds: 1,
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
scorm2004API.lmsInitialize();
|
|
568
|
+
|
|
569
|
+
const callback = sinon.spy();
|
|
570
|
+
scorm2004API.on("CommitError", callback);
|
|
571
|
+
|
|
572
|
+
scorm2004API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
573
|
+
clock.tick(2000);
|
|
574
|
+
|
|
575
|
+
await clock.runAllAsync();
|
|
576
|
+
|
|
577
|
+
expect(callback.called).toBe(true);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
});
|