@memberjunction/actions-bizapps-lms 5.23.0 → 5.25.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/.env.integration.example +4 -0
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +28 -0
- package/dist/base/base-lms.action.d.ts +5 -0
- package/dist/base/base-lms.action.d.ts.map +1 -1
- package/dist/base/base-lms.action.js +11 -4
- package/dist/base/base-lms.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.js +3 -0
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.js +6 -6
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +5 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.js +73 -48
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +3 -3
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.js +23 -23
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +4 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +48 -37
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +3 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.js +21 -15
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/onboard-learner.action.js +4 -4
- package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +2 -2
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +44 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.js +107 -2
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/get-certificates.action.test.ts +467 -0
- package/src/__tests__/get-course-analytics.action.test.ts +340 -0
- package/src/__tests__/get-course-details.action.test.ts +510 -0
- package/src/__tests__/get-courses.action.test.ts +1191 -0
- package/src/__tests__/get-quiz-results.action.test.ts +575 -0
- package/src/__tests__/get-user-details.action.test.ts +533 -0
- package/src/__tests__/get-user-enrollments.action.test.ts +387 -0
- package/src/__tests__/get-user-progress.action.test.ts +588 -0
- package/src/__tests__/get-users.action.test.ts +464 -0
- package/src/__tests__/integration.test.ts +252 -3
- package/src/__tests__/rate-limit-retry.test.ts +296 -0
- package/src/__tests__/update-user-progress.action.test.ts +312 -0
- package/src/base/base-lms.action.ts +12 -4
- package/src/providers/learnworlds/actions/create-user.action.ts +4 -0
- package/src/providers/learnworlds/actions/get-course-details.action.ts +6 -6
- package/src/providers/learnworlds/actions/get-courses.action.ts +78 -58
- package/src/providers/learnworlds/actions/get-user-details.action.ts +32 -25
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +54 -41
- package/src/providers/learnworlds/actions/get-users.action.ts +24 -16
- package/src/providers/learnworlds/actions/onboard-learner.action.ts +4 -4
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +2 -2
- package/src/providers/learnworlds/learnworlds-base.action.ts +128 -2
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock dependencies (same pattern as get-bundles.action.test.ts)
|
|
4
|
+
vi.mock('@memberjunction/actions', () => ({
|
|
5
|
+
BaseAction: class BaseAction {
|
|
6
|
+
protected async InternalRunAction(): Promise<unknown> {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock('@memberjunction/global', () => ({
|
|
13
|
+
RegisterClass: () => (target: unknown) => target,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock('@memberjunction/core', () => ({
|
|
17
|
+
UserInfo: class UserInfo {},
|
|
18
|
+
Metadata: vi.fn(),
|
|
19
|
+
RunView: vi.fn().mockImplementation(() => ({
|
|
20
|
+
RunView: vi.fn().mockResolvedValue({ Success: true, Results: [] }),
|
|
21
|
+
})),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
vi.mock('@memberjunction/core-entities', () => ({
|
|
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
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
vi.mock('@memberjunction/actions-base', () => ({
|
|
35
|
+
ActionParam: class ActionParam {
|
|
36
|
+
Name: string = '';
|
|
37
|
+
Value: unknown = null;
|
|
38
|
+
Type: string = 'Input';
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
import { UserInfo } from '@memberjunction/core';
|
|
43
|
+
import { GetLearnWorldsCourseDetailsAction } from '../providers/learnworlds/actions/get-course-details.action';
|
|
44
|
+
import { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Helper to create a mock UserInfo for test context
|
|
48
|
+
*/
|
|
49
|
+
function createMockContextUser(): UserInfo {
|
|
50
|
+
return { ID: 'test-user-id', Name: 'Test User', Email: 'test@example.com' } as unknown as UserInfo;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates a raw LW course API response
|
|
55
|
+
*/
|
|
56
|
+
function createRawCourseData(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
|
57
|
+
return {
|
|
58
|
+
id: 'course-1',
|
|
59
|
+
title: 'Intro to TypeScript',
|
|
60
|
+
slug: 'intro-typescript',
|
|
61
|
+
description: 'A comprehensive course on TypeScript',
|
|
62
|
+
short_description: 'Learn TS basics',
|
|
63
|
+
access: 'published',
|
|
64
|
+
original_price: 99.99,
|
|
65
|
+
final_price: 79.99,
|
|
66
|
+
currency: 'USD',
|
|
67
|
+
level: 'beginner',
|
|
68
|
+
language: 'en',
|
|
69
|
+
duration: 3600,
|
|
70
|
+
total_enrollments: 250,
|
|
71
|
+
average_rating: 4.5,
|
|
72
|
+
total_ratings: 80,
|
|
73
|
+
tags: ['typescript', 'programming'],
|
|
74
|
+
categories: ['Development'],
|
|
75
|
+
courseImage: 'https://example.com/img.jpg',
|
|
76
|
+
certificate_enabled: true,
|
|
77
|
+
created: 1700000000,
|
|
78
|
+
modified: 1700100000,
|
|
79
|
+
...overrides,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates a raw LW sections/modules API response
|
|
85
|
+
*/
|
|
86
|
+
function createRawSectionsResponse(): Record<string, unknown> {
|
|
87
|
+
return {
|
|
88
|
+
data: [
|
|
89
|
+
{
|
|
90
|
+
id: 'mod-1',
|
|
91
|
+
title: 'Getting Started',
|
|
92
|
+
description: 'Introduction module',
|
|
93
|
+
order: 1,
|
|
94
|
+
duration: 1200,
|
|
95
|
+
total_lessons: 3,
|
|
96
|
+
lessons: [
|
|
97
|
+
{ id: 'les-1', title: 'Welcome', type: 'video', duration: 300, order: 1, is_free: true, has_video: true, has_quiz: false, has_assignment: false },
|
|
98
|
+
{ id: 'les-2', title: 'Setup', type: 'text', duration: 600, order: 2, is_free: false, has_video: false, has_quiz: false, has_assignment: false },
|
|
99
|
+
{ id: 'les-3', title: 'Quiz 1', type: 'quiz', duration: 300, order: 3, is_free: false, has_video: false, has_quiz: true, has_assignment: false },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'mod-2',
|
|
104
|
+
title: 'Advanced Topics',
|
|
105
|
+
description: 'Deep dive',
|
|
106
|
+
order: 2,
|
|
107
|
+
duration: 1800,
|
|
108
|
+
total_lessons: 2,
|
|
109
|
+
lessons: [
|
|
110
|
+
{ id: 'les-4', title: 'Generics', type: 'video', duration: 900, order: 1, is_free: false, has_video: true, has_quiz: false, has_assignment: false },
|
|
111
|
+
{ id: 'les-5', title: 'Assignment 1', type: 'assignment', duration: 900, order: 2, is_free: false, has_video: false, has_quiz: false, has_assignment: true },
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a raw LW instructors API response
|
|
120
|
+
*/
|
|
121
|
+
function createRawInstructorsResponse(): Record<string, unknown> {
|
|
122
|
+
return {
|
|
123
|
+
data: [
|
|
124
|
+
{
|
|
125
|
+
id: 'instr-1',
|
|
126
|
+
name: 'Jane Doe',
|
|
127
|
+
email: 'jane@example.com',
|
|
128
|
+
bio: 'Expert in TypeScript',
|
|
129
|
+
title: 'Senior Instructor',
|
|
130
|
+
image_url: 'https://example.com/jane.jpg',
|
|
131
|
+
total_courses: 5,
|
|
132
|
+
total_students: 1000,
|
|
133
|
+
average_rating: 4.8,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates a raw LW stats API response
|
|
141
|
+
*/
|
|
142
|
+
function createRawStatsResponse(): Record<string, unknown> {
|
|
143
|
+
return {
|
|
144
|
+
success: true,
|
|
145
|
+
data: {
|
|
146
|
+
total_enrollments: 300,
|
|
147
|
+
active_students: 120,
|
|
148
|
+
completion_rate: 55,
|
|
149
|
+
average_progress: 70,
|
|
150
|
+
average_time_to_complete: 7200,
|
|
151
|
+
total_revenue: 15000,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
describe('GetLearnWorldsCourseDetailsAction', () => {
|
|
157
|
+
let action: GetLearnWorldsCourseDetailsAction;
|
|
158
|
+
let contextUser: UserInfo;
|
|
159
|
+
|
|
160
|
+
beforeEach(() => {
|
|
161
|
+
action = new GetLearnWorldsCourseDetailsAction();
|
|
162
|
+
contextUser = createMockContextUser();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('GetCourseDetails() typed method', () => {
|
|
166
|
+
it('should return course details with modules, instructors, and stats', async () => {
|
|
167
|
+
const courseData = createRawCourseData();
|
|
168
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
169
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
170
|
+
const statsResponse = createRawStatsResponse();
|
|
171
|
+
|
|
172
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
173
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
174
|
+
.mockResolvedValueOnce(sectionsResponse as never) // sections/modules
|
|
175
|
+
.mockResolvedValueOnce(instructorsResponse as never) // instructors
|
|
176
|
+
.mockResolvedValueOnce(statsResponse as never); // stats
|
|
177
|
+
|
|
178
|
+
const result = await action.GetCourseDetails(
|
|
179
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: true },
|
|
180
|
+
contextUser,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
// Verify base course details
|
|
184
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
185
|
+
expect(result.CourseDetails.title).toBe('Intro to TypeScript');
|
|
186
|
+
expect(result.CourseDetails.slug).toBe('intro-typescript');
|
|
187
|
+
expect(result.CourseDetails.price).toBe(79.99);
|
|
188
|
+
expect(result.CourseDetails.currency).toBe('USD');
|
|
189
|
+
expect(result.CourseDetails.level).toBe('beginner');
|
|
190
|
+
expect(result.CourseDetails.certificateEnabled).toBe(true);
|
|
191
|
+
expect(result.CourseDetails.tags).toEqual(['typescript', 'programming']);
|
|
192
|
+
|
|
193
|
+
// Verify modules
|
|
194
|
+
expect(result.CourseDetails.modules).toBeDefined();
|
|
195
|
+
expect(result.CourseDetails.modules).toHaveLength(2);
|
|
196
|
+
expect(result.CourseDetails.totalModules).toBe(2);
|
|
197
|
+
expect(result.CourseDetails.totalLessons).toBe(5);
|
|
198
|
+
|
|
199
|
+
// Verify instructors
|
|
200
|
+
expect(result.CourseDetails.instructors).toBeDefined();
|
|
201
|
+
expect(result.CourseDetails.instructors).toHaveLength(1);
|
|
202
|
+
expect(result.CourseDetails.instructors![0].name).toBe('Jane Doe');
|
|
203
|
+
expect(result.CourseDetails.instructors![0].totalCourses).toBe(5);
|
|
204
|
+
|
|
205
|
+
// Verify stats
|
|
206
|
+
expect(result.CourseDetails.stats).toBeDefined();
|
|
207
|
+
expect(result.CourseDetails.stats!.totalEnrollments).toBe(300);
|
|
208
|
+
expect(result.CourseDetails.stats!.completionRate).toBe(55);
|
|
209
|
+
expect(result.CourseDetails.stats!.totalRevenue).toBe(15000);
|
|
210
|
+
|
|
211
|
+
// Verify summary
|
|
212
|
+
expect(result.Summary.courseId).toBe('course-1');
|
|
213
|
+
expect(result.Summary.title).toBe('Intro to TypeScript');
|
|
214
|
+
expect(result.Summary.totalModules).toBe(2);
|
|
215
|
+
expect(result.Summary.totalLessons).toBe(5);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should return course details without modules when IncludeModules is false', async () => {
|
|
219
|
+
const courseData = createRawCourseData();
|
|
220
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
221
|
+
const statsResponse = createRawStatsResponse();
|
|
222
|
+
|
|
223
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
224
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
225
|
+
.mockResolvedValueOnce(instructorsResponse as never) // instructors
|
|
226
|
+
.mockResolvedValueOnce(statsResponse as never); // stats
|
|
227
|
+
|
|
228
|
+
const result = await action.GetCourseDetails(
|
|
229
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: false, IncludeInstructors: true, IncludeStats: true },
|
|
230
|
+
contextUser,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
234
|
+
expect(result.CourseDetails.modules).toBeUndefined();
|
|
235
|
+
expect(result.CourseDetails.instructors).toBeDefined();
|
|
236
|
+
expect(result.CourseDetails.stats).toBeDefined();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should return course details without instructors when IncludeInstructors is false', async () => {
|
|
240
|
+
const courseData = createRawCourseData();
|
|
241
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
242
|
+
const statsResponse = createRawStatsResponse();
|
|
243
|
+
|
|
244
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
245
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
246
|
+
.mockResolvedValueOnce(sectionsResponse as never) // sections
|
|
247
|
+
.mockResolvedValueOnce(statsResponse as never); // stats
|
|
248
|
+
|
|
249
|
+
const result = await action.GetCourseDetails(
|
|
250
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: false, IncludeStats: true },
|
|
251
|
+
contextUser,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
255
|
+
expect(result.CourseDetails.modules).toBeDefined();
|
|
256
|
+
expect(result.CourseDetails.instructors).toBeUndefined();
|
|
257
|
+
expect(result.CourseDetails.stats).toBeDefined();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should return course details without stats when IncludeStats is false', async () => {
|
|
261
|
+
const courseData = createRawCourseData();
|
|
262
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
263
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
264
|
+
|
|
265
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
266
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
267
|
+
.mockResolvedValueOnce(sectionsResponse as never) // sections
|
|
268
|
+
.mockResolvedValueOnce(instructorsResponse as never); // instructors
|
|
269
|
+
|
|
270
|
+
const result = await action.GetCourseDetails(
|
|
271
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: false },
|
|
272
|
+
contextUser,
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
276
|
+
expect(result.CourseDetails.modules).toBeDefined();
|
|
277
|
+
expect(result.CourseDetails.instructors).toBeDefined();
|
|
278
|
+
expect(result.CourseDetails.stats).toBeUndefined();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('should log warning and continue when sections endpoint fails', async () => {
|
|
282
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
283
|
+
const courseData = createRawCourseData();
|
|
284
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
285
|
+
const statsResponse = createRawStatsResponse();
|
|
286
|
+
|
|
287
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
288
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
289
|
+
.mockRejectedValueOnce(new Error('Sections endpoint not found')) // sections fail
|
|
290
|
+
.mockResolvedValueOnce(instructorsResponse as never) // instructors
|
|
291
|
+
.mockResolvedValueOnce(statsResponse as never); // stats
|
|
292
|
+
|
|
293
|
+
const result = await action.GetCourseDetails(
|
|
294
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: true },
|
|
295
|
+
contextUser,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
299
|
+
expect(result.CourseDetails.modules).toBeUndefined();
|
|
300
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
301
|
+
expect.stringContaining('Sections endpoint unavailable'),
|
|
302
|
+
expect.stringContaining('Sections endpoint not found'),
|
|
303
|
+
);
|
|
304
|
+
// Instructors and stats should still be present
|
|
305
|
+
expect(result.CourseDetails.instructors).toBeDefined();
|
|
306
|
+
expect(result.CourseDetails.stats).toBeDefined();
|
|
307
|
+
|
|
308
|
+
warnSpy.mockRestore();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('should log warning and continue when instructors endpoint fails', async () => {
|
|
312
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
313
|
+
const courseData = createRawCourseData();
|
|
314
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
315
|
+
const statsResponse = createRawStatsResponse();
|
|
316
|
+
|
|
317
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
318
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
319
|
+
.mockResolvedValueOnce(sectionsResponse as never) // sections
|
|
320
|
+
.mockRejectedValueOnce(new Error('Instructors API error')) // instructors fail
|
|
321
|
+
.mockResolvedValueOnce(statsResponse as never); // stats
|
|
322
|
+
|
|
323
|
+
const result = await action.GetCourseDetails(
|
|
324
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: true },
|
|
325
|
+
contextUser,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
329
|
+
expect(result.CourseDetails.instructors).toBeUndefined();
|
|
330
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
331
|
+
expect.stringContaining('Instructors endpoint unavailable'),
|
|
332
|
+
expect.stringContaining('Instructors API error'),
|
|
333
|
+
);
|
|
334
|
+
expect(result.CourseDetails.modules).toBeDefined();
|
|
335
|
+
expect(result.CourseDetails.stats).toBeDefined();
|
|
336
|
+
|
|
337
|
+
warnSpy.mockRestore();
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('should log warning and continue when stats endpoint fails', async () => {
|
|
341
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
342
|
+
const courseData = createRawCourseData();
|
|
343
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
344
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
345
|
+
|
|
346
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
347
|
+
.mockResolvedValueOnce(courseData as never) // course details
|
|
348
|
+
.mockResolvedValueOnce(sectionsResponse as never) // sections
|
|
349
|
+
.mockResolvedValueOnce(instructorsResponse as never) // instructors
|
|
350
|
+
.mockRejectedValueOnce(new Error('Stats service down')); // stats fail
|
|
351
|
+
|
|
352
|
+
const result = await action.GetCourseDetails(
|
|
353
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: true },
|
|
354
|
+
contextUser,
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
expect(result.CourseDetails.id).toBe('course-1');
|
|
358
|
+
expect(result.CourseDetails.stats).toBeUndefined();
|
|
359
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
360
|
+
expect.stringContaining('Stats endpoint unavailable'),
|
|
361
|
+
expect.stringContaining('Stats service down'),
|
|
362
|
+
);
|
|
363
|
+
expect(result.CourseDetails.modules).toBeDefined();
|
|
364
|
+
expect(result.CourseDetails.instructors).toBeDefined();
|
|
365
|
+
|
|
366
|
+
warnSpy.mockRestore();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('should throw error when CourseID is missing', async () => {
|
|
370
|
+
await expect(
|
|
371
|
+
action.GetCourseDetails({ CompanyID: 'comp-1', CourseID: '' }, contextUser),
|
|
372
|
+
).rejects.toThrow('CourseID is required');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('should correctly format modules and lessons', async () => {
|
|
376
|
+
const courseData = createRawCourseData();
|
|
377
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
378
|
+
|
|
379
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
380
|
+
.mockResolvedValueOnce(courseData as never)
|
|
381
|
+
.mockResolvedValueOnce(sectionsResponse as never);
|
|
382
|
+
|
|
383
|
+
const result = await action.GetCourseDetails(
|
|
384
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: false, IncludeStats: false },
|
|
385
|
+
contextUser,
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
const modules = result.CourseDetails.modules!;
|
|
389
|
+
expect(modules[0].id).toBe('mod-1');
|
|
390
|
+
expect(modules[0].title).toBe('Getting Started');
|
|
391
|
+
expect(modules[0].order).toBe(1);
|
|
392
|
+
expect(modules[0].totalLessons).toBe(3);
|
|
393
|
+
expect(modules[0].lessons).toHaveLength(3);
|
|
394
|
+
|
|
395
|
+
// Check first lesson details
|
|
396
|
+
const firstLesson = modules[0].lessons[0];
|
|
397
|
+
expect(firstLesson.id).toBe('les-1');
|
|
398
|
+
expect(firstLesson.title).toBe('Welcome');
|
|
399
|
+
expect(firstLesson.type).toBe('video');
|
|
400
|
+
expect(firstLesson.isFree).toBe(true);
|
|
401
|
+
expect(firstLesson.hasVideo).toBe(true);
|
|
402
|
+
expect(firstLesson.hasQuiz).toBe(false);
|
|
403
|
+
|
|
404
|
+
// Check second module
|
|
405
|
+
expect(modules[1].id).toBe('mod-2');
|
|
406
|
+
expect(modules[1].order).toBe(2);
|
|
407
|
+
expect(modules[1].lessons).toHaveLength(2);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('should build correct summary structure', async () => {
|
|
411
|
+
const courseData = createRawCourseData();
|
|
412
|
+
const sectionsResponse = createRawSectionsResponse();
|
|
413
|
+
const instructorsResponse = createRawInstructorsResponse();
|
|
414
|
+
const statsResponse = createRawStatsResponse();
|
|
415
|
+
|
|
416
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest')
|
|
417
|
+
.mockResolvedValueOnce(courseData as never)
|
|
418
|
+
.mockResolvedValueOnce(sectionsResponse as never)
|
|
419
|
+
.mockResolvedValueOnce(instructorsResponse as never)
|
|
420
|
+
.mockResolvedValueOnce(statsResponse as never);
|
|
421
|
+
|
|
422
|
+
const result = await action.GetCourseDetails(
|
|
423
|
+
{ CompanyID: 'comp-1', CourseID: 'course-1', IncludeModules: true, IncludeInstructors: true, IncludeStats: true },
|
|
424
|
+
contextUser,
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
expect(result.Summary).toEqual({
|
|
428
|
+
courseId: 'course-1',
|
|
429
|
+
title: 'Intro to TypeScript',
|
|
430
|
+
status: 'published',
|
|
431
|
+
level: 'beginner',
|
|
432
|
+
duration: expect.any(String),
|
|
433
|
+
totalModules: 2,
|
|
434
|
+
totalLessons: 5,
|
|
435
|
+
totalEnrollments: 250,
|
|
436
|
+
averageRating: 4.5,
|
|
437
|
+
certificateEnabled: true,
|
|
438
|
+
price: 79.99,
|
|
439
|
+
currency: 'USD',
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
describe('InternalRunAction()', () => {
|
|
445
|
+
it('should return success when GetCourseDetails succeeds', async () => {
|
|
446
|
+
vi.spyOn(action, 'GetCourseDetails').mockResolvedValue({
|
|
447
|
+
CourseDetails: {
|
|
448
|
+
id: 'course-1',
|
|
449
|
+
title: 'Test Course',
|
|
450
|
+
status: 'published',
|
|
451
|
+
price: 0,
|
|
452
|
+
currency: 'USD',
|
|
453
|
+
level: 'beginner',
|
|
454
|
+
language: 'en',
|
|
455
|
+
totalEnrollments: 10,
|
|
456
|
+
totalRatings: 0,
|
|
457
|
+
tags: [],
|
|
458
|
+
categories: [],
|
|
459
|
+
certificateEnabled: false,
|
|
460
|
+
},
|
|
461
|
+
Summary: {
|
|
462
|
+
courseId: 'course-1',
|
|
463
|
+
title: 'Test Course',
|
|
464
|
+
status: 'published',
|
|
465
|
+
level: 'beginner',
|
|
466
|
+
totalModules: 0,
|
|
467
|
+
totalLessons: 0,
|
|
468
|
+
totalEnrollments: 10,
|
|
469
|
+
averageRating: 0,
|
|
470
|
+
certificateEnabled: false,
|
|
471
|
+
price: 0,
|
|
472
|
+
currency: 'USD',
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const runParams: RunActionParams = {
|
|
477
|
+
Params: [
|
|
478
|
+
{ Name: 'CompanyID', Type: 'Input', Value: 'comp-1' },
|
|
479
|
+
{ Name: 'CourseID', Type: 'Input', Value: 'course-1' },
|
|
480
|
+
],
|
|
481
|
+
ContextUser: contextUser,
|
|
482
|
+
} as unknown as RunActionParams;
|
|
483
|
+
|
|
484
|
+
const result = (await action['InternalRunAction'](runParams)) as ActionResultSimple;
|
|
485
|
+
|
|
486
|
+
expect(result.Success).toBe(true);
|
|
487
|
+
expect(result.ResultCode).toBe('SUCCESS');
|
|
488
|
+
expect(result.Message).toContain('Course details retrieved successfully');
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it('should return error result when GetCourseDetails throws', async () => {
|
|
492
|
+
vi.spyOn(action, 'GetCourseDetails').mockRejectedValue(new Error('Course not found'));
|
|
493
|
+
|
|
494
|
+
const runParams: RunActionParams = {
|
|
495
|
+
Params: [
|
|
496
|
+
{ Name: 'CompanyID', Type: 'Input', Value: 'comp-1' },
|
|
497
|
+
{ Name: 'CourseID', Type: 'Input', Value: 'course-1' },
|
|
498
|
+
],
|
|
499
|
+
ContextUser: contextUser,
|
|
500
|
+
} as unknown as RunActionParams;
|
|
501
|
+
|
|
502
|
+
const result = (await action['InternalRunAction'](runParams)) as ActionResultSimple;
|
|
503
|
+
|
|
504
|
+
expect(result.Success).toBe(false);
|
|
505
|
+
expect(result.ResultCode).toBe('ERROR');
|
|
506
|
+
expect(result.Message).toContain('Error retrieving course details');
|
|
507
|
+
expect(result.Message).toContain('Course not found');
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
});
|