scorm-again 2.5.0 → 2.6.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.
Files changed (85) hide show
  1. package/dist/aicc.js +648 -485
  2. package/dist/aicc.js.map +1 -1
  3. package/dist/aicc.min.js +1 -1
  4. package/dist/aicc.min.js.map +1 -1
  5. package/dist/esm/aicc.js +664 -488
  6. package/dist/esm/aicc.js.map +1 -1
  7. package/dist/esm/aicc.min.js +1 -1
  8. package/dist/esm/aicc.min.js.map +1 -1
  9. package/dist/esm/scorm-again.js +1111 -729
  10. package/dist/esm/scorm-again.js.map +1 -1
  11. package/dist/esm/scorm-again.min.js +1 -1
  12. package/dist/esm/scorm-again.min.js.map +1 -1
  13. package/dist/esm/scorm12.js +506 -393
  14. package/dist/esm/scorm12.js.map +1 -1
  15. package/dist/esm/scorm12.min.js +1 -1
  16. package/dist/esm/scorm12.min.js.map +1 -1
  17. package/dist/esm/scorm2004.js +672 -451
  18. package/dist/esm/scorm2004.js.map +1 -1
  19. package/dist/esm/scorm2004.min.js +1 -1
  20. package/dist/esm/scorm2004.min.js.map +1 -1
  21. package/dist/scorm-again.js +1087 -717
  22. package/dist/scorm-again.js.map +1 -1
  23. package/dist/scorm-again.min.js +1 -1
  24. package/dist/scorm-again.min.js.map +1 -1
  25. package/dist/scorm12.js +493 -392
  26. package/dist/scorm12.js.map +1 -1
  27. package/dist/scorm12.min.js +1 -1
  28. package/dist/scorm12.min.js.map +1 -1
  29. package/dist/scorm2004.js +658 -450
  30. package/dist/scorm2004.js.map +1 -1
  31. package/dist/scorm2004.min.js +1 -1
  32. package/dist/scorm2004.min.js.map +1 -1
  33. package/package.json +14 -14
  34. package/src/AICC.ts +3 -0
  35. package/src/BaseAPI.ts +33 -30
  36. package/src/Scorm12API.ts +14 -14
  37. package/src/Scorm2004API.ts +99 -33
  38. package/src/cmi/aicc/attempts.ts +22 -12
  39. package/src/cmi/aicc/cmi.ts +2 -2
  40. package/src/cmi/aicc/core.ts +44 -26
  41. package/src/cmi/aicc/evaluation.ts +31 -12
  42. package/src/cmi/aicc/paths.ts +29 -15
  43. package/src/cmi/aicc/student_data.ts +14 -5
  44. package/src/cmi/aicc/student_demographics.ts +31 -24
  45. package/src/cmi/aicc/student_preferences.ts +11 -11
  46. package/src/cmi/aicc/tries.ts +24 -14
  47. package/src/cmi/aicc/validation.ts +3 -4
  48. package/src/cmi/common/array.ts +17 -5
  49. package/src/cmi/common/base_cmi.ts +3 -1
  50. package/src/cmi/common/score.ts +16 -13
  51. package/src/cmi/scorm12/cmi.ts +25 -10
  52. package/src/cmi/scorm12/interactions.ts +62 -28
  53. package/src/cmi/scorm12/nav.ts +13 -5
  54. package/src/cmi/scorm12/objectives.ts +28 -18
  55. package/src/cmi/scorm12/student_data.ts +15 -8
  56. package/src/cmi/scorm12/student_preference.ts +20 -13
  57. package/src/cmi/scorm12/validation.ts +7 -7
  58. package/src/cmi/scorm2004/adl.ts +141 -25
  59. package/src/cmi/scorm2004/cmi.ts +50 -55
  60. package/src/cmi/scorm2004/comments.ts +21 -20
  61. package/src/cmi/scorm2004/interactions.ts +73 -32
  62. package/src/cmi/scorm2004/learner_preference.ts +20 -13
  63. package/src/cmi/scorm2004/objectives.ts +41 -16
  64. package/src/cmi/scorm2004/score.ts +22 -11
  65. package/src/cmi/scorm2004/validation.ts +4 -4
  66. package/src/constants/api_constants.ts +8 -19
  67. package/src/constants/default_settings.ts +6 -5
  68. package/src/constants/error_codes.ts +5 -12
  69. package/src/constants/regex.ts +4 -10
  70. package/src/constants/response_constants.ts +1 -2
  71. package/src/exceptions/aicc_exceptions.ts +29 -0
  72. package/src/exceptions/scorm12_exceptions.ts +29 -0
  73. package/src/exceptions/scorm2004_exceptions.ts +29 -0
  74. package/src/exceptions.ts +0 -81
  75. package/src/types/api_types.ts +3 -2
  76. package/test/AICC.spec.ts +114 -43
  77. package/test/Scorm12API.spec.ts +37 -39
  78. package/test/Scorm2004API.spec.ts +165 -80
  79. package/test/cmi/aicc_cmi.spec.ts +6 -9
  80. package/test/cmi/scorm12_cmi.spec.ts +8 -8
  81. package/test/cmi/scorm2004_cmi.spec.ts +8 -9
  82. package/test/exceptions.spec.ts +11 -9
  83. package/test/types/api_types.spec.ts +3 -3
  84. package/test/utilities.spec.ts +1 -4
  85. package/webpack.config.js +4 -0
