@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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +26 -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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock dependencies (same pattern as lms.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
|
+
ActionResultSimple: class ActionResultSimple {
|
|
41
|
+
Success: boolean = false;
|
|
42
|
+
ResultCode: string = '';
|
|
43
|
+
Message: string = '';
|
|
44
|
+
Params?: Array<{ Name: string; Value: unknown; Type: string }>;
|
|
45
|
+
},
|
|
46
|
+
RunActionParams: class RunActionParams {
|
|
47
|
+
Params: Array<{ Name: string; Value: unknown; Type: string }> = [];
|
|
48
|
+
ContextUser: unknown = {};
|
|
49
|
+
Action: unknown = {};
|
|
50
|
+
Filters: unknown[] = [];
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
import { SSOLoginAction } from '../providers/learnworlds/actions/sso-login.action';
|
|
55
|
+
import { UserInfo } from '@memberjunction/core';
|
|
56
|
+
import { SSOLoginParams } from '../providers/learnworlds/interfaces';
|
|
57
|
+
|
|
58
|
+
/** Helper to build a mock UserInfo */
|
|
59
|
+
function mockContextUser(): UserInfo {
|
|
60
|
+
return { ID: 'user-1', Name: 'Test User', Email: 'test@example.com' } as unknown as UserInfo;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('SSOLoginAction', () => {
|
|
64
|
+
let action: SSOLoginAction;
|
|
65
|
+
const contextUser = mockContextUser();
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
action = new SSOLoginAction();
|
|
69
|
+
vi.restoreAllMocks();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('GenerateSSOUrl() typed method', () => {
|
|
73
|
+
it('should generate SSO URL with email', async () => {
|
|
74
|
+
const requestSpy = vi
|
|
75
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
76
|
+
.mockResolvedValue({
|
|
77
|
+
url: 'https://school.learnworlds.com/sso?token=abc123',
|
|
78
|
+
user_id: 'lw-user-42',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const params: SSOLoginParams = {
|
|
82
|
+
CompanyID: 'comp-1',
|
|
83
|
+
Email: 'student@example.com',
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const result = await action.GenerateSSOUrl(params, contextUser);
|
|
87
|
+
|
|
88
|
+
expect(result.LoginURL).toBe('https://school.learnworlds.com/sso?token=abc123');
|
|
89
|
+
expect(result.LearnWorldsUserID).toBe('lw-user-42');
|
|
90
|
+
|
|
91
|
+
// Verify the request body contained the email
|
|
92
|
+
expect(requestSpy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(requestSpy.mock.calls[0][0]).toBe('sso');
|
|
94
|
+
expect(requestSpy.mock.calls[0][1]).toBe('POST');
|
|
95
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
96
|
+
expect(body.email).toBe('student@example.com');
|
|
97
|
+
expect(body.user_id).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should generate SSO URL with userId', async () => {
|
|
101
|
+
const requestSpy = vi
|
|
102
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
103
|
+
.mockResolvedValue({
|
|
104
|
+
url: 'https://school.learnworlds.com/sso?token=def456',
|
|
105
|
+
user_id: 'lw-user-99',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const params: SSOLoginParams = {
|
|
109
|
+
CompanyID: 'comp-1',
|
|
110
|
+
UserID: 'lw-user-99',
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const result = await action.GenerateSSOUrl(params, contextUser);
|
|
114
|
+
|
|
115
|
+
expect(result.LoginURL).toBe('https://school.learnworlds.com/sso?token=def456');
|
|
116
|
+
expect(result.LearnWorldsUserID).toBe('lw-user-99');
|
|
117
|
+
|
|
118
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
119
|
+
expect(body.user_id).toBe('lw-user-99');
|
|
120
|
+
expect(body.email).toBeUndefined();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should throw when neither email nor userId provided', async () => {
|
|
124
|
+
const params: SSOLoginParams = {
|
|
125
|
+
CompanyID: 'comp-1',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
await expect(action.GenerateSSOUrl(params, contextUser)).rejects.toThrow('Either Email or UserID is required for SSO login');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should include RedirectTo in the request body when provided', async () => {
|
|
132
|
+
const requestSpy = vi
|
|
133
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
134
|
+
.mockResolvedValue({
|
|
135
|
+
url: 'https://school.learnworlds.com/sso?token=xyz',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const params: SSOLoginParams = {
|
|
139
|
+
CompanyID: 'comp-1',
|
|
140
|
+
Email: 'student@example.com',
|
|
141
|
+
RedirectTo: '/courses/my-course',
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
await action.GenerateSSOUrl(params, contextUser);
|
|
145
|
+
|
|
146
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
147
|
+
expect(body.redirect_to).toBe('/courses/my-course');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should prefer email over userId when both are provided', async () => {
|
|
151
|
+
const requestSpy = vi
|
|
152
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
153
|
+
.mockResolvedValue({
|
|
154
|
+
url: 'https://school.learnworlds.com/sso?token=both',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const params: SSOLoginParams = {
|
|
158
|
+
CompanyID: 'comp-1',
|
|
159
|
+
Email: 'both@example.com',
|
|
160
|
+
UserID: 'lw-user-both',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
await action.GenerateSSOUrl(params, contextUser);
|
|
164
|
+
|
|
165
|
+
// Email should be set, and since the code checks `if (params.Email)` first,
|
|
166
|
+
// user_id should NOT be set (it's in the else-if branch)
|
|
167
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
168
|
+
expect(body.email).toBe('both@example.com');
|
|
169
|
+
expect(body.user_id).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should propagate API errors', async () => {
|
|
173
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockRejectedValue(
|
|
174
|
+
new Error('LearnWorlds API error: 401 Unauthorized'),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const params: SSOLoginParams = {
|
|
178
|
+
CompanyID: 'comp-1',
|
|
179
|
+
Email: 'student@example.com',
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
await expect(action.GenerateSSOUrl(params, contextUser)).rejects.toThrow('LearnWorlds API error: 401 Unauthorized');
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('InternalRunAction()', () => {
|
|
187
|
+
it('should work via framework path', async () => {
|
|
188
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
189
|
+
url: 'https://school.learnworlds.com/sso?token=framework',
|
|
190
|
+
user_id: 'lw-user-fw',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const runParams = {
|
|
194
|
+
Params: [
|
|
195
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
196
|
+
{ Name: 'Email', Value: 'student@example.com', Type: 'Input' as const },
|
|
197
|
+
],
|
|
198
|
+
ContextUser: contextUser,
|
|
199
|
+
Action: {},
|
|
200
|
+
Filters: [],
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const result = await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
204
|
+
|
|
205
|
+
expect(result.Success).toBe(true);
|
|
206
|
+
expect(result.ResultCode).toBe('SUCCESS');
|
|
207
|
+
expect(result.Message).toContain('SSO URL generated successfully');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should set output params on success', async () => {
|
|
211
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue({
|
|
212
|
+
url: 'https://school.learnworlds.com/sso?token=output',
|
|
213
|
+
user_id: 'lw-user-out',
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const params = [
|
|
217
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
218
|
+
{ Name: 'Email', Value: 'student@example.com', Type: 'Input' as const },
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
const runParams = {
|
|
222
|
+
Params: params,
|
|
223
|
+
ContextUser: contextUser,
|
|
224
|
+
Action: {},
|
|
225
|
+
Filters: [],
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
229
|
+
|
|
230
|
+
const loginUrlParam = params.find((p) => p.Name === 'LoginURL');
|
|
231
|
+
const userIdParam = params.find((p) => p.Name === 'LearnWorldsUserID');
|
|
232
|
+
expect(loginUrlParam).toBeDefined();
|
|
233
|
+
expect(loginUrlParam?.Value).toBe('https://school.learnworlds.com/sso?token=output');
|
|
234
|
+
expect(userIdParam).toBeDefined();
|
|
235
|
+
expect(userIdParam?.Value).toBe('lw-user-out');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should return error when validation fails', async () => {
|
|
239
|
+
const runParams = {
|
|
240
|
+
Params: [
|
|
241
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
242
|
+
// Neither Email nor UserID provided
|
|
243
|
+
],
|
|
244
|
+
ContextUser: contextUser,
|
|
245
|
+
Action: {},
|
|
246
|
+
Filters: [],
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const result = await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
250
|
+
|
|
251
|
+
expect(result.Success).toBe(false);
|
|
252
|
+
expect(result.ResultCode).toBe('ERROR');
|
|
253
|
+
expect(result.Message).toContain('Either Email or UserID is required');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Mock dependencies (same pattern as lms.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
|
+
ActionResultSimple: class ActionResultSimple {
|
|
41
|
+
Success: boolean = false;
|
|
42
|
+
ResultCode: string = '';
|
|
43
|
+
Message: string = '';
|
|
44
|
+
Params?: Array<{ Name: string; Value: unknown; Type: string }>;
|
|
45
|
+
},
|
|
46
|
+
RunActionParams: class RunActionParams {
|
|
47
|
+
Params: Array<{ Name: string; Value: unknown; Type: string }> = [];
|
|
48
|
+
ContextUser: unknown = {};
|
|
49
|
+
Action: unknown = {};
|
|
50
|
+
Filters: unknown[] = [];
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
import { UpdateUserAction } from '../providers/learnworlds/actions/update-user.action';
|
|
55
|
+
import { UserInfo } from '@memberjunction/core';
|
|
56
|
+
import { UpdateUserParams, LWApiUser } from '../providers/learnworlds/interfaces';
|
|
57
|
+
|
|
58
|
+
/** Helper to build a mock UserInfo */
|
|
59
|
+
function mockContextUser(): UserInfo {
|
|
60
|
+
return { ID: 'user-1', Name: 'Test User', Email: 'test@example.com' } as unknown as UserInfo;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Helper to build a mock LW API user response */
|
|
64
|
+
function mockLWApiUserResponse(overrides: Partial<LWApiUser> = {}): LWApiUser {
|
|
65
|
+
return {
|
|
66
|
+
id: 'lw-user-1',
|
|
67
|
+
email: 'updated@example.com',
|
|
68
|
+
username: 'updateduser',
|
|
69
|
+
first_name: 'Updated',
|
|
70
|
+
last_name: 'User',
|
|
71
|
+
full_name: 'Updated User',
|
|
72
|
+
status: 'active',
|
|
73
|
+
role: 'student',
|
|
74
|
+
is_active: true,
|
|
75
|
+
created: '2024-01-01T00:00:00Z',
|
|
76
|
+
created_at: '2024-01-01T00:00:00Z',
|
|
77
|
+
tags: ['tag1'],
|
|
78
|
+
custom_fields: { level: 'senior' },
|
|
79
|
+
...overrides,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('UpdateUserAction', () => {
|
|
84
|
+
let action: UpdateUserAction;
|
|
85
|
+
const contextUser = mockContextUser();
|
|
86
|
+
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
action = new UpdateUserAction();
|
|
89
|
+
vi.restoreAllMocks();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('UpdateUser() typed method', () => {
|
|
93
|
+
it('should update user successfully', async () => {
|
|
94
|
+
const apiResponse = mockLWApiUserResponse();
|
|
95
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue(
|
|
96
|
+
apiResponse,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const params: UpdateUserParams = {
|
|
100
|
+
CompanyID: 'comp-1',
|
|
101
|
+
UserID: 'lw-user-1',
|
|
102
|
+
Email: 'updated@example.com',
|
|
103
|
+
FirstName: 'Updated',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const result = await action.UpdateUser(params, contextUser);
|
|
107
|
+
|
|
108
|
+
expect(result.UserDetails.id).toBe('lw-user-1');
|
|
109
|
+
expect(result.UserDetails.email).toBe('updated@example.com');
|
|
110
|
+
expect(result.UserDetails.firstName).toBe('Updated');
|
|
111
|
+
expect(result.UserDetails.status).toBe('active');
|
|
112
|
+
expect(result.Summary.userId).toBe('lw-user-1');
|
|
113
|
+
expect(result.Summary.email).toBe('updated@example.com');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should only send non-undefined fields', async () => {
|
|
117
|
+
const apiResponse = mockLWApiUserResponse();
|
|
118
|
+
const requestSpy = vi
|
|
119
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
120
|
+
.mockResolvedValue(apiResponse);
|
|
121
|
+
|
|
122
|
+
const params: UpdateUserParams = {
|
|
123
|
+
CompanyID: 'comp-1',
|
|
124
|
+
UserID: 'lw-user-1',
|
|
125
|
+
FirstName: 'OnlyFirst',
|
|
126
|
+
// Email, Username, Password, LastName, Role, IsActive, Tags, CustomFields all undefined
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
await action.UpdateUser(params, contextUser);
|
|
130
|
+
|
|
131
|
+
expect(requestSpy).toHaveBeenCalledTimes(1);
|
|
132
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
133
|
+
expect(body.first_name).toBe('OnlyFirst');
|
|
134
|
+
// These should NOT be in the body
|
|
135
|
+
expect(body.email).toBeUndefined();
|
|
136
|
+
expect(body.username).toBeUndefined();
|
|
137
|
+
expect(body.password).toBeUndefined();
|
|
138
|
+
expect(body.last_name).toBeUndefined();
|
|
139
|
+
expect(body.role).toBeUndefined();
|
|
140
|
+
expect(body.is_active).toBeUndefined();
|
|
141
|
+
expect(body.tags).toBeUndefined();
|
|
142
|
+
expect(body.custom_fields).toBeUndefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should track fields updated in summary', async () => {
|
|
146
|
+
const apiResponse = mockLWApiUserResponse();
|
|
147
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue(
|
|
148
|
+
apiResponse,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const params: UpdateUserParams = {
|
|
152
|
+
CompanyID: 'comp-1',
|
|
153
|
+
UserID: 'lw-user-1',
|
|
154
|
+
Email: 'new@example.com',
|
|
155
|
+
FirstName: 'Jane',
|
|
156
|
+
LastName: 'Smith',
|
|
157
|
+
Role: 'instructor',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const result = await action.UpdateUser(params, contextUser);
|
|
161
|
+
|
|
162
|
+
expect(result.Summary.fieldsUpdated).toContain('Email');
|
|
163
|
+
expect(result.Summary.fieldsUpdated).toContain('FirstName');
|
|
164
|
+
expect(result.Summary.fieldsUpdated).toContain('LastName');
|
|
165
|
+
expect(result.Summary.fieldsUpdated).toContain('Role');
|
|
166
|
+
expect(result.Summary.fieldsUpdated).toHaveLength(4);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should throw when UserID missing', async () => {
|
|
170
|
+
// buildUpdateBody needs at least one field to not throw "No fields"
|
|
171
|
+
// but the caller needs UserID - let's verify the API call uses UserID
|
|
172
|
+
const apiResponse = mockLWApiUserResponse();
|
|
173
|
+
const requestSpy = vi
|
|
174
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
175
|
+
.mockResolvedValue(apiResponse);
|
|
176
|
+
|
|
177
|
+
const params: UpdateUserParams = {
|
|
178
|
+
CompanyID: 'comp-1',
|
|
179
|
+
UserID: 'lw-user-1',
|
|
180
|
+
Email: 'new@example.com',
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
await action.UpdateUser(params, contextUser);
|
|
184
|
+
|
|
185
|
+
// Verify the endpoint included the UserID
|
|
186
|
+
expect(requestSpy.mock.calls[0][0]).toBe('users/lw-user-1');
|
|
187
|
+
expect(requestSpy.mock.calls[0][1]).toBe('PUT');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should throw when no fields provided to update', async () => {
|
|
191
|
+
const params: UpdateUserParams = {
|
|
192
|
+
CompanyID: 'comp-1',
|
|
193
|
+
UserID: 'lw-user-1',
|
|
194
|
+
// No updatable fields provided
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
await expect(action.UpdateUser(params, contextUser)).rejects.toThrow('No fields provided to update');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should map all update fields correctly to the API body', async () => {
|
|
201
|
+
const apiResponse = mockLWApiUserResponse();
|
|
202
|
+
const requestSpy = vi
|
|
203
|
+
.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest')
|
|
204
|
+
.mockResolvedValue(apiResponse);
|
|
205
|
+
|
|
206
|
+
const params: UpdateUserParams = {
|
|
207
|
+
CompanyID: 'comp-1',
|
|
208
|
+
UserID: 'lw-user-1',
|
|
209
|
+
Email: 'all@example.com',
|
|
210
|
+
Username: 'allfields',
|
|
211
|
+
Password: 'newpass',
|
|
212
|
+
FirstName: 'All',
|
|
213
|
+
LastName: 'Fields',
|
|
214
|
+
Role: 'Instructor',
|
|
215
|
+
IsActive: false,
|
|
216
|
+
Tags: ['new-tag', 'another-tag'],
|
|
217
|
+
CustomFields: { department: 'Sales', region: 'NA' },
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
await action.UpdateUser(params, contextUser);
|
|
221
|
+
|
|
222
|
+
const body = requestSpy.mock.calls[0][2] as Record<string, unknown>;
|
|
223
|
+
expect(body.email).toBe('all@example.com');
|
|
224
|
+
expect(body.username).toBe('allfields');
|
|
225
|
+
expect(body.password).toBe('newpass');
|
|
226
|
+
expect(body.first_name).toBe('All');
|
|
227
|
+
expect(body.last_name).toBe('Fields');
|
|
228
|
+
expect(body.role).toBe('instructor');
|
|
229
|
+
expect(body.is_active).toBe(false);
|
|
230
|
+
expect(body.tags).toEqual(['new-tag', 'another-tag']);
|
|
231
|
+
expect(body.custom_fields).toEqual({ department: 'Sales', region: 'NA' });
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should handle API user response with _id instead of id', async () => {
|
|
235
|
+
const apiResponse = mockLWApiUserResponse({ id: undefined, _id: 'mongo-id-123' });
|
|
236
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue(
|
|
237
|
+
apiResponse,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const params: UpdateUserParams = {
|
|
241
|
+
CompanyID: 'comp-1',
|
|
242
|
+
UserID: 'lw-user-1',
|
|
243
|
+
Email: 'mongo@example.com',
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const result = await action.UpdateUser(params, contextUser);
|
|
247
|
+
|
|
248
|
+
expect(result.UserDetails.id).toBe('mongo-id-123');
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('InternalRunAction()', () => {
|
|
253
|
+
it('should work via framework path', async () => {
|
|
254
|
+
const apiResponse = mockLWApiUserResponse();
|
|
255
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue(
|
|
256
|
+
apiResponse,
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const runParams = {
|
|
260
|
+
Params: [
|
|
261
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
262
|
+
{ Name: 'UserID', Value: 'lw-user-1', Type: 'Input' as const },
|
|
263
|
+
{ Name: 'Email', Value: 'updated@example.com', Type: 'Input' as const },
|
|
264
|
+
{ Name: 'FirstName', Value: 'Updated', Type: 'Input' as const },
|
|
265
|
+
],
|
|
266
|
+
ContextUser: contextUser,
|
|
267
|
+
Action: {},
|
|
268
|
+
Filters: [],
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const result = await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
272
|
+
|
|
273
|
+
expect(result.Success).toBe(true);
|
|
274
|
+
expect(result.ResultCode).toBe('SUCCESS');
|
|
275
|
+
expect(result.Message).toContain('Successfully updated user');
|
|
276
|
+
expect(result.Message).toContain('updated@example.com');
|
|
277
|
+
expect(result.Message).toContain('field(s) updated');
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('should return validation error when UserID is missing', async () => {
|
|
281
|
+
const runParams = {
|
|
282
|
+
Params: [
|
|
283
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
284
|
+
// No UserID
|
|
285
|
+
{ Name: 'Email', Value: 'new@example.com', Type: 'Input' as const },
|
|
286
|
+
],
|
|
287
|
+
ContextUser: contextUser,
|
|
288
|
+
Action: {},
|
|
289
|
+
Filters: [],
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const result = await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
293
|
+
|
|
294
|
+
expect(result.Success).toBe(false);
|
|
295
|
+
expect(result.ResultCode).toBe('ERROR');
|
|
296
|
+
expect(result.Message).toContain("'UserID'");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should return error when API call fails', async () => {
|
|
300
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockRejectedValue(
|
|
301
|
+
new Error('Server unavailable'),
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const runParams = {
|
|
305
|
+
Params: [
|
|
306
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
307
|
+
{ Name: 'UserID', Value: 'lw-user-1', Type: 'Input' as const },
|
|
308
|
+
{ Name: 'Email', Value: 'fail@example.com', Type: 'Input' as const },
|
|
309
|
+
],
|
|
310
|
+
ContextUser: contextUser,
|
|
311
|
+
Action: {},
|
|
312
|
+
Filters: [],
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const result = await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
316
|
+
|
|
317
|
+
expect(result.Success).toBe(false);
|
|
318
|
+
expect(result.ResultCode).toBe('ERROR');
|
|
319
|
+
expect(result.Message).toContain('Server unavailable');
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('should set output params on success', async () => {
|
|
323
|
+
const apiResponse = mockLWApiUserResponse();
|
|
324
|
+
vi.spyOn(action as unknown as { makeLearnWorldsRequest: (...args: unknown[]) => Promise<unknown> }, 'makeLearnWorldsRequest').mockResolvedValue(
|
|
325
|
+
apiResponse,
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
const params = [
|
|
329
|
+
{ Name: 'CompanyID', Value: 'comp-1', Type: 'Input' as const },
|
|
330
|
+
{ Name: 'UserID', Value: 'lw-user-1', Type: 'Input' as const },
|
|
331
|
+
{ Name: 'FirstName', Value: 'Updated', Type: 'Input' as const },
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
const runParams = {
|
|
335
|
+
Params: params,
|
|
336
|
+
ContextUser: contextUser,
|
|
337
|
+
Action: {},
|
|
338
|
+
Filters: [],
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
await action['InternalRunAction'](runParams as unknown as Parameters<(typeof action)['InternalRunAction']>[0]);
|
|
342
|
+
|
|
343
|
+
const userDetailsParam = params.find((p) => p.Name === 'UserDetails');
|
|
344
|
+
const summaryParam = params.find((p) => p.Name === 'Summary');
|
|
345
|
+
|
|
346
|
+
expect(userDetailsParam).toBeDefined();
|
|
347
|
+
expect(summaryParam).toBeDefined();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|