@memberjunction/actions-bizapps-lms 5.3.1 → 5.4.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 +16 -0
- package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
- package/dist/base/base-lms.action.d.ts +26 -4
- package/dist/base/base-lms.action.d.ts.map +1 -1
- package/dist/base/base-lms.action.js +73 -17
- package/dist/base/base-lms.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/index.d.ts +7 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +7 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
- package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
- package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +1 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/index.js +2 -0
- package/dist/providers/learnworlds/index.js.map +1 -1
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.js +13 -0
- package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/attach-tags.action.test.ts +137 -0
- package/src/__tests__/create-user.action.test.ts +311 -0
- package/src/__tests__/detach-tags.action.test.ts +136 -0
- package/src/__tests__/enroll-user.action.test.ts +283 -0
- package/src/__tests__/get-bulk-data.action.test.ts +649 -0
- package/src/__tests__/get-bundles.action.test.ts +215 -0
- package/src/__tests__/lms.test.ts +275 -184
- package/src/__tests__/onboard-learner.action.test.ts +455 -0
- package/src/__tests__/sso-login.action.test.ts +256 -0
- package/src/__tests__/update-user.action.test.ts +350 -0
- package/src/base/base-lms.action.ts +226 -163
- package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
- package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
- package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
- package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
- package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
- package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
- package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
- package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
- package/src/providers/learnworlds/actions/index.ts +8 -1
- package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
- package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
- package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
- package/src/providers/learnworlds/index.ts +4 -1
- package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
- package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
- package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
- package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
- package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
- package/src/providers/learnworlds/interfaces/index.ts +12 -0
- package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
- package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
- package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
- package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
- package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
- package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
- package/tsconfig.json +1 -1
- package/dist/__tests__/lms.test.d.ts +0 -2
- package/dist/__tests__/lms.test.d.ts.map +0 -1
- package/dist/__tests__/lms.test.js +0 -232
- package/dist/__tests__/lms.test.js.map +0 -1
|
@@ -2,39 +2,41 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
// Mock dependencies
|
|
4
4
|
vi.mock('@memberjunction/actions', () => ({
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
BaseAction: class BaseAction {
|
|
6
|
+
protected async InternalRunAction(): Promise<unknown> {
|
|
7
|
+
return {};
|
|
7
8
|
}
|
|
9
|
+
},
|
|
8
10
|
}));
|
|
9
11
|
|
|
10
12
|
vi.mock('@memberjunction/global', () => ({
|
|
11
|
-
|
|
13
|
+
RegisterClass: () => (target: unknown) => target,
|
|
12
14
|
}));
|
|
13
15
|
|
|
14
16
|
vi.mock('@memberjunction/core', () => ({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
UserInfo: class UserInfo {},
|
|
18
|
+
Metadata: vi.fn(),
|
|
19
|
+
RunView: vi.fn().mockImplementation(() => ({
|
|
20
|
+
RunView: vi.fn().mockResolvedValue({ Success: true, Results: [] }),
|
|
21
|
+
})),
|
|
20
22
|
}));
|
|
21
23
|
|
|
22
24
|
vi.mock('@memberjunction/core-entities', () => ({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
MJCompanyIntegrationEntity: class MJCompanyIntegrationEntity {
|
|
26
|
+
CompanyID: string = '';
|
|
27
|
+
APIKey: string | null = null;
|
|
28
|
+
AccessToken: string | null = null;
|
|
29
|
+
ExternalSystemID: string | null = null;
|
|
30
|
+
CustomAttribute1: string | null = null;
|
|
31
|
+
},
|
|
30
32
|
}));
|
|
31
33
|
|
|
32
34
|
vi.mock('@memberjunction/actions-base', () => ({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
ActionParam: class ActionParam {
|
|
36
|
+
Name: string = '';
|
|
37
|
+
Value: unknown = null;
|
|
38
|
+
Type: string = 'Input';
|
|
39
|
+
},
|
|
38
40
|
}));
|
|
39
41
|
|
|
40
42
|
import { BaseLMSAction } from '../base/base-lms.action';
|
|
@@ -42,229 +44,318 @@ import { LearnWorldsBaseAction } from '../providers/learnworlds/learnworlds-base
|
|
|
42
44
|
|
|
43
45
|
// Concrete subclass for testing BaseLMSAction
|
|
44
46
|
class TestLMSAction extends BaseLMSAction {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
protected lmsProvider = 'TestLMS';
|
|
48
|
+
protected integrationName = 'TestLMS';
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
|
|
51
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
describe('BaseLMSAction', () => {
|
|
54
|
-
|
|
56
|
+
let action: TestLMSAction;
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
action = new TestLMSAction();
|
|
60
|
+
});
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
describe('calculateProgressPercentage', () => {
|
|
63
|
+
it('should calculate percentage correctly', () => {
|
|
64
|
+
expect(action['calculateProgressPercentage'](75, 100)).toBe(75);
|
|
65
|
+
expect(action['calculateProgressPercentage'](1, 3)).toBe(33);
|
|
58
66
|
});
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
expect(action['calculateProgressPercentage'](1, 3)).toBe(33);
|
|
64
|
-
});
|
|
68
|
+
it('should return 0 when total is 0', () => {
|
|
69
|
+
expect(action['calculateProgressPercentage'](0, 0)).toBe(0);
|
|
70
|
+
});
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
it('should return 100 when all completed', () => {
|
|
73
|
+
expect(action['calculateProgressPercentage'](50, 50)).toBe(100);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
describe('formatDuration', () => {
|
|
78
|
+
it('should format seconds only', () => {
|
|
79
|
+
expect(action['formatDuration'](30)).toBe('30s');
|
|
73
80
|
});
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
82
|
+
it('should format minutes and seconds', () => {
|
|
83
|
+
expect(action['formatDuration'](90)).toBe('1m 30s');
|
|
84
|
+
});
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
it('should format hours, minutes, and seconds', () => {
|
|
87
|
+
expect(action['formatDuration'](3661)).toBe('1h 1m 1s');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
describe('mapEnrollmentStatus', () => {
|
|
92
|
+
it('should map active statuses', () => {
|
|
93
|
+
expect(action['mapEnrollmentStatus']('active')).toBe('active');
|
|
87
94
|
});
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
it('should map completed statuses', () => {
|
|
97
|
+
expect(action['mapEnrollmentStatus']('completed')).toBe('completed');
|
|
98
|
+
expect(action['mapEnrollmentStatus']('finished')).toBe('completed');
|
|
99
|
+
});
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
101
|
+
it('should map expired statuses', () => {
|
|
102
|
+
expect(action['mapEnrollmentStatus']('expired')).toBe('expired');
|
|
103
|
+
});
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
it('should map suspended statuses', () => {
|
|
106
|
+
expect(action['mapEnrollmentStatus']('suspended')).toBe('suspended');
|
|
107
|
+
expect(action['mapEnrollmentStatus']('paused')).toBe('suspended');
|
|
108
|
+
expect(action['mapEnrollmentStatus']('inactive')).toBe('suspended');
|
|
109
|
+
});
|
|
102
110
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
it('should return unknown for unrecognized statuses', () => {
|
|
112
|
+
expect(action['mapEnrollmentStatus']('pending')).toBe('unknown');
|
|
113
|
+
expect(action['mapEnrollmentStatus']('review')).toBe('unknown');
|
|
114
|
+
});
|
|
115
|
+
});
|
|
108
116
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
describe('formatLMSDate', () => {
|
|
118
|
+
it('should format date as ISO string', () => {
|
|
119
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
120
|
+
expect(action['formatLMSDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
113
121
|
});
|
|
122
|
+
});
|
|
114
123
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
124
|
+
describe('parseLMSDate', () => {
|
|
125
|
+
it('should parse ISO date string', () => {
|
|
126
|
+
const result = action['parseLMSDate']('2024-06-15T10:30:00Z');
|
|
127
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
120
128
|
});
|
|
129
|
+
});
|
|
121
130
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
126
|
-
});
|
|
131
|
+
describe('buildLMSErrorMessage', () => {
|
|
132
|
+
it('should build error message without system error', () => {
|
|
133
|
+
expect(action['buildLMSErrorMessage']('GetCourse', 'Not found')).toBe('LMS operation failed: GetCourse. Not found');
|
|
127
134
|
});
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
it('should include system error details', () => {
|
|
137
|
+
const result = action['buildLMSErrorMessage']('GetCourse', 'Failed', new Error('timeout'));
|
|
138
|
+
expect(result).toContain('System error: timeout');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
134
141
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
describe('getCommonLMSParams', () => {
|
|
143
|
+
it('should return CompanyID param', () => {
|
|
144
|
+
const params = action['getCommonLMSParams']();
|
|
145
|
+
expect(params).toHaveLength(1);
|
|
146
|
+
expect(params[0].Name).toBe('CompanyID');
|
|
139
147
|
});
|
|
148
|
+
});
|
|
140
149
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
150
|
+
describe('getCredentialFromEnv', () => {
|
|
151
|
+
it('should build correct env key', () => {
|
|
152
|
+
process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'] = 'key123';
|
|
153
|
+
expect(action['getCredentialFromEnv']('COMP1', 'API_KEY')).toBe('key123');
|
|
154
|
+
delete process.env['BIZAPPS_TESTLMS_COMP1_API_KEY'];
|
|
147
155
|
});
|
|
148
156
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
157
|
+
it('should return undefined for missing env var', () => {
|
|
158
|
+
const result = action['getCredentialFromEnv']('COMP1', 'MISSING_KEY');
|
|
159
|
+
expect(result).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
155
162
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
describe('getParamValue', () => {
|
|
164
|
+
it('should find param by name', () => {
|
|
165
|
+
const params = [{ Name: 'CourseID', Value: 'c1', Type: 'Input' as const }];
|
|
166
|
+
expect(action['getParamValue'](params, 'CourseID')).toBe('c1');
|
|
160
167
|
});
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
it('should return undefined for missing param', () => {
|
|
170
|
+
expect(action['getParamValue']([], 'Missing')).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('setOutputParam', () => {
|
|
175
|
+
it('should create param if it does not exist', () => {
|
|
176
|
+
const params: { Name: string; Type: string; Value: unknown }[] = [];
|
|
177
|
+
action['setOutputParam'](params, 'Result', 42);
|
|
178
|
+
expect(params).toHaveLength(1);
|
|
179
|
+
expect(params[0].Name).toBe('Result');
|
|
180
|
+
expect(params[0].Value).toBe(42);
|
|
181
|
+
expect(params[0].Type).toBe('Output');
|
|
182
|
+
});
|
|
167
183
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
184
|
+
it('should update existing param value', () => {
|
|
185
|
+
const params = [{ Name: 'Result', Type: 'Output', Value: 'old' }];
|
|
186
|
+
action['setOutputParam'](params, 'Result', 'new');
|
|
187
|
+
expect(params).toHaveLength(1);
|
|
188
|
+
expect(params[0].Value).toBe('new');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('buildSuccessResult', () => {
|
|
193
|
+
it('should return a success ActionResultSimple', () => {
|
|
194
|
+
const result = action['buildSuccessResult']('All good');
|
|
195
|
+
expect(result.Success).toBe(true);
|
|
196
|
+
expect(result.ResultCode).toBe('SUCCESS');
|
|
197
|
+
expect(result.Message).toBe('All good');
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('buildErrorResult', () => {
|
|
202
|
+
it('should return an error ActionResultSimple', () => {
|
|
203
|
+
const result = action['buildErrorResult']('FAIL', 'Bad things');
|
|
204
|
+
expect(result.Success).toBe(false);
|
|
205
|
+
expect(result.ResultCode).toBe('FAIL');
|
|
206
|
+
expect(result.Message).toBe('Bad things');
|
|
171
207
|
});
|
|
208
|
+
});
|
|
172
209
|
});
|
|
173
210
|
|
|
174
211
|
describe('LearnWorldsBaseAction', () => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
212
|
+
class TestLearnWorldsAction extends LearnWorldsBaseAction {
|
|
213
|
+
protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
|
|
214
|
+
return { Success: true, ResultCode: 'SUCCESS' };
|
|
179
215
|
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let action: TestLearnWorldsAction;
|
|
180
219
|
|
|
181
|
-
|
|
220
|
+
beforeEach(() => {
|
|
221
|
+
action = new TestLearnWorldsAction();
|
|
222
|
+
});
|
|
182
223
|
|
|
183
|
-
|
|
184
|
-
|
|
224
|
+
describe('parseLearnWorldsDate', () => {
|
|
225
|
+
it('should parse ISO date string', () => {
|
|
226
|
+
const result = action['parseLearnWorldsDate']('2024-06-15T10:30:00Z');
|
|
227
|
+
expect(result.toISOString()).toBe('2024-06-15T10:30:00.000Z');
|
|
185
228
|
});
|
|
186
229
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
230
|
+
it('should parse unix timestamp (seconds)', () => {
|
|
231
|
+
const result = action['parseLearnWorldsDate'](1718444400);
|
|
232
|
+
expect(result).toBeInstanceOf(Date);
|
|
233
|
+
expect(result.getTime()).toBe(1718444400000);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('formatLearnWorldsDate', () => {
|
|
238
|
+
it('should format date as ISO string', () => {
|
|
239
|
+
const date = new Date('2024-06-15T10:30:00Z');
|
|
240
|
+
expect(action['formatLearnWorldsDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('mapUserStatus', () => {
|
|
245
|
+
it('should map active status', () => {
|
|
246
|
+
expect(action['mapUserStatus']('active')).toBe('active');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('should map inactive status', () => {
|
|
250
|
+
expect(action['mapUserStatus']('inactive')).toBe('inactive');
|
|
251
|
+
});
|
|
192
252
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
expect(result.getTime()).toBe(1718444400000);
|
|
197
|
-
});
|
|
253
|
+
it('should map suspended/blocked statuses', () => {
|
|
254
|
+
expect(action['mapUserStatus']('suspended')).toBe('suspended');
|
|
255
|
+
expect(action['mapUserStatus']('blocked')).toBe('suspended');
|
|
198
256
|
});
|
|
199
257
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const date = new Date('2024-06-15T10:30:00Z');
|
|
203
|
-
expect(action['formatLearnWorldsDate'](date)).toBe('2024-06-15T10:30:00.000Z');
|
|
204
|
-
});
|
|
258
|
+
it('should return inactive for unknown statuses', () => {
|
|
259
|
+
expect(action['mapUserStatus']('unknown')).toBe('inactive');
|
|
205
260
|
});
|
|
261
|
+
});
|
|
206
262
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
263
|
+
describe('mapLearnWorldsEnrollmentStatus', () => {
|
|
264
|
+
it('should return completed when completed is true', () => {
|
|
265
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ completed: true, active: true })).toBe('completed');
|
|
266
|
+
});
|
|
211
267
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
268
|
+
it('should return expired when expired is true', () => {
|
|
269
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ expired: true, active: true })).toBe('expired');
|
|
270
|
+
});
|
|
215
271
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
272
|
+
it('should return suspended when suspended is true', () => {
|
|
273
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ suspended: true, active: false })).toBe('suspended');
|
|
274
|
+
});
|
|
220
275
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
});
|
|
276
|
+
it('should return suspended when not active', () => {
|
|
277
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: false })).toBe('suspended');
|
|
224
278
|
});
|
|
225
279
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
280
|
+
it('should return active when active and not completed/expired/suspended', () => {
|
|
281
|
+
expect(action['mapLearnWorldsEnrollmentStatus']({ active: true })).toBe('active');
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('calculateProgress', () => {
|
|
286
|
+
it('should extract progress data', () => {
|
|
287
|
+
const result = action['calculateProgress']({
|
|
288
|
+
percentage: 75,
|
|
289
|
+
completed_units: 15,
|
|
290
|
+
total_units: 20,
|
|
291
|
+
time_spent: 3600,
|
|
292
|
+
});
|
|
293
|
+
expect(result.percentage).toBe(75);
|
|
294
|
+
expect(result.completedUnits).toBe(15);
|
|
295
|
+
expect(result.totalUnits).toBe(20);
|
|
296
|
+
expect(result.timeSpent).toBe(3600);
|
|
297
|
+
});
|
|
230
298
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
299
|
+
it('should default missing values to 0', () => {
|
|
300
|
+
const result = action['calculateProgress']({});
|
|
301
|
+
expect(result.percentage).toBe(0);
|
|
302
|
+
expect(result.completedUnits).toBe(0);
|
|
303
|
+
expect(result.totalUnits).toBe(0);
|
|
304
|
+
expect(result.timeSpent).toBe(0);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('SetCompanyContext', () => {
|
|
309
|
+
it('should set params with CompanyID', () => {
|
|
310
|
+
action.SetCompanyContext('comp-123');
|
|
311
|
+
expect(action['params']).toHaveLength(1);
|
|
312
|
+
expect(action['params'][0].Name).toBe('CompanyID');
|
|
313
|
+
expect(action['params'][0].Value).toBe('comp-123');
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('FindUserByEmail', () => {
|
|
318
|
+
it('should return user when found', async () => {
|
|
319
|
+
const mockUser = {
|
|
320
|
+
id: 'u1',
|
|
321
|
+
email: 'test@example.com',
|
|
322
|
+
username: 'testuser',
|
|
323
|
+
first_name: 'Test',
|
|
324
|
+
last_name: 'User',
|
|
325
|
+
status: 'active',
|
|
326
|
+
role: 'student',
|
|
327
|
+
created: '2024-01-01T00:00:00Z',
|
|
328
|
+
tags: ['tag1'],
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
action.SetCompanyContext('comp-123');
|
|
332
|
+
vi.spyOn(action as never, 'makeLearnWorldsPaginatedRequest').mockResolvedValue([mockUser] as never);
|
|
333
|
+
|
|
334
|
+
const mockCtx = { ID: 'ctx-user' } as unknown as (typeof import('@memberjunction/core'))['UserInfo'];
|
|
335
|
+
const result = await action.FindUserByEmail('test@example.com', mockCtx as never);
|
|
336
|
+
|
|
337
|
+
expect(result).not.toBeNull();
|
|
338
|
+
expect(result!.id).toBe('u1');
|
|
339
|
+
expect(result!.email).toBe('test@example.com');
|
|
340
|
+
});
|
|
234
341
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
342
|
+
it('should return null when not found', async () => {
|
|
343
|
+
action.SetCompanyContext('comp-123');
|
|
344
|
+
vi.spyOn(action as never, 'makeLearnWorldsPaginatedRequest').mockResolvedValue([] as never);
|
|
238
345
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
});
|
|
346
|
+
const mockCtx = { ID: 'ctx-user' } as unknown as (typeof import('@memberjunction/core'))['UserInfo'];
|
|
347
|
+
const result = await action.FindUserByEmail('nobody@example.com', mockCtx as never);
|
|
242
348
|
|
|
243
|
-
|
|
244
|
-
expect(action['mapLearnWorldsEnrollmentStatus']({ active: true })).toBe('active');
|
|
245
|
-
});
|
|
349
|
+
expect(result).toBeNull();
|
|
246
350
|
});
|
|
247
351
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
});
|
|
352
|
+
it('should re-throw on API error', async () => {
|
|
353
|
+
action.SetCompanyContext('comp-123');
|
|
354
|
+
vi.spyOn(action as never, 'makeLearnWorldsPaginatedRequest').mockRejectedValue(new Error('API error') as never);
|
|
355
|
+
|
|
356
|
+
const mockCtx = { ID: 'ctx-user' } as unknown as (typeof import('@memberjunction/core'))['UserInfo'];
|
|
261
357
|
|
|
262
|
-
|
|
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
|
-
});
|
|
358
|
+
await expect(action.FindUserByEmail('test@example.com', mockCtx as never)).rejects.toThrow('API error');
|
|
269
359
|
});
|
|
360
|
+
});
|
|
270
361
|
});
|