@@ -2,7 +2,7 @@ export type ErrorCode = {
2
2
  [key: string]: number;
3
3
  };
4
4
 
5
- const global: ErrorCode = {
5
+ export const global_errors: ErrorCode = {
6
6
  GENERAL: 101,
7
7
  INITIALIZATION_FAILED: 101,
8
8
  INITIALIZED: 101,
@@ -33,8 +33,8 @@ const global: ErrorCode = {
33
33
  DEPENDENCY_NOT_ESTABLISHED: 101,
34
34
  };
35
35
 
36
- const scorm12: ErrorCode = {
37
- ...global,
36
+ export const scorm12_errors: ErrorCode = {
37
+ ...global_errors,
38
38
  RETRIEVE_BEFORE_INIT: 301,
39
39
  STORE_BEFORE_INIT: 301,
40
40
  COMMIT_BEFORE_INIT: 301,
@@ -52,8 +52,8 @@ const scorm12: ErrorCode = {
52
52
  DEPENDENCY_NOT_ESTABLISHED: 408,
53
53
  };
54
54
 
55
- const scorm2004: ErrorCode = {
56
- ...global,
55
+ export const scorm2004_errors: ErrorCode = {
56
+ ...global_errors,
57
57
  INITIALIZATION_FAILED: 102,
58
58
  INITIALIZED: 103,
59
59
  TERMINATED: 104,
@@ -79,10 +79,3 @@ const scorm2004: ErrorCode = {
79
79
  VALUE_OUT_OF_RANGE: 407,
80
80
  DEPENDENCY_NOT_ESTABLISHED: 408,
81
81
  };
82
-
83
- const ErrorCodes = {
84
- scorm12,
85
- scorm2004,
86
- };
87
-
88
- export default ErrorCodes;
@@ -1,4 +1,4 @@
1
- const scorm12 = {
1
+ export const scorm12_regex = {
2
2
  CMIString256: "^.{0,255}$",
3
3
  CMIString4096: "^.{0,4096}$",
4
4
  CMITime: "^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$",
@@ -28,13 +28,13 @@ const scorm12 = {
28
28
  weighting_range: "-100#100",
29
29
  text_range: "-1#1",
30
30
  };
31
- const aicc = {
32
- ...scorm12,
31
+ export const aicc_regex = {
32
+ ...scorm12_regex,
33
33
  ...{
34
34
  CMIIdentifier: "^\\w{1,255}$",
35
35
  },
36
36
  };
37
- const scorm2004 = {
37
+ export const scorm2004_regex = {
38
38
  CMIString200: "^[\\u0000-\\uFFFF]{0,200}$",
39
39
  CMIString250: "^[\\u0000-\\uFFFF]{0,250}$",
40
40
  CMIString1000: "^[\\u0000-\\uFFFF]{0,1000}$",
@@ -89,9 +89,3 @@ const scorm2004 = {
89
89
  text_range: "-1#1",
90
90
  progress_range: "0#1",
91
91
  };
92
- const Regex = {
93
- aicc: aicc,
94
- scorm12: scorm12,
95
- scorm2004: scorm2004,
96
- };
97
- export default Regex;
@@ -1,6 +1,5 @@
1
- import Regex from "./regex";
1
+ import { scorm2004_regex } from "./regex";
2
2
 
3
- const scorm2004_regex = Regex.scorm2004;
4
3
  export const LearnerResponses: Responses = {
5
4
  "true-false": {
6
5
  format: "^true$|^false$",
@@ -0,0 +1,29 @@
1
+ import { ValidationError } from "../exceptions";
2
+ import { aicc_constants } from "../constants/api_constants";
3
+
4
+ const aicc_errors = aicc_constants.error_descriptions;
5
+
6
+ /**
7
+ * AICC Validation Error
8
+ */
9
+ export class AICCValidationError extends ValidationError {
10
+ /**
11
+ * Constructor to take in an error code
12
+ * @param {number} errorCode
13
+ */
14
+ constructor(errorCode: number) {
15
+ if ({}.hasOwnProperty.call(aicc_errors, String(errorCode))) {
16
+ super(
17
+ errorCode,
18
+ aicc_errors[String(errorCode)].basicMessage,
19
+ aicc_errors[String(errorCode)].detailMessage,
20
+ );
21
+ } else {
22
+ super(
23
+ 101,
24
+ aicc_errors["101"].basicMessage,
25
+ aicc_errors["101"].detailMessage,
26
+ );
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ import { ValidationError } from "../exceptions";
2
+ import { scorm12_constants } from "../constants/api_constants";
3
+
4
+ const scorm12_errors = scorm12_constants.error_descriptions;
5
+
6
+ /**
7
+ * SCORM 1.2 Validation Error
8
+ */
9
+ export class Scorm12ValidationError extends ValidationError {
10
+ /**
11
+ * Constructor to take in an error code
12
+ * @param {number} errorCode
13
+ */
14
+ constructor(errorCode: number) {
15
+ if ({}.hasOwnProperty.call(scorm12_errors, String(errorCode))) {
16
+ super(
17
+ errorCode,
18
+ scorm12_errors[String(errorCode)].basicMessage,
19
+ scorm12_errors[String(errorCode)].detailMessage,
20
+ );
21
+ } else {
22
+ super(
23
+ 101,
24
+ scorm12_errors["101"].basicMessage,
25
+ scorm12_errors["101"].detailMessage,
26
+ );
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ import { ValidationError } from "../exceptions";
2
+ import { scorm2004_constants } from "../constants/api_constants";
3
+
4
+ const scorm2004_errors = scorm2004_constants.error_descriptions;
5
+
6
+ /**
7
+ * SCORM 2004 Validation Error
8
+ */
9
+ export class Scorm2004ValidationError extends ValidationError {
10
+ /**
11
+ * Constructor to take in an error code
12
+ * @param {number} errorCode
13
+ */
14
+ constructor(errorCode: number) {
15
+ if ({}.hasOwnProperty.call(scorm2004_errors, String(errorCode))) {
16
+ super(
17
+ errorCode,
18
+ scorm2004_errors[String(errorCode)].basicMessage,
19
+ scorm2004_errors[String(errorCode)].detailMessage,
20
+ );
21
+ } else {
22
+ super(
23
+ 101,
24
+ scorm2004_errors["101"].basicMessage,
25
+ scorm2004_errors["101"].detailMessage,
26
+ );
27
+ }
28
+ }
29
+ }
package/src/exceptions.ts CHANGED
@@ -1,9 +1,3 @@
1
- import APIConstants from "./constants/api_constants";
2
-
3
- const scorm12_errors = APIConstants.scorm12.error_descriptions;
4
- const aicc_errors = APIConstants.aicc.error_descriptions;
5
- const scorm2004_errors = APIConstants.scorm2004.error_descriptions;
6
-
7
1
  type APIError = {
8
2
  errorCode: number;
9
3
  errorMessage: string;
@@ -73,78 +67,3 @@ export class ValidationError
73
67
  return this._detailedMessage;
74
68
  }
75
69
  }
76
-
77
- /**
78
- * SCORM 1.2 Validation Error
79
- */
80
- export class Scorm12ValidationError extends ValidationError {
81
- /**
82
- * Constructor to take in an error code
83
- * @param {number} errorCode
84
- */
85
- constructor(errorCode: number) {
86
- if ({}.hasOwnProperty.call(scorm12_errors, String(errorCode))) {
87
- super(
88
- errorCode,
89
- scorm12_errors[String(errorCode)].basicMessage,
90
- scorm12_errors[String(errorCode)].detailMessage,
91
- );
92
- } else {
93
- super(
94
- 101,
95
- scorm12_errors["101"].basicMessage,
96
- scorm12_errors["101"].detailMessage,
97
- );
98
- }
99
- }
100
- }
101
-
102
- /**
103
- * AICC Validation Error
104
- */
105
- export class AICCValidationError extends ValidationError {
106
- /**
107
- * Constructor to take in an error code
108
- * @param {number} errorCode
109
- */
110
- constructor(errorCode: number) {
111
- if ({}.hasOwnProperty.call(aicc_errors, String(errorCode))) {
112
- super(
113
- errorCode,
114
- aicc_errors[String(errorCode)].basicMessage,
115
- aicc_errors[String(errorCode)].detailMessage,
116
- );
117
- } else {
118
- super(
119
- 101,
120
- aicc_errors["101"].basicMessage,
121
- aicc_errors["101"].detailMessage,
122
- );
123
- }
124
- }
125
- }
126
-
127
- /**
128
- * SCORM 2004 Validation Error
129
- */
130
- export class Scorm2004ValidationError extends ValidationError {
131
- /**
132
- * Constructor to take in an error code
133
- * @param {number} errorCode
134
- */
135
- constructor(errorCode: number) {
136
- if ({}.hasOwnProperty.call(scorm2004_errors, String(errorCode))) {
137
- super(
138
- errorCode,
139
- scorm2004_errors[String(errorCode)].basicMessage,
140
- scorm2004_errors[String(errorCode)].detailMessage,
141
- );
142
- } else {
143
- super(
144
- 101,
145
- scorm2004_errors["101"].basicMessage,
146
- scorm2004_errors["101"].detailMessage,
147
- );
148
- }
149
- }
150
- }
@@ -23,10 +23,11 @@ export type Settings = {
23
23
  responseHandler?: (response: Response) => Promise<ResultObject>;
24
24
  requestHandler?: (commitObject: any) => any;
25
25
  onLogMessage?: (messageLevel: LogLevel, logMessage: string) => void;
26
- scoItemIds?: string[];
27
- scoItemIdValidator?: false | ((scoItemId: string) => boolean);
28
26
  mastery_override?: boolean;
29
27
  renderCommonCommitFields?: boolean;
28
+ scoItemIds?: string[];
29
+ scoItemIdValidator?: false | ((scoItemId: string) => boolean);
30
+ globalObjectiveIds?: string[];
30
31
  };
31
32
 
32
33
  export type RefObject = {
package/test/AICC.spec.ts CHANGED
@@ -1,18 +1,25 @@
1
1
  import { expect } from "expect";
2
- import { describe } from "mocha";
2
+ import { describe, it } from "mocha";
3
3
  import * as h from "./api_helpers";
4
- import ErrorCodes from "../src/constants/error_codes";
4
+ import { scorm12_errors } from "../src/constants/error_codes";
5
5
  import { AICCImpl } from "../src/AICC";
6
+ import { DefaultSettings } from "../src/constants/default_settings";
7
+ import * as sinon from "sinon";
8
+ import { CMITries } from "../src/cmi/aicc/tries";
9
+ import { CMIInteractions } from "../src/cmi/scorm12/interactions";
10
+ import { RefObject, Settings } from "../src/types/api_types";
6
11
 
7
- const scorm12_error_codes = ErrorCodes.scorm12;
8
-
9
- const api = () => {
10
- const API = new AICCImpl();
12
+ const api = (settings?: Settings, startingData: RefObject = {}) => {
13
+ const API = new AICCImpl(settings);
11
14
  API.apiLogLevel = 1;
15
+ if (startingData) {
16
+ API.startingData = startingData;
17
+ }
12
18
  return API;
13
19
  };
14
- const apiInitialized = () => {
20
+ const apiInitialized = (startingData?: RefObject) => {
15
21
  const API = api();
22
+ API.loadFromJSON(startingData ? startingData : {}, "");
16
23
  API.lmsInitialize();
17
24
  return API;
18
25
  };
@@ -23,52 +30,52 @@ describe("AICC API Tests", () => {
23
30
  h.checkSetCMIValue({
24
31
  api: api(),
25
32
  fieldName: "cmi._version",
26
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
33
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
27
34
  });
28
35
  h.checkSetCMIValue({
29
36
  api: api(),
30
37
  fieldName: "cmi._children",
31
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
38
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
32
39
  });
33
40
  h.checkSetCMIValue({
34
41
  api: api(),
35
42
  fieldName: "cmi.core._children",
36
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
43
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
37
44
  });
38
45
  h.checkSetCMIValue({
39
46
  api: api(),
40
47
  fieldName: "cmi.core.score._children",
41
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
48
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
42
49
  });
43
50
  h.checkSetCMIValue({
44
51
  api: api(),
45
52
  fieldName: "cmi.objectives._children",
46
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
53
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
47
54
  });
48
55
  h.checkSetCMIValue({
49
56
  api: api(),
50
57
  fieldName: "cmi.objectives._count",
51
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
58
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
52
59
  });
53
60
  h.checkSetCMIValue({
54
61
  api: api(),
55
62
  fieldName: "cmi.interactions._children",
56
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
63
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
57
64
  });
58
65
  h.checkSetCMIValue({
59
66
  api: api(),
60
67
  fieldName: "cmi.interactions._count",
61
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
68
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
62
69
  });
63
70
  h.checkSetCMIValue({
64
71
  api: api(),
65
72
  fieldName: "cmi.interactions.0.objectives._count",
66
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
73
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
67
74
  });
68
75
  h.checkSetCMIValue({
69
76
  api: api(),
70
77
  fieldName: "cmi.interactions.0.correct_responses._count",
71
- expectedError: scorm12_error_codes.INVALID_SET_VALUE,
78
+ expectedError: scorm12_errors.INVALID_SET_VALUE,
72
79
  });
73
80
  });
74
81
 
@@ -76,57 +83,57 @@ describe("AICC API Tests", () => {
76
83
  h.checkSetCMIValue({
77
84
  api: apiInitialized(),
78
85
  fieldName: "cmi.launch_data",
79
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
86
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
80
87
  });
81
88
  h.checkSetCMIValue({
82
89
  api: apiInitialized(),
83
90
  fieldName: "cmi.comments_from_lms",
84
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
91
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
85
92
  });
86
93
  h.checkSetCMIValue({
87
94
  api: apiInitialized(),
88
95
  fieldName: "cmi.core.student_id",
89
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
96
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
90
97
  });
91
98
  h.checkSetCMIValue({
92
99
  api: apiInitialized(),
93
100
  fieldName: "cmi.core.student_name",
94
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
101
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
95
102
  });
96
103
  h.checkSetCMIValue({
97
104
  api: apiInitialized(),
98
105
  fieldName: "cmi.core.credit",
99
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
106
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
100
107
  });
101
108
  h.checkSetCMIValue({
102
109
  api: apiInitialized(),
103
110
  fieldName: "cmi.core.entry",
104
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
111
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
105
112
  });
106
113
  h.checkSetCMIValue({
107
114
  api: apiInitialized(),
108
115
  fieldName: "cmi.core.total_time",
109
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
116
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
110
117
  });
111
118
  h.checkSetCMIValue({
112
119
  api: apiInitialized(),
113
120
  fieldName: "cmi.core.lesson_mode",
114
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
121
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
115
122
  });
116
123
  h.checkSetCMIValue({
117
124
  api: apiInitialized(),
118
125
  fieldName: "cmi.student_data.mastery_score",
119
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
126
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
120
127
  });
121
128
  h.checkSetCMIValue({
122
129
  api: apiInitialized(),
123
130
  fieldName: "cmi.student_data.max_time_allowed",
124
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
131
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
125
132
  });
126
133
  h.checkSetCMIValue({
127
134
  api: apiInitialized(),
128
135
  fieldName: "cmi.student_data.time_limit_action",
129
- expectedError: scorm12_error_codes.READ_ONLY_ELEMENT,
136
+ expectedError: scorm12_errors.READ_ONLY_ELEMENT,
130
137
  });
131
138
  });
132
139
  });
@@ -136,19 +143,19 @@ describe("AICC API Tests", () => {
136
143
  h.checkLMSGetValue({
137
144
  api: apiInitialized(),
138
145
  fieldName: "cmi.core.close",
139
- expectedError: scorm12_error_codes.GENERAL,
146
+ expectedError: scorm12_errors.GENERAL,
140
147
  errorThrown: false,
141
148
  });
142
149
  h.checkLMSGetValue({
143
150
  api: apiInitialized(),
144
151
  fieldName: "cmi.exit",
145
- expectedError: scorm12_error_codes.GENERAL,
152
+ expectedError: scorm12_errors.GENERAL,
146
153
  errorThrown: false,
147
154
  });
148
155
  h.checkLMSGetValue({
149
156
  api: apiInitialized(),
150
157
  fieldName: "cmi.entry",
151
- expectedError: scorm12_error_codes.GENERAL,
158
+ expectedError: scorm12_errors.GENERAL,
152
159
  errorThrown: false,
153
160
  });
154
161
  });
@@ -157,66 +164,66 @@ describe("AICC API Tests", () => {
157
164
  h.checkLMSGetValue({
158
165
  api: apiInitialized(),
159
166
  fieldName: "cmi.core.exit",
160
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
167
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
161
168
  });
162
169
  h.checkLMSGetValue({
163
170
  api: apiInitialized(),
164
171
  fieldName: "cmi.core.session_time",
165
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
172
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
166
173
  });
167
174
  h.checkLMSGetValue({
168
175
  api: apiInitialized(),
169
176
  fieldName: "cmi.interactions.0.id",
170
177
  initializeFirst: true,
171
178
  initializationValue: "AAA",
172
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
179
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
173
180
  });
174
181
  h.checkLMSGetValue({
175
182
  api: apiInitialized(),
176
183
  fieldName: "cmi.interactions.0.time",
177
184
  initializeFirst: true,
178
185
  initializationValue: "12:59:59",
179
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
186
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
180
187
  });
181
188
  h.checkLMSGetValue({
182
189
  api: apiInitialized(),
183
190
  fieldName: "cmi.interactions.0.type",
184
191
  initializeFirst: true,
185
192
  initializationValue: "true-false",
186
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
193
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
187
194
  });
188
195
  h.checkLMSGetValue({
189
196
  api: apiInitialized(),
190
197
  fieldName: "cmi.interactions.0.weighting",
191
198
  initializeFirst: true,
192
199
  initializationValue: "0",
193
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
200
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
194
201
  });
195
202
  h.checkLMSGetValue({
196
203
  api: apiInitialized(),
197
204
  fieldName: "cmi.interactions.0.student_response",
198
205
  initializeFirst: true,
199
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
206
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
200
207
  });
201
208
  h.checkLMSGetValue({
202
209
  api: apiInitialized(),
203
210
  fieldName: "cmi.interactions.0.result",
204
211
  initializeFirst: true,
205
212
  initializationValue: "correct",
206
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
213
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
207
214
  });
208
215
  h.checkLMSGetValue({
209
216
  api: apiInitialized(),
210
217
  fieldName: "cmi.interactions.0.latency",
211
218
  initializeFirst: true,
212
219
  initializationValue: "01:59:59.99",
213
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
220
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
214
221
  });
215
222
  h.checkLMSGetValue({
216
223
  api: apiInitialized(),
217
224
  fieldName: "cmi.interactions.0.correct_responses.0.pattern",
218
225
  initializeFirst: true,
219
- expectedError: scorm12_error_codes.WRITE_ONLY_ELEMENT,
226
+ expectedError: scorm12_errors.WRITE_ONLY_ELEMENT,
220
227
  });
221
228
  });
222
229
  });
@@ -226,12 +233,12 @@ describe("AICC API Tests", () => {
226
233
  h.checkLMSSetValue({
227
234
  api: api(),
228
235
  fieldName: "cmi.objectives.0.id",
229
- expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
236
+ expectedError: scorm12_errors.STORE_BEFORE_INIT,
230
237
  });
231
238
  h.checkLMSSetValue({
232
239
  api: api(),
233
240
  fieldName: "cmi.interactions.0.id",
234
- expectedError: scorm12_error_codes.STORE_BEFORE_INIT,
241
+ expectedError: scorm12_errors.STORE_BEFORE_INIT,
235
242
  });
236
243
  });
237
244
 
@@ -269,6 +276,70 @@ describe("AICC API Tests", () => {
269
276
  });
270
277
  });
271
278
 
279
+ describe("reset()", () => {
280
+ it("should reset all CMI values to their default state", () => {
281
+ const aiccAPI = api();
282
+ aiccAPI.cmi.core.student_id = "student_1";
283
+ aiccAPI.lmsInitialize();
284
+
285
+ aiccAPI.cmi.core.session_time = "01:00:00";
286
+ aiccAPI.setCMIValue("cmi.student_data.tries.0.score.max", "99");
287
+
288
+ aiccAPI.reset();
289
+ expect(aiccAPI.cmi.interactions).toEqual(new CMIInteractions());
290
+ expect(aiccAPI.cmi.core.student_id).toEqual("student_1");
291
+ expect(aiccAPI.getCMIValue("cmi.student_data.tries")).toEqual(
292
+ new CMITries(),
293
+ );
294
+ });
295
+
296
+ it("should keep original settings", () => {
297
+ const aiccAPI = api({
298
+ dataCommitFormat: "flattened",
299
+ autocommit: true,
300
+ });
301
+
302
+ aiccAPI.reset();
303
+
304
+ expect(aiccAPI.settings.sendFullCommit).toEqual(
305
+ DefaultSettings.sendFullCommit,
306
+ );
307
+ expect(aiccAPI.settings.dataCommitFormat).toEqual("flattened");
308
+ expect(aiccAPI.settings.autocommit).toEqual(true);
309
+ });
310
+
311
+ it("should be able to override original settings", () => {
312
+ const aiccAPI = api({
313
+ ...DefaultSettings,
314
+ dataCommitFormat: "flattened",
315
+ autocommit: true,
316
+ });
317
+
318
+ aiccAPI.reset({
319
+ alwaysSendTotalTime: !DefaultSettings.alwaysSendTotalTime,
320
+ });
321
+
322
+ expect(aiccAPI.settings.sendFullCommit).toEqual(
323
+ DefaultSettings.sendFullCommit,
324
+ );
325
+ expect(aiccAPI.settings.dataCommitFormat).toEqual("flattened");
326
+ expect(aiccAPI.settings.autocommit).toEqual(true);
327
+ expect(aiccAPI.settings.alwaysSendTotalTime).toEqual(
328
+ !DefaultSettings.alwaysSendTotalTime,
329
+ );
330
+ });
331
+
332
+ it("should call commonReset from the superclass", () => {
333
+ const aiccAPI = api();
334
+ const commonResetSpy = sinon.spy(aiccAPI, "commonReset");
335
+
336
+ aiccAPI.reset();
337
+
338
+ expect(commonResetSpy.calledOnce).toBe(true);
339
+ commonResetSpy.restore();
340
+ });
341
+ });
342
+
272
343
  describe("replaceWithAnotherScormAPI()", () => {
273
344
  const firstAPI = api();
274
345
  const secondAPI = api();