@memberjunction/actions-bizapps-lms 5.3.1 → 5.4.1

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 (194) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
  4. package/dist/base/base-lms.action.d.ts +26 -4
  5. package/dist/base/base-lms.action.d.ts.map +1 -1
  6. package/dist/base/base-lms.action.js +73 -17
  7. package/dist/base/base-lms.action.js.map +1 -1
  8. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
  9. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
  10. package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
  11. package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
  12. package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
  13. package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
  14. package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
  15. package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
  16. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
  17. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
  18. package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
  19. package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
  20. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
  21. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
  22. package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
  23. package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
  24. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
  25. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
  26. package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
  27. package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
  28. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
  29. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
  30. package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
  31. package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
  32. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
  33. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
  34. package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
  35. package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
  36. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
  37. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
  38. package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
  39. package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
  40. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
  41. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
  42. package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
  43. package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
  44. package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
  45. package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
  46. package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
  47. package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
  48. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
  49. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
  50. package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
  51. package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
  52. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
  53. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
  54. package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
  55. package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
  56. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
  57. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
  58. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
  59. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
  60. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
  61. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
  62. package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
  63. package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
  64. package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
  65. package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
  66. package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
  67. package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
  68. package/dist/providers/learnworlds/actions/index.d.ts +7 -0
  69. package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
  70. package/dist/providers/learnworlds/actions/index.js +7 -0
  71. package/dist/providers/learnworlds/actions/index.js.map +1 -1
  72. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
  73. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
  74. package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
  75. package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
  76. package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
  77. package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
  78. package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
  79. package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
  80. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
  81. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
  82. package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
  83. package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
  84. package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
  85. package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
  86. package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
  87. package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
  88. package/dist/providers/learnworlds/index.d.ts +1 -0
  89. package/dist/providers/learnworlds/index.d.ts.map +1 -1
  90. package/dist/providers/learnworlds/index.js +2 -0
  91. package/dist/providers/learnworlds/index.js.map +1 -1
  92. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
  93. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
  94. package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
  95. package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
  96. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
  97. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
  98. package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
  99. package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
  100. package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
  101. package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
  102. package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
  103. package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
  104. package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
  105. package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
  106. package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
  107. package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
  108. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
  109. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
  110. package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
  111. package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
  112. package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
  113. package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
  114. package/dist/providers/learnworlds/interfaces/index.js +13 -0
  115. package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
  116. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
  117. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
  118. package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
  119. package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
  120. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
  121. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
  122. package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
  123. package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
  124. package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
  125. package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
  126. package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
  127. package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
  128. package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
  129. package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
  130. package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
  131. package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
  132. package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
  133. package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
  134. package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
  135. package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
  136. package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
  137. package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
  138. package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
  139. package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
  140. package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
  141. package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
  142. package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
  143. package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
  144. package/package.json +8 -7
  145. package/src/__tests__/attach-tags.action.test.ts +137 -0
  146. package/src/__tests__/create-user.action.test.ts +311 -0
  147. package/src/__tests__/detach-tags.action.test.ts +136 -0
  148. package/src/__tests__/enroll-user.action.test.ts +283 -0
  149. package/src/__tests__/get-bulk-data.action.test.ts +649 -0
  150. package/src/__tests__/get-bundles.action.test.ts +215 -0
  151. package/src/__tests__/lms.test.ts +275 -184
  152. package/src/__tests__/onboard-learner.action.test.ts +455 -0
  153. package/src/__tests__/sso-login.action.test.ts +256 -0
  154. package/src/__tests__/update-user.action.test.ts +350 -0
  155. package/src/base/base-lms.action.ts +226 -163
  156. package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
  157. package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
  158. package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
  159. package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
  160. package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
  161. package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
  162. package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
  163. package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
  164. package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
  165. package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
  166. package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
  167. package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
  168. package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
  169. package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
  170. package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
  171. package/src/providers/learnworlds/actions/index.ts +8 -1
  172. package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
  173. package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
  174. package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
  175. package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
  176. package/src/providers/learnworlds/index.ts +4 -1
  177. package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
  178. package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
  179. package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
  180. package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
  181. package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
  182. package/src/providers/learnworlds/interfaces/index.ts +12 -0
  183. package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
  184. package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
  185. package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
  186. package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
  187. package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
  188. package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
  189. package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
  190. package/tsconfig.json +1 -1
  191. package/dist/__tests__/lms.test.d.ts +0 -2
  192. package/dist/__tests__/lms.test.d.ts.map +0 -1
  193. package/dist/__tests__/lms.test.js +0 -232
  194. 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
- BaseAction: class BaseAction {
6
- protected async InternalRunAction(): Promise<unknown> { return {}; }
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
- RegisterClass: () => (target: unknown) => target
13
+ RegisterClass: () => (target: unknown) => target,
12
14
  }));
13
15
 
14
16
  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
- }))
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
- MJCompanyIntegrationEntity: class MJCompanyIntegrationEntity {
24
- CompanyID: string = '';
25
- APIKey: string | null = null;
26
- AccessToken: string | null = null;
27
- ExternalSystemID: string | null = null;
28
- CustomAttribute1: string | null = null;
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
- ActionParam: class ActionParam {
34
- Name: string = '';
35
- Value: unknown = null;
36
- Type: string = 'Input';
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
- protected lmsProvider = 'TestLMS';
46
- protected integrationName = 'TestLMS';
47
+ protected lmsProvider = 'TestLMS';
48
+ protected integrationName = 'TestLMS';
47
49
 
48
- protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
49
- return { Success: true, ResultCode: 'SUCCESS' };
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
- let action: TestLMSAction;
56
+ let action: TestLMSAction;
57
+
58
+ beforeEach(() => {
59
+ action = new TestLMSAction();
60
+ });
55
61
 
56
- beforeEach(() => {
57
- action = new TestLMSAction();
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
- 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
- });
68
+ it('should return 0 when total is 0', () => {
69
+ expect(action['calculateProgressPercentage'](0, 0)).toBe(0);
70
+ });
65
71
 
66
- it('should return 0 when total is 0', () => {
67
- expect(action['calculateProgressPercentage'](0, 0)).toBe(0);
68
- });
72
+ it('should return 100 when all completed', () => {
73
+ expect(action['calculateProgressPercentage'](50, 50)).toBe(100);
74
+ });
75
+ });
69
76
 
70
- it('should return 100 when all completed', () => {
71
- expect(action['calculateProgressPercentage'](50, 50)).toBe(100);
72
- });
77
+ describe('formatDuration', () => {
78
+ it('should format seconds only', () => {
79
+ expect(action['formatDuration'](30)).toBe('30s');
73
80
  });
74
81
 
75
- describe('formatDuration', () => {
76
- it('should format seconds only', () => {
77
- expect(action['formatDuration'](30)).toBe('30s');
78
- });
82
+ it('should format minutes and seconds', () => {
83
+ expect(action['formatDuration'](90)).toBe('1m 30s');
84
+ });
79
85
 
80
- it('should format minutes and seconds', () => {
81
- expect(action['formatDuration'](90)).toBe('1m 30s');
82
- });
86
+ it('should format hours, minutes, and seconds', () => {
87
+ expect(action['formatDuration'](3661)).toBe('1h 1m 1s');
88
+ });
89
+ });
83
90
 
84
- it('should format hours, minutes, and seconds', () => {
85
- expect(action['formatDuration'](3661)).toBe('1h 1m 1s');
86
- });
91
+ describe('mapEnrollmentStatus', () => {
92
+ it('should map active statuses', () => {
93
+ expect(action['mapEnrollmentStatus']('active')).toBe('active');
87
94
  });
88
95
 
89
- describe('mapEnrollmentStatus', () => {
90
- it('should map active statuses', () => {
91
- expect(action['mapEnrollmentStatus']('active')).toBe('active');
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
- it('should map completed statuses', () => {
95
- expect(action['mapEnrollmentStatus']('completed')).toBe('completed');
96
- expect(action['mapEnrollmentStatus']('finished')).toBe('completed');
97
- });
101
+ it('should map expired statuses', () => {
102
+ expect(action['mapEnrollmentStatus']('expired')).toBe('expired');
103
+ });
98
104
 
99
- it('should map expired statuses', () => {
100
- expect(action['mapEnrollmentStatus']('expired')).toBe('expired');
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
- 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
- });
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
- it('should return unknown for unrecognized statuses', () => {
110
- expect(action['mapEnrollmentStatus']('pending')).toBe('unknown');
111
- expect(action['mapEnrollmentStatus']('review')).toBe('unknown');
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
- 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
- });
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
- 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
- });
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
- 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
- });
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
- it('should include system error details', () => {
136
- const result = action['buildLMSErrorMessage']('GetCourse', 'Failed', new Error('timeout'));
137
- expect(result).toContain('System error: timeout');
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
- 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
- });
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
- 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
- });
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
- it('should return undefined for missing env var', () => {
157
- const result = action['getCredentialFromEnv']('COMP1', 'MISSING_KEY');
158
- expect(result).toBeUndefined();
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
- 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
- });
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
- it('should return undefined for missing param', () => {
169
- expect(action['getParamValue']([], 'Missing')).toBeUndefined();
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
- class TestLearnWorldsAction extends LearnWorldsBaseAction {
176
- protected async InternalRunAction(): Promise<{ Success: boolean; ResultCode: string }> {
177
- return { Success: true, ResultCode: 'SUCCESS' };
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
- let action: TestLearnWorldsAction;
220
+ beforeEach(() => {
221
+ action = new TestLearnWorldsAction();
222
+ });
182
223
 
183
- beforeEach(() => {
184
- action = new TestLearnWorldsAction();
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
- 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
- });
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
- it('should parse unix timestamp (seconds)', () => {
194
- const result = action['parseLearnWorldsDate'](1718444400);
195
- expect(result).toBeInstanceOf(Date);
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
- 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
- });
258
+ it('should return inactive for unknown statuses', () => {
259
+ expect(action['mapUserStatus']('unknown')).toBe('inactive');
205
260
  });
261
+ });
206
262
 
207
- describe('mapUserStatus', () => {
208
- it('should map active status', () => {
209
- expect(action['mapUserStatus']('active')).toBe('active');
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
- it('should map inactive status', () => {
213
- expect(action['mapUserStatus']('inactive')).toBe('inactive');
214
- });
268
+ it('should return expired when expired is true', () => {
269
+ expect(action['mapLearnWorldsEnrollmentStatus']({ expired: true, active: true })).toBe('expired');
270
+ });
215
271
 
216
- it('should map suspended/blocked statuses', () => {
217
- expect(action['mapUserStatus']('suspended')).toBe('suspended');
218
- expect(action['mapUserStatus']('blocked')).toBe('suspended');
219
- });
272
+ it('should return suspended when suspended is true', () => {
273
+ expect(action['mapLearnWorldsEnrollmentStatus']({ suspended: true, active: false })).toBe('suspended');
274
+ });
220
275
 
221
- it('should return inactive for unknown statuses', () => {
222
- expect(action['mapUserStatus']('unknown')).toBe('inactive');
223
- });
276
+ it('should return suspended when not active', () => {
277
+ expect(action['mapLearnWorldsEnrollmentStatus']({ active: false })).toBe('suspended');
224
278
  });
225
279
 
226
- describe('mapLearnWorldsEnrollmentStatus', () => {
227
- it('should return completed when completed is true', () => {
228
- expect(action['mapLearnWorldsEnrollmentStatus']({ completed: true, active: true })).toBe('completed');
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
- it('should return expired when expired is true', () => {
232
- expect(action['mapLearnWorldsEnrollmentStatus']({ expired: true, active: true })).toBe('expired');
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
- it('should return suspended when suspended is true', () => {
236
- expect(action['mapLearnWorldsEnrollmentStatus']({ suspended: true, active: false })).toBe('suspended');
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
- it('should return suspended when not active', () => {
240
- expect(action['mapLearnWorldsEnrollmentStatus']({ active: false })).toBe('suspended');
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
- it('should return active when active and not completed/expired/suspended', () => {
244
- expect(action['mapLearnWorldsEnrollmentStatus']({ active: true })).toBe('active');
245
- });
349
+ expect(result).toBeNull();
246
350
  });
247
351
 
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
- });
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
- 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
- });
358
+ await expect(action.FindUserByEmail('test@example.com', mockCtx as never)).rejects.toThrow('API error');
269
359
  });
360
+ });
270
361
  });