@memberjunction/actions-bizapps-lms 4.2.0 → 4.3.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/__tests__/lms.test.d.ts +2 -0
- package/dist/__tests__/lms.test.d.ts.map +1 -0
- package/dist/__tests__/lms.test.js +232 -0
- package/dist/__tests__/lms.test.js.map +1 -0
- package/package.json +6 -6
- package/src/__tests__/lms.test.ts +270 -0
- package/vitest.config.ts +3 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @memberjunction/actions-bizapps-lms
|
|
2
2
|
|
|
3
|
+
## 4.3.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [564e1af]
|
|
8
|
+
- @memberjunction/core@4.3.0
|
|
9
|
+
- @memberjunction/core-entities@4.3.0
|
|
10
|
+
- @memberjunction/actions-base@4.3.0
|
|
11
|
+
- @memberjunction/actions@4.3.0
|
|
12
|
+
- @memberjunction/global@4.3.0
|
|
13
|
+
|
|
3
14
|
## 4.2.0
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lms.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/lms.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
// Mock dependencies
|
|
3
|
+
vi.mock('@memberjunction/actions', () => ({
|
|
4
|
+
BaseAction: class BaseAction {
|
|
5
|
+
async InternalRunAction() { return {}; }
|
|
6
|
+
}
|
|
7
|
+
}));
|
|
8
|
+
vi.mock('@memberjunction/global', () => ({
|
|
9
|
+
RegisterClass: () => (target) => target
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('@memberjunction/core', () => ({
|
|
12
|
+
UserInfo: class UserInfo {
|
|
13
|
+
},
|
|
14
|
+
Metadata: vi.fn(),
|
|
15
|
+
RunView: vi.fn().mockImplementation(() => ({
|
|
16
|
+
RunView: vi.fn().mockResolvedValue({ Success: true, Results: [] })
|
|
17
|
+
}))
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('@memberjunction/core-entities', () => ({
|
|
20
|
+
CompanyIntegrationEntity: class CompanyIntegrationEntity {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.CompanyID = '';
|
|
23
|
+
this.APIKey = null;
|
|
24
|
+
this.AccessToken = null;
|
|
25
|
+
this.ExternalSystemID = null;
|
|
26
|
+
this.CustomAttribute1 = null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('@memberjunction/actions-base', () => ({
|
|
31
|
+
ActionParam: class ActionParam {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.Name = '';
|
|
34
|
+
this.Value = null;
|
|
35
|
+
this.Type = 'Input';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
import { BaseLMSAction } from '../base/base-lms.action.js';
|
|
40
|
+
import { LearnWorldsBaseAction } from '../providers/learnworlds/learnworlds-base.action.js';
|
|
41
|
+
// Concrete subclass for testing BaseLMSAction
|
|
42
|
+
class TestLMSAction extends BaseLMSAction {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.lmsProvider = 'TestLMS';
|
|
46
|
+
this.integrationName = 'TestLMS';
|
|
47
|
+
}
|
|
48
|
+
async InternalRunAction() {
|
|
49
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
describe('BaseLMSAction', () => {
|
|
53
|
+
let action;
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
action = new TestLMSAction();
|
|
56
|
+
});
|
|
57
|
+
describe('calculateProgressPercentage', () => {
|
|
58
|
+
it('should calculate percentage correctly', () => {
|
|
59
|
+
expect(action['calculateProgressPercentage'](75, 100)).toBe(75);
|
|
60
|
+
expect(action['calculateProgressPercentage'](1, 3)).toBe(33);
|
|
61
|
+
});
|
|
62
|
+
it('should return 0 when total is 0', () => {
|
|
63
|
+
expect(action['calculateProgressPercentage'](0, 0)).toBe(0);
|
|
64
|
+
});
|
|
65
|
+
it('should return 100 when all completed', () => {
|
|
66
|
+
expect(action['calculateProgressPercentage'](50, 50)).toBe(100);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('formatDuration', () => {
|
|
70
|
+
it('should format seconds only', () => {
|
|
71
|
+
expect(action['formatDuration'](30)).toBe('30s');
|
|
72
|
+
});
|
|
73
|
+
it('should format minutes and seconds', () => {
|
|
74
|
+
expect(action['formatDuration'](90)).toBe('1m 30s');
|
|
75
|
+
});
|
|
76
|
+
it('should format hours, minutes, and seconds', () => {
|
|
77
|
+
expect(action['formatDuration'](3661)).toBe('1h 1m 1s');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
describe('mapEnrollmentStatus', () => {
|
|
81
|
+
it('should map active statuses', () => {
|
|
82
|
+
expect(action['mapEnrollmentStatus']('active')).toBe('active');
|
|
83
|
+
});
|
|
84
|
+
it('should map completed statuses', () => {
|
|
85
|
+
expect(action['mapEnrollmentStatus']('completed')).toBe('completed');
|
|
86
|
+
expect(action['mapEnrollmentStatus']('finished')).toBe('completed');
|
|
87
|
+
});
|
|
88
|
+
it('should map expired statuses', () => {
|
|
89
|
+
expect(action['mapEnrollmentStatus']('expired')).toBe('expired');
|
|
90
|
+
});
|
|
91
|
+
it('should map suspended statuses', () => {
|
|
92
|
+
expect(action['mapEnrollmentStatus']('suspended')).toBe('suspended');
|
|
93
|
+
expect(action['mapEnrollmentStatus']('paused')).toBe('suspended');
|
|
94
|
+
expect(action['mapEnrollmentStatus']('inactive')).toBe('suspended');
|
|
95
|
+
});
|
|
96
|
+
it('should return unknown for unrecognized statuses', () => {
|
|
97
|
+
expect(action['mapEnrollmentStatus']('pending')).toBe('unknown');
|
|
98
|
+
expect(action['mapEnrollmentStatus']('review')).toBe('unknown');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('formatLMSDate', () => {
|
|
102
|
+
it('should format date as ISO string', () => {
|
|
103
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
104
|
+
expect(action['formatLMSDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('parseLMSDate', () => {
|
|
108
|
+
it('should parse ISO date string', () => {
|
|
109
|
+
const result = action['parseLMSDate']('2024-06-15T10:30:00Z');
|
|
110
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('buildLMSErrorMessage', () => {
|
|
114
|
+
it('should build error message without system error', () => {
|
|
115
|
+
expect(action['buildLMSErrorMessage']('GetCourse', 'Not found'))
|
|
116
|
+
.toBe('LMS operation failed: GetCourse. Not found');
|
|
117
|
+
});
|
|
118
|
+
it('should include system error details', () => {
|
|
119
|
+
const result = action['buildLMSErrorMessage']('GetCourse', 'Failed', new Error('timeout'));
|
|
120
|
+
expect(result).toContain('System error: timeout');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('getCommonLMSParams', () => {
|
|
124
|
+
it('should return CompanyID param', () => {
|
|
125
|
+
const params = action['getCommonLMSParams']();
|
|
126
|
+
expect(params).toHaveLength(1);
|
|
127
|
+
expect(params[0].Name).toBe('CompanyID');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('getCredentialFromEnv', () => {
|
|
131
|
+
it('should build correct env key', () => {
|
|
132
|
+
process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'] = 'key123';
|
|
133
|
+
expect(action['getCredentialFromEnv']('COMP1', 'API_KEY')).toBe('key123');
|
|
134
|
+
delete process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'];
|
|
135
|
+
});
|
|
136
|
+
it('should return undefined for missing env var', () => {
|
|
137
|
+
const result = action['getCredentialFromEnv']('COMP1', 'MISSING_KEY');
|
|
138
|
+
expect(result).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe('getParamValue', () => {
|
|
142
|
+
it('should find param by name', () => {
|
|
143
|
+
const params = [{ Name: 'CourseID', Value: 'c1', Type: 'Input' }];
|
|
144
|
+
expect(action['getParamValue'](params, 'CourseID')).toBe('c1');
|
|
145
|
+
});
|
|
146
|
+
it('should return undefined for missing param', () => {
|
|
147
|
+
expect(action['getParamValue']([], 'Missing')).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('LearnWorldsBaseAction', () => {
|
|
152
|
+
class TestLearnWorldsAction extends LearnWorldsBaseAction {
|
|
153
|
+
async InternalRunAction() {
|
|
154
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let action;
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
action = new TestLearnWorldsAction();
|
|
160
|
+
});
|
|
161
|
+
describe('parseLearnWorldsDate', () => {
|
|
162
|
+
it('should parse ISO date string', () => {
|
|
163
|
+
const result = action['parseLearnWorldsDate']('2024-06-15T10:30:00Z');
|
|
164
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
165
|
+
});
|
|
166
|
+
it('should parse unix timestamp (seconds)', () => {
|
|
167
|
+
const result = action['parseLearnWorldsDate'](1718444400);
|
|
168
|
+
expect(result).toBeInstanceOf(Date);
|
|
169
|
+
expect(result.getTime()).toBe(1718444400000);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe('formatLearnWorldsDate', () => {
|
|
173
|
+
it('should format date as ISO string', () => {
|
|
174
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
175
|
+
expect(action['formatLearnWorldsDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('mapUserStatus', () => {
|
|
179
|
+
it('should map active status', () => {
|
|
180
|
+
expect(action['mapUserStatus']('active')).toBe('active');
|
|
181
|
+
});
|
|
182
|
+
it('should map inactive status', () => {
|
|
183
|
+
expect(action['mapUserStatus']('inactive')).toBe('inactive');
|
|
184
|
+
});
|
|
185
|
+
it('should map suspended/blocked statuses', () => {
|
|
186
|
+
expect(action['mapUserStatus']('suspended')).toBe('suspended');
|
|
187
|
+
expect(action['mapUserStatus']('blocked')).toBe('suspended');
|
|
188
|
+
});
|
|
189
|
+
it('should return inactive for unknown statuses', () => {
|
|
190
|
+
expect(action['mapUserStatus']('unknown')).toBe('inactive');
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe('mapLearnWorldsEnrollmentStatus', () => {
|
|
194
|
+
it('should return completed when completed is true', () => {
|
|
195
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ completed: true, active: true })).toBe('completed');
|
|
196
|
+
});
|
|
197
|
+
it('should return expired when expired is true', () => {
|
|
198
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ expired: true, active: true })).toBe('expired');
|
|
199
|
+
});
|
|
200
|
+
it('should return suspended when suspended is true', () => {
|
|
201
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ suspended: true, active: false })).toBe('suspended');
|
|
202
|
+
});
|
|
203
|
+
it('should return suspended when not active', () => {
|
|
204
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: false })).toBe('suspended');
|
|
205
|
+
});
|
|
206
|
+
it('should return active when active and not completed/expired/suspended', () => {
|
|
207
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: true })).toBe('active');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe('calculateProgress', () => {
|
|
211
|
+
it('should extract progress data', () => {
|
|
212
|
+
const result = action['calculateProgress']({
|
|
213
|
+
percentage: 75,
|
|
214
|
+
completed_units: 15,
|
|
215
|
+
total_units: 20,
|
|
216
|
+
time_spent: 3600
|
|
217
|
+
});
|
|
218
|
+
expect(result.percentage).toBe(75);
|
|
219
|
+
expect(result.completedUnits).toBe(15);
|
|
220
|
+
expect(result.totalUnits).toBe(20);
|
|
221
|
+
expect(result.timeSpent).toBe(3600);
|
|
222
|
+
});
|
|
223
|
+
it('should default missing values to 0', () => {
|
|
224
|
+
const result = action['calculateProgress']({});
|
|
225
|
+
expect(result.percentage).toBe(0);
|
|
226
|
+
expect(result.completedUnits).toBe(0);
|
|
227
|
+
expect(result.totalUnits).toBe(0);
|
|
228
|
+
expect(result.timeSpent).toBe(0);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
//# sourceMappingURL=lms.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lms.test.js","sourceRoot":"","sources":["../../src/__tests__/lms.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,oBAAoB;AACpB,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,UAAU,EAAE,MAAM,UAAU;QACd,KAAK,CAAC,iBAAiB,KAAuB,OAAO,EAAE,CAAC,CAAC,CAAC;KACvE;CACJ,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,MAAe,EAAE,EAAE,CAAC,MAAM;CACnD,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,QAAQ,EAAE,MAAM,QAAQ;KAAG;IAC3B,QAAQ,EAAE,EAAE,CAAC,EAAE,EA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izapps-lms",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.3.0",
|
|
5
5
|
"description": "LMS system integration actions for MemberJunction",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"author": "MemberJunction",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@memberjunction/core": "4.
|
|
28
|
-
"@memberjunction/global": "4.
|
|
29
|
-
"@memberjunction/actions-base": "4.
|
|
30
|
-
"@memberjunction/actions": "4.
|
|
31
|
-
"@memberjunction/core-entities": "4.
|
|
27
|
+
"@memberjunction/core": "4.3.0",
|
|
28
|
+
"@memberjunction/global": "4.3.0",
|
|
29
|
+
"@memberjunction/actions-base": "4.3.0",
|
|
30
|
+
"@memberjunction/actions": "4.3.0",
|
|
31
|
+
"@memberjunction/core-entities": "4.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "24.10.11",
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock dependencies
|
|
4
|
+
vi.mock('@memberjunction/actions', () => ({
|
|
5
|
+
BaseAction: class BaseAction {
|
|
6
|
+
protected async InternalRunAction(): Promise<unknown> { return {}; }
|
|
7
|
+
}
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
vi.mock('@memberjunction/global', () => ({
|
|
11
|
+
RegisterClass: () => (target: unknown) => target
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
vi.mock('@memberjunction/core', () => ({
|
|
15
|
+
UserInfo: class UserInfo {},
|
|
16
|
+
Metadata: vi.fn(),
|
|
17
|
+
RunView: vi.fn().mockImplementation(() => ({
|
|
18
|
+
RunView: vi.fn().mockResolvedValue({ Success: true, Results: [] })
|
|
19
|
+
}))
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock('@memberjunction/core-entities', () => ({
|
|
23
|
+
CompanyIntegrationEntity: class CompanyIntegrationEntity {
|
|
24
|
+
CompanyID: string = '';
|
|
25
|
+
APIKey: string | null = null;
|
|
26
|
+
AccessToken: string | null = null;
|
|
27
|
+
ExternalSystemID: string | null = null;
|
|
28
|
+
CustomAttribute1: string | null = null;
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
vi.mock('@memberjunction/actions-base', () => ({
|
|
33
|
+
ActionParam: class ActionParam {
|
|
34
|
+
Name: string = '';
|
|
35
|
+
Value: unknown = null;
|
|
36
|
+
Type: string = 'Input';
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
import { BaseLMSAction } from '../base/base-lms.action';
|
|
41
|
+
import { LearnWorldsBaseAction } from '../providers/learnworlds/learnworlds-base.action';
|
|
42
|
+
|
|
43
|
+
// Concrete subclass for testing BaseLMSAction
|
|
44
|
+
class TestLMSAction extends BaseLMSAction {
|
|
45
|
+
protected lmsProvider = 'TestLMS';
|
|
46
|
+
protected integrationName = 'TestLMS';
|
|
47
|
+
|
|
48
|
+
protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
|
|
49
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('BaseLMSAction', () => {
|
|
54
|
+
let action: TestLMSAction;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
action = new TestLMSAction();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('calculateProgressPercentage', () => {
|
|
61
|
+
it('should calculate percentage correctly', () => {
|
|
62
|
+
expect(action['calculateProgressPercentage'](75, 100)).toBe(75);
|
|
63
|
+
expect(action['calculateProgressPercentage'](1, 3)).toBe(33);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should return 0 when total is 0', () => {
|
|
67
|
+
expect(action['calculateProgressPercentage'](0, 0)).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should return 100 when all completed', () => {
|
|
71
|
+
expect(action['calculateProgressPercentage'](50, 50)).toBe(100);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('formatDuration', () => {
|
|
76
|
+
it('should format seconds only', () => {
|
|
77
|
+
expect(action['formatDuration'](30)).toBe('30s');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should format minutes and seconds', () => {
|
|
81
|
+
expect(action['formatDuration'](90)).toBe('1m 30s');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should format hours, minutes, and seconds', () => {
|
|
85
|
+
expect(action['formatDuration'](3661)).toBe('1h 1m 1s');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('mapEnrollmentStatus', () => {
|
|
90
|
+
it('should map active statuses', () => {
|
|
91
|
+
expect(action['mapEnrollmentStatus']('active')).toBe('active');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should map completed statuses', () => {
|
|
95
|
+
expect(action['mapEnrollmentStatus']('completed')).toBe('completed');
|
|
96
|
+
expect(action['mapEnrollmentStatus']('finished')).toBe('completed');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should map expired statuses', () => {
|
|
100
|
+
expect(action['mapEnrollmentStatus']('expired')).toBe('expired');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should map suspended statuses', () => {
|
|
104
|
+
expect(action['mapEnrollmentStatus']('suspended')).toBe('suspended');
|
|
105
|
+
expect(action['mapEnrollmentStatus']('paused')).toBe('suspended');
|
|
106
|
+
expect(action['mapEnrollmentStatus']('inactive')).toBe('suspended');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should return unknown for unrecognized statuses', () => {
|
|
110
|
+
expect(action['mapEnrollmentStatus']('pending')).toBe('unknown');
|
|
111
|
+
expect(action['mapEnrollmentStatus']('review')).toBe('unknown');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('formatLMSDate', () => {
|
|
116
|
+
it('should format date as ISO string', () => {
|
|
117
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
118
|
+
expect(action['formatLMSDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('parseLMSDate', () => {
|
|
123
|
+
it('should parse ISO date string', () => {
|
|
124
|
+
const result = action['parseLMSDate']('2024-06-15T10:30:00Z');
|
|
125
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('buildLMSErrorMessage', () => {
|
|
130
|
+
it('should build error message without system error', () => {
|
|
131
|
+
expect(action['buildLMSErrorMessage']('GetCourse', 'Not found'))
|
|
132
|
+
.toBe('LMS operation failed: GetCourse. Not found');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should include system error details', () => {
|
|
136
|
+
const result = action['buildLMSErrorMessage']('GetCourse', 'Failed', new Error('timeout'));
|
|
137
|
+
expect(result).toContain('System error: timeout');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('getCommonLMSParams', () => {
|
|
142
|
+
it('should return CompanyID param', () => {
|
|
143
|
+
const params = action['getCommonLMSParams']();
|
|
144
|
+
expect(params).toHaveLength(1);
|
|
145
|
+
expect(params[0].Name).toBe('CompanyID');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('getCredentialFromEnv', () => {
|
|
150
|
+
it('should build correct env key', () => {
|
|
151
|
+
process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'] = 'key123';
|
|
152
|
+
expect(action['getCredentialFromEnv']('COMP1', 'API_KEY')).toBe('key123');
|
|
153
|
+
delete process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'];
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should return undefined for missing env var', () => {
|
|
157
|
+
const result = action['getCredentialFromEnv']('COMP1', 'MISSING_KEY');
|
|
158
|
+
expect(result).toBeUndefined();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('getParamValue', () => {
|
|
163
|
+
it('should find param by name', () => {
|
|
164
|
+
const params = [{ Name: 'CourseID', Value: 'c1', Type: 'Input' as const }];
|
|
165
|
+
expect(action['getParamValue'](params, 'CourseID')).toBe('c1');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should return undefined for missing param', () => {
|
|
169
|
+
expect(action['getParamValue']([], 'Missing')).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('LearnWorldsBaseAction', () => {
|
|
175
|
+
class TestLearnWorldsAction extends LearnWorldsBaseAction {
|
|
176
|
+
protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
|
|
177
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let action: TestLearnWorldsAction;
|
|
182
|
+
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
action = new TestLearnWorldsAction();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('parseLearnWorldsDate', () => {
|
|
188
|
+
it('should parse ISO date string', () => {
|
|
189
|
+
const result = action['parseLearnWorldsDate']('2024-06-15T10:30:00Z');
|
|
190
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should parse unix timestamp (seconds)', () => {
|
|
194
|
+
const result = action['parseLearnWorldsDate'](1718444400);
|
|
195
|
+
expect(result).toBeInstanceOf(Date);
|
|
196
|
+
expect(result.getTime()).toBe(1718444400000);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('formatLearnWorldsDate', () => {
|
|
201
|
+
it('should format date as ISO string', () => {
|
|
202
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
203
|
+
expect(action['formatLearnWorldsDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('mapUserStatus', () => {
|
|
208
|
+
it('should map active status', () => {
|
|
209
|
+
expect(action['mapUserStatus']('active')).toBe('active');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should map inactive status', () => {
|
|
213
|
+
expect(action['mapUserStatus']('inactive')).toBe('inactive');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should map suspended/blocked statuses', () => {
|
|
217
|
+
expect(action['mapUserStatus']('suspended')).toBe('suspended');
|
|
218
|
+
expect(action['mapUserStatus']('blocked')).toBe('suspended');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('should return inactive for unknown statuses', () => {
|
|
222
|
+
expect(action['mapUserStatus']('unknown')).toBe('inactive');
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('mapLearnWorldsEnrollmentStatus', () => {
|
|
227
|
+
it('should return completed when completed is true', () => {
|
|
228
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ completed: true, active: true })).toBe('completed');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should return expired when expired is true', () => {
|
|
232
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ expired: true, active: true })).toBe('expired');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('should return suspended when suspended is true', () => {
|
|
236
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ suspended: true, active: false })).toBe('suspended');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should return suspended when not active', () => {
|
|
240
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: false })).toBe('suspended');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should return active when active and not completed/expired/suspended', () => {
|
|
244
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: true })).toBe('active');
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('calculateProgress', () => {
|
|
249
|
+
it('should extract progress data', () => {
|
|
250
|
+
const result = action['calculateProgress']({
|
|
251
|
+
percentage: 75,
|
|
252
|
+
completed_units: 15,
|
|
253
|
+
total_units: 20,
|
|
254
|
+
time_spent: 3600
|
|
255
|
+
});
|
|
256
|
+
expect(result.percentage).toBe(75);
|
|
257
|
+
expect(result.completedUnits).toBe(15);
|
|
258
|
+
expect(result.totalUnits).toBe(20);
|
|
259
|
+
expect(result.timeSpent).toBe(3600);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should default missing values to 0', () => {
|
|
263
|
+
const result = action['calculateProgress']({});
|
|
264
|
+
expect(result.percentage).toBe(0);
|
|
265
|
+
expect(result.completedUnits).toBe(0);
|
|
266
|
+
expect(result.totalUnits).toBe(0);
|
|
267
|
+
expect(result.timeSpent).toBe(0);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
package/vitest.config.ts
ADDED