@memberjunction/actions-bizapps-lms 5.22.0 → 5.24.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 +27 -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,467 @@
|
|
|
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 { GetCertificatesAction } from '../providers/learnworlds/actions/get-certificates.action';
|
|
44
|
+
import { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
45
|
+
import { FormattedCertificate } from '../providers/learnworlds/interfaces';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Helper to create a mock UserInfo for test context
|
|
49
|
+
*/
|
|
50
|
+
function createMockContextUser(): UserInfo {
|
|
51
|
+
return { ID: 'test-user-id', Name: 'Test User', Email: 'test@example.com' } as unknown as UserInfo;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Helper to build a raw LW API certificate object matching the LWRawCertificate interface
|
|
56
|
+
*/
|
|
57
|
+
function createRawApiCertificate(overrides: Record<string, unknown> = {}): Record<string, unknown> {
|
|
58
|
+
return {
|
|
59
|
+
id: 'cert-1',
|
|
60
|
+
user_id: 'user-1',
|
|
61
|
+
course_id: 'course-1',
|
|
62
|
+
certificate_number: 'CERT-2024-001',
|
|
63
|
+
issued_at: '2024-06-15T10:00:00Z',
|
|
64
|
+
expires_at: '2025-06-15T10:00:00Z',
|
|
65
|
+
status: 'active',
|
|
66
|
+
grade: 95,
|
|
67
|
+
score: 92,
|
|
68
|
+
completion_percentage: 100,
|
|
69
|
+
user: {
|
|
70
|
+
id: 'user-1',
|
|
71
|
+
email: 'student@example.com',
|
|
72
|
+
first_name: 'Jane',
|
|
73
|
+
last_name: 'Doe',
|
|
74
|
+
},
|
|
75
|
+
course: {
|
|
76
|
+
id: 'course-1',
|
|
77
|
+
title: 'Intro to Testing',
|
|
78
|
+
duration: 3600,
|
|
79
|
+
},
|
|
80
|
+
pdf_url: 'https://example.com/cert.pdf',
|
|
81
|
+
image_url: 'https://example.com/cert.png',
|
|
82
|
+
public_url: 'https://example.com/cert/public',
|
|
83
|
+
verification_url: 'https://example.com/verify/CERT-2024-001',
|
|
84
|
+
verification_code: 'VERIFY-001',
|
|
85
|
+
qr_code_url: 'https://example.com/qr/CERT-2024-001',
|
|
86
|
+
...overrides,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe('GetCertificatesAction', () => {
|
|
91
|
+
let action: GetCertificatesAction;
|
|
92
|
+
let contextUser: UserInfo;
|
|
93
|
+
|
|
94
|
+
beforeEach(() => {
|
|
95
|
+
action = new GetCertificatesAction();
|
|
96
|
+
contextUser = createMockContextUser();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('GetCertificates() typed method', () => {
|
|
100
|
+
it('should get certificates successfully with full data', async () => {
|
|
101
|
+
const rawCert = createRawApiCertificate();
|
|
102
|
+
|
|
103
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
104
|
+
success: true,
|
|
105
|
+
data: [rawCert],
|
|
106
|
+
} as never);
|
|
107
|
+
|
|
108
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
109
|
+
|
|
110
|
+
expect(result.TotalCount).toBe(1);
|
|
111
|
+
expect(result.Certificates).toHaveLength(1);
|
|
112
|
+
|
|
113
|
+
const cert: FormattedCertificate = result.Certificates[0];
|
|
114
|
+
expect(cert.id).toBe('cert-1');
|
|
115
|
+
expect(cert.userId).toBe('user-1');
|
|
116
|
+
expect(cert.courseId).toBe('course-1');
|
|
117
|
+
expect(cert.certificateNumber).toBe('CERT-2024-001');
|
|
118
|
+
expect(cert.issuedAt).toBe('2024-06-15T10:00:00Z');
|
|
119
|
+
expect(cert.expiresAt).toBe('2025-06-15T10:00:00Z');
|
|
120
|
+
expect(cert.status).toBe('active');
|
|
121
|
+
expect(cert.grade).toBe(95);
|
|
122
|
+
expect(cert.score).toBe(92);
|
|
123
|
+
expect(cert.completionPercentage).toBe(100);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should format certificate with inline user and course info', async () => {
|
|
127
|
+
const rawCert = createRawApiCertificate();
|
|
128
|
+
|
|
129
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
130
|
+
success: true,
|
|
131
|
+
data: [rawCert],
|
|
132
|
+
} as never);
|
|
133
|
+
|
|
134
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
135
|
+
const cert = result.Certificates[0];
|
|
136
|
+
|
|
137
|
+
expect(cert.user).toBeDefined();
|
|
138
|
+
expect(cert.user?.id).toBe('user-1');
|
|
139
|
+
expect(cert.user?.email).toBe('student@example.com');
|
|
140
|
+
expect(cert.user?.name).toBe('Jane Doe');
|
|
141
|
+
|
|
142
|
+
expect(cert.course).toBeDefined();
|
|
143
|
+
expect(cert.course?.id).toBe('course-1');
|
|
144
|
+
expect(cert.course?.title).toBe('Intro to Testing');
|
|
145
|
+
expect(cert.course?.duration).toBe(3600);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should include download links by default', async () => {
|
|
149
|
+
const rawCert = createRawApiCertificate();
|
|
150
|
+
|
|
151
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
152
|
+
success: true,
|
|
153
|
+
data: [rawCert],
|
|
154
|
+
} as never);
|
|
155
|
+
|
|
156
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
157
|
+
const cert = result.Certificates[0];
|
|
158
|
+
|
|
159
|
+
expect(cert.downloadLinks).toBeDefined();
|
|
160
|
+
expect(cert.downloadLinks?.pdf).toBe('https://example.com/cert.pdf');
|
|
161
|
+
expect(cert.downloadLinks?.image).toBe('https://example.com/cert.png');
|
|
162
|
+
expect(cert.downloadLinks?.publicUrl).toBe('https://example.com/cert/public');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should omit download links when IncludeDownloadLinks is false', async () => {
|
|
166
|
+
const rawCert = createRawApiCertificate();
|
|
167
|
+
|
|
168
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
169
|
+
success: true,
|
|
170
|
+
data: [rawCert],
|
|
171
|
+
} as never);
|
|
172
|
+
|
|
173
|
+
const result = await action.GetCertificates(
|
|
174
|
+
{ CompanyID: 'comp-1', UserID: 'user-1', IncludeDownloadLinks: false },
|
|
175
|
+
contextUser,
|
|
176
|
+
);
|
|
177
|
+
const cert = result.Certificates[0];
|
|
178
|
+
|
|
179
|
+
expect(cert.downloadLinks).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should include verification info', async () => {
|
|
183
|
+
const rawCert = createRawApiCertificate();
|
|
184
|
+
|
|
185
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
186
|
+
success: true,
|
|
187
|
+
data: [rawCert],
|
|
188
|
+
} as never);
|
|
189
|
+
|
|
190
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
191
|
+
const cert = result.Certificates[0];
|
|
192
|
+
|
|
193
|
+
expect(cert.verification).toBeDefined();
|
|
194
|
+
expect(cert.verification.url).toBe('https://example.com/verify/CERT-2024-001');
|
|
195
|
+
expect(cert.verification.code).toBe('VERIFY-001');
|
|
196
|
+
expect(cert.verification.qrCode).toBe('https://example.com/qr/CERT-2024-001');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should build summary with correct counts and grouping by course when filtering by user', async () => {
|
|
200
|
+
const cert1 = createRawApiCertificate({
|
|
201
|
+
id: 'cert-1',
|
|
202
|
+
course_id: 'course-1',
|
|
203
|
+
course: { id: 'course-1', title: 'Course A' },
|
|
204
|
+
status: 'active',
|
|
205
|
+
expires_at: '2099-12-31T00:00:00Z',
|
|
206
|
+
});
|
|
207
|
+
const cert2 = createRawApiCertificate({
|
|
208
|
+
id: 'cert-2',
|
|
209
|
+
course_id: 'course-2',
|
|
210
|
+
course: { id: 'course-2', title: 'Course B' },
|
|
211
|
+
status: 'active',
|
|
212
|
+
expires_at: '2000-01-01T00:00:00Z', // expired
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
216
|
+
success: true,
|
|
217
|
+
data: [cert1, cert2],
|
|
218
|
+
} as never);
|
|
219
|
+
|
|
220
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
221
|
+
|
|
222
|
+
expect(result.Summary.totalCertificates).toBe(2);
|
|
223
|
+
expect(result.Summary.activeCertificates).toBe(1);
|
|
224
|
+
expect(result.Summary.expiredCertificates).toBe(1);
|
|
225
|
+
expect(result.Summary.filterType).toBe('user');
|
|
226
|
+
// When filtering by UserID only, certs are grouped by course title
|
|
227
|
+
expect(result.Summary.groupedData).not.toBeNull();
|
|
228
|
+
expect(result.Summary.groupedData?.['Course A']).toHaveLength(1);
|
|
229
|
+
expect(result.Summary.groupedData?.['Course B']).toHaveLength(1);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should build summary grouped by user when filtering by course', async () => {
|
|
233
|
+
const cert1 = createRawApiCertificate({
|
|
234
|
+
id: 'cert-1',
|
|
235
|
+
user_id: 'user-1',
|
|
236
|
+
user: { id: 'user-1', email: 'alice@example.com', first_name: 'Alice', last_name: 'Smith' },
|
|
237
|
+
});
|
|
238
|
+
const cert2 = createRawApiCertificate({
|
|
239
|
+
id: 'cert-2',
|
|
240
|
+
user_id: 'user-2',
|
|
241
|
+
user: { id: 'user-2', email: 'bob@example.com', first_name: 'Bob', last_name: 'Jones' },
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Mock once for the certificates endpoint, no extra user/course lookups needed (inline data present)
|
|
245
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
246
|
+
success: true,
|
|
247
|
+
data: [cert1, cert2],
|
|
248
|
+
} as never);
|
|
249
|
+
|
|
250
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', CourseID: 'course-1' }, contextUser);
|
|
251
|
+
|
|
252
|
+
expect(result.Summary.filterType).toBe('course');
|
|
253
|
+
expect(result.Summary.groupedData).not.toBeNull();
|
|
254
|
+
expect(result.Summary.groupedData?.['Alice Smith']).toHaveLength(1);
|
|
255
|
+
expect(result.Summary.groupedData?.['Bob Jones']).toHaveLength(1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should set filterType to user-course when both UserID and CourseID are provided', async () => {
|
|
259
|
+
const rawCert = createRawApiCertificate();
|
|
260
|
+
|
|
261
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
262
|
+
success: true,
|
|
263
|
+
data: [rawCert],
|
|
264
|
+
} as never);
|
|
265
|
+
|
|
266
|
+
const result = await action.GetCertificates(
|
|
267
|
+
{ CompanyID: 'comp-1', UserID: 'user-1', CourseID: 'course-1' },
|
|
268
|
+
contextUser,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
expect(result.Summary.filterType).toBe('user-course');
|
|
272
|
+
// No groupedData when both filters are provided
|
|
273
|
+
expect(result.Summary.groupedData).toBeNull();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('should handle empty certificates', async () => {
|
|
277
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
278
|
+
success: true,
|
|
279
|
+
data: [],
|
|
280
|
+
} as never);
|
|
281
|
+
|
|
282
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
283
|
+
|
|
284
|
+
expect(result.TotalCount).toBe(0);
|
|
285
|
+
expect(result.Certificates).toEqual([]);
|
|
286
|
+
expect(result.Summary.totalCertificates).toBe(0);
|
|
287
|
+
expect(result.Summary.activeCertificates).toBe(0);
|
|
288
|
+
expect(result.Summary.expiredCertificates).toBe(0);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should throw when neither UserID nor CourseID is provided', async () => {
|
|
292
|
+
await expect(action.GetCertificates({ CompanyID: 'comp-1' }, contextUser)).rejects.toThrow(
|
|
293
|
+
'Either UserID or CourseID is required',
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('should propagate API errors', async () => {
|
|
298
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
299
|
+
success: false,
|
|
300
|
+
message: 'Unauthorized',
|
|
301
|
+
} as never);
|
|
302
|
+
|
|
303
|
+
await expect(action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser)).rejects.toThrow(
|
|
304
|
+
'Unauthorized',
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should propagate network errors', async () => {
|
|
309
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockRejectedValue(new Error('Network timeout') as never);
|
|
310
|
+
|
|
311
|
+
await expect(action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser)).rejects.toThrow(
|
|
312
|
+
'Network timeout',
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('should use download_url as fallback for pdf when pdf_url is missing', async () => {
|
|
317
|
+
const rawCert = createRawApiCertificate({
|
|
318
|
+
pdf_url: undefined,
|
|
319
|
+
download_url: 'https://example.com/download/cert.pdf',
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
323
|
+
success: true,
|
|
324
|
+
data: [rawCert],
|
|
325
|
+
} as never);
|
|
326
|
+
|
|
327
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
328
|
+
|
|
329
|
+
expect(result.Certificates[0].downloadLinks?.pdf).toBe('https://example.com/download/cert.pdf');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('should use certificate_url as fallback for publicUrl when public_url is missing', async () => {
|
|
333
|
+
const rawCert = createRawApiCertificate({
|
|
334
|
+
public_url: undefined,
|
|
335
|
+
certificate_url: 'https://example.com/certificate/view',
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
339
|
+
success: true,
|
|
340
|
+
data: [rawCert],
|
|
341
|
+
} as never);
|
|
342
|
+
|
|
343
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
344
|
+
|
|
345
|
+
expect(result.Certificates[0].downloadLinks?.publicUrl).toBe('https://example.com/certificate/view');
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should use certificate_id as fallback when id is missing', async () => {
|
|
349
|
+
const rawCert = createRawApiCertificate({ id: undefined, certificate_id: 'alt-cert-id' });
|
|
350
|
+
|
|
351
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
352
|
+
success: true,
|
|
353
|
+
data: [rawCert],
|
|
354
|
+
} as never);
|
|
355
|
+
|
|
356
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
357
|
+
|
|
358
|
+
expect(result.Certificates[0].id).toBe('alt-cert-id');
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('should handle nested data shape from API response', async () => {
|
|
362
|
+
const rawCert = createRawApiCertificate();
|
|
363
|
+
|
|
364
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
365
|
+
success: true,
|
|
366
|
+
data: { data: [rawCert] },
|
|
367
|
+
} as never);
|
|
368
|
+
|
|
369
|
+
const result = await action.GetCertificates({ CompanyID: 'comp-1', UserID: 'user-1' }, contextUser);
|
|
370
|
+
|
|
371
|
+
expect(result.TotalCount).toBe(1);
|
|
372
|
+
expect(result.Certificates[0].id).toBe('cert-1');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('should handle single-certificate object response', async () => {
|
|
376
|
+
const rawCert = createRawApiCertificate();
|
|
377
|
+
|
|
378
|
+
vi.spyOn(action as never, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
379
|
+
success: true,
|
|
380
|
+
data: rawCert, // single object, not array
|
|
381
|
+
} as never);
|
|
382
|
+
|
|
383
|
+
const result = await action.GetCertificates(
|
|
384
|
+
{ CompanyID: 'comp-1', UserID: 'user-1', CourseID: 'course-1' },
|
|
385
|
+
contextUser,
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
expect(result.TotalCount).toBe(1);
|
|
389
|
+
expect(result.Certificates[0].id).toBe('cert-1');
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe('InternalRunAction()', () => {
|
|
394
|
+
it('should return success when GetCertificates succeeds', async () => {
|
|
395
|
+
const mockCertificates: FormattedCertificate[] = [
|
|
396
|
+
{
|
|
397
|
+
id: 'cert-1',
|
|
398
|
+
userId: 'user-1',
|
|
399
|
+
courseId: 'course-1',
|
|
400
|
+
certificateNumber: 'CERT-001',
|
|
401
|
+
issuedAt: '2024-06-15T10:00:00Z',
|
|
402
|
+
status: 'active',
|
|
403
|
+
completionPercentage: 100,
|
|
404
|
+
verification: { url: undefined, code: undefined, qrCode: undefined },
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
id: 'cert-2',
|
|
408
|
+
userId: 'user-1',
|
|
409
|
+
courseId: 'course-2',
|
|
410
|
+
certificateNumber: 'CERT-002',
|
|
411
|
+
issuedAt: '2024-07-01T10:00:00Z',
|
|
412
|
+
status: 'active',
|
|
413
|
+
completionPercentage: 100,
|
|
414
|
+
verification: { url: undefined, code: undefined, qrCode: undefined },
|
|
415
|
+
},
|
|
416
|
+
];
|
|
417
|
+
|
|
418
|
+
vi.spyOn(action, 'GetCertificates').mockResolvedValue({
|
|
419
|
+
Certificates: mockCertificates,
|
|
420
|
+
TotalCount: 2,
|
|
421
|
+
Summary: {
|
|
422
|
+
totalCertificates: 2,
|
|
423
|
+
activeCertificates: 2,
|
|
424
|
+
expiredCertificates: 0,
|
|
425
|
+
dateRange: { from: 'all-time', to: 'current' },
|
|
426
|
+
filterType: 'user',
|
|
427
|
+
groupedData: null,
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const runParams: RunActionParams = {
|
|
432
|
+
Params: [
|
|
433
|
+
{ Name: 'CompanyID', Type: 'Input', Value: 'comp-1' },
|
|
434
|
+
{ Name: 'UserID', Type: 'Input', Value: 'user-1' },
|
|
435
|
+
{ Name: 'CourseID', Type: 'Input', Value: undefined },
|
|
436
|
+
{ Name: 'IncludeDownloadLinks', Type: 'Input', Value: true },
|
|
437
|
+
],
|
|
438
|
+
ContextUser: contextUser,
|
|
439
|
+
} as unknown as RunActionParams;
|
|
440
|
+
|
|
441
|
+
const result = (await action['InternalRunAction'](runParams)) as ActionResultSimple;
|
|
442
|
+
|
|
443
|
+
expect(result.Success).toBe(true);
|
|
444
|
+
expect(result.ResultCode).toBe('SUCCESS');
|
|
445
|
+
expect(result.Message).toContain('Retrieved 2 certificate(s)');
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('should return error result when GetCertificates throws', async () => {
|
|
449
|
+
vi.spyOn(action, 'GetCertificates').mockRejectedValue(new Error('API connection failed'));
|
|
450
|
+
|
|
451
|
+
const runParams: RunActionParams = {
|
|
452
|
+
Params: [
|
|
453
|
+
{ Name: 'CompanyID', Type: 'Input', Value: 'comp-1' },
|
|
454
|
+
{ Name: 'UserID', Type: 'Input', Value: 'user-1' },
|
|
455
|
+
],
|
|
456
|
+
ContextUser: contextUser,
|
|
457
|
+
} as unknown as RunActionParams;
|
|
458
|
+
|
|
459
|
+
const result = (await action['InternalRunAction'](runParams)) as ActionResultSimple;
|
|
460
|
+
|
|
461
|
+
expect(result.Success).toBe(false);
|
|
462
|
+
expect(result.ResultCode).toBe('ERROR');
|
|
463
|
+
expect(result.Message).toContain('Error retrieving certificates');
|
|
464
|
+
expect(result.Message).toContain('API connection failed');
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
});
|