@scalekit-sdk/node 2.2.0 → 2.2.2
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/{reference.md → REFERENCE.md} +530 -77
- package/lib/core.js +1 -1
- package/package.json +9 -3
- package/.github/dependabot.yml +0 -10
- package/.nvmrc +0 -1
- package/buf.gen.yaml +0 -20
- package/jest.config.js +0 -15
- package/src/auth.ts +0 -99
- package/src/connect.ts +0 -32
- package/src/connection.ts +0 -267
- package/src/constants/user.ts +0 -22
- package/src/core.ts +0 -139
- package/src/directory.ts +0 -431
- package/src/domain.ts +0 -273
- package/src/errors/base-exception.ts +0 -263
- package/src/errors/index.ts +0 -3
- package/src/errors/specific-exceptions.ts +0 -88
- package/src/index.ts +0 -10
- package/src/organization.ts +0 -571
- package/src/passwordless.ts +0 -139
- package/src/permission.ts +0 -310
- package/src/pkg/grpc/buf/validate/validate_pb.ts +0 -28
- package/src/pkg/grpc/google/api/annotations_pb.ts +0 -28
- package/src/pkg/grpc/google/api/field_behavior_pb.ts +0 -28
- package/src/pkg/grpc/google/api/visibility_pb.ts +0 -28
- package/src/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.ts +0 -28
- package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -257
- package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -836
- package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -264
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -794
- package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -452
- package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -2645
- package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -1393
- package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -599
- package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -311
- package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -200
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1141
- package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -1491
- package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -497
- package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -1404
- package/src/role.ts +0 -463
- package/src/scalekit.ts +0 -800
- package/src/session.ts +0 -323
- package/src/types/auth.ts +0 -73
- package/src/types/organization.ts +0 -12
- package/src/types/scalekit.ts +0 -50
- package/src/types/user.ts +0 -21
- package/src/user.ts +0 -829
- package/src/webauthn.ts +0 -99
- package/tests/README.md +0 -25
- package/tests/connection.test.ts +0 -42
- package/tests/directory.test.ts +0 -46
- package/tests/domain.test.ts +0 -293
- package/tests/organization.test.ts +0 -81
- package/tests/passwordless.test.ts +0 -108
- package/tests/permission.test.ts +0 -399
- package/tests/role.test.ts +0 -323
- package/tests/scalekit.test.ts +0 -104
- package/tests/setup.ts +0 -34
- package/tests/users.test.ts +0 -168
- package/tests/utils/test-data.ts +0 -490
- package/tsconfig.json +0 -19
package/tests/role.test.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
3
|
-
import { TestDataGenerator, TestOrganizationManager, TestRoleManager } from './utils/test-data';
|
|
4
|
-
|
|
5
|
-
describe('Roles', () => {
|
|
6
|
-
let client: ScalekitClient;
|
|
7
|
-
let testOrg: string;
|
|
8
|
-
let testRoleName: string | null = null;
|
|
9
|
-
let testOrgRoleName: string | null = null;
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
// Use global client
|
|
13
|
-
client = global.client;
|
|
14
|
-
|
|
15
|
-
// Create test organization for each test
|
|
16
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(async () => {
|
|
20
|
-
// Clean up test resources
|
|
21
|
-
if (testRoleName) {
|
|
22
|
-
await TestRoleManager.cleanupTestRole(client, testRoleName);
|
|
23
|
-
testRoleName = null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (testOrgRoleName) {
|
|
27
|
-
await TestRoleManager.cleanupTestOrganizationRole(client, testOrg, testOrgRoleName);
|
|
28
|
-
testOrgRoleName = null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Clean up test organization
|
|
32
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('RoleClient', () => {
|
|
36
|
-
it('should have role client available', () => {
|
|
37
|
-
expect(client.role).toBeDefined();
|
|
38
|
-
expect(typeof client.role.createRole).toBe('function');
|
|
39
|
-
expect(typeof client.role.getRole).toBe('function');
|
|
40
|
-
expect(typeof client.role.listRoles).toBe('function');
|
|
41
|
-
expect(typeof client.role.updateRole).toBe('function');
|
|
42
|
-
expect(typeof client.role.deleteRole).toBe('function');
|
|
43
|
-
expect(typeof client.role.getRoleUsersCount).toBe('function');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should have organization role methods available', () => {
|
|
47
|
-
expect(typeof client.role.createOrganizationRole).toBe('function');
|
|
48
|
-
expect(typeof client.role.getOrganizationRole).toBe('function');
|
|
49
|
-
expect(typeof client.role.listOrganizationRoles).toBe('function');
|
|
50
|
-
expect(typeof client.role.updateOrganizationRole).toBe('function');
|
|
51
|
-
expect(typeof client.role.deleteOrganizationRole).toBe('function');
|
|
52
|
-
expect(typeof client.role.getOrganizationRoleUsersCount).toBe('function');
|
|
53
|
-
expect(typeof client.role.updateDefaultOrganizationRoles).toBe('function');
|
|
54
|
-
expect(typeof client.role.deleteOrganizationRoleBase).toBe('function');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('Role API Integration Tests', () => {
|
|
59
|
-
describe('createRole', () => {
|
|
60
|
-
it('should create a new role', async () => {
|
|
61
|
-
const roleData = TestDataGenerator.generateRoleData();
|
|
62
|
-
|
|
63
|
-
const response = await client.role.createRole(roleData);
|
|
64
|
-
|
|
65
|
-
expect(response).toBeDefined();
|
|
66
|
-
expect(response.role).toBeDefined();
|
|
67
|
-
expect(response.role?.name).toBe(roleData.name);
|
|
68
|
-
expect(response.role?.displayName).toBe(roleData.displayName);
|
|
69
|
-
expect(response.role?.description).toBe(roleData.description);
|
|
70
|
-
|
|
71
|
-
testRoleName = response.role?.name || null;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should throw error when role name is missing', async () => {
|
|
75
|
-
const roleData = TestDataGenerator.generateRoleData({ name: '' });
|
|
76
|
-
|
|
77
|
-
await expect(
|
|
78
|
-
client.role.createRole(roleData)
|
|
79
|
-
).rejects.toThrow();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('listRoles', () => {
|
|
84
|
-
it('should list all roles', async () => {
|
|
85
|
-
const response = await client.role.listRoles();
|
|
86
|
-
|
|
87
|
-
expect(response).toBeDefined();
|
|
88
|
-
expect(response.roles).toBeDefined();
|
|
89
|
-
expect(Array.isArray(response.roles)).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('getRole', () => {
|
|
94
|
-
it('should get role by name', async () => {
|
|
95
|
-
// Create a test role first
|
|
96
|
-
const roleData = TestDataGenerator.generateRoleData();
|
|
97
|
-
const createResponse = await client.role.createRole(roleData);
|
|
98
|
-
testRoleName = createResponse.role?.name || null;
|
|
99
|
-
|
|
100
|
-
const response = await client.role.getRole(testRoleName!);
|
|
101
|
-
|
|
102
|
-
expect(response).toBeDefined();
|
|
103
|
-
expect(response.role).toBeDefined();
|
|
104
|
-
expect(response.role?.name).toBe(testRoleName);
|
|
105
|
-
expect(response.role?.displayName).toBe(roleData.displayName);
|
|
106
|
-
expect(response.role?.description).toBe(roleData.description);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('should throw error when role does not exist', async () => {
|
|
110
|
-
await expect(
|
|
111
|
-
client.role.getRole('non-existent-role')
|
|
112
|
-
).rejects.toThrow();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('updateRole', () => {
|
|
117
|
-
it('should update an existing role', async () => {
|
|
118
|
-
// Create a test role first
|
|
119
|
-
const roleData = TestDataGenerator.generateRoleData();
|
|
120
|
-
const createResponse = await client.role.createRole(roleData);
|
|
121
|
-
testRoleName = createResponse.role?.name || null;
|
|
122
|
-
|
|
123
|
-
const updateData = TestDataGenerator.generateRoleUpdateData();
|
|
124
|
-
const response = await client.role.updateRole(testRoleName!, updateData);
|
|
125
|
-
|
|
126
|
-
expect(response).toBeDefined();
|
|
127
|
-
expect(response.role).toBeDefined();
|
|
128
|
-
expect(response.role?.name).toBe(testRoleName);
|
|
129
|
-
expect(response.role?.displayName).toBe(updateData.displayName);
|
|
130
|
-
expect(response.role?.description).toBe(updateData.description);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should throw error when updating non-existent role', async () => {
|
|
134
|
-
const updateData = TestDataGenerator.generateRoleUpdateData();
|
|
135
|
-
|
|
136
|
-
await expect(
|
|
137
|
-
client.role.updateRole('non-existent-role', updateData)
|
|
138
|
-
).rejects.toThrow();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('deleteRole', () => {
|
|
143
|
-
it('should delete an existing role', async () => {
|
|
144
|
-
// Create a test role first
|
|
145
|
-
const roleData = TestDataGenerator.generateRoleData();
|
|
146
|
-
const createResponse = await client.role.createRole(roleData);
|
|
147
|
-
const roleName = createResponse.role?.name || null;
|
|
148
|
-
|
|
149
|
-
const response = await client.role.deleteRole(roleName!);
|
|
150
|
-
|
|
151
|
-
expect(response).toBeDefined();
|
|
152
|
-
|
|
153
|
-
// Verify role is deleted
|
|
154
|
-
await expect(
|
|
155
|
-
client.role.getRole(roleName!)
|
|
156
|
-
).rejects.toThrow();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('getRoleUsersCount', () => {
|
|
161
|
-
it('should get user count for a role', async () => {
|
|
162
|
-
// Create a test role first
|
|
163
|
-
const roleData = TestDataGenerator.generateRoleData();
|
|
164
|
-
const createResponse = await client.role.createRole(roleData);
|
|
165
|
-
testRoleName = createResponse.role?.name || null;
|
|
166
|
-
|
|
167
|
-
const response = await client.role.getRoleUsersCount(testRoleName!);
|
|
168
|
-
|
|
169
|
-
expect(response).toBeDefined();
|
|
170
|
-
expect(Number(response.count)).toBeGreaterThanOrEqual(0);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('Organization Role API Integration Tests', () => {
|
|
176
|
-
describe('createOrganizationRole', () => {
|
|
177
|
-
it('should create a new organization role', async () => {
|
|
178
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
179
|
-
|
|
180
|
-
const response = await client.role.createOrganizationRole(testOrg, roleData);
|
|
181
|
-
|
|
182
|
-
expect(response).toBeDefined();
|
|
183
|
-
expect(response.role).toBeDefined();
|
|
184
|
-
expect(response.role?.name).toBe(roleData.name);
|
|
185
|
-
expect(response.role?.displayName).toBe(roleData.displayName);
|
|
186
|
-
expect(response.role?.description).toBe(roleData.description);
|
|
187
|
-
expect(response.role?.isOrgRole).toBe(true);
|
|
188
|
-
|
|
189
|
-
testOrgRoleName = response.role?.name || null;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('should throw error when organizationId is missing', async () => {
|
|
193
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
194
|
-
|
|
195
|
-
await expect(
|
|
196
|
-
client.role.createOrganizationRole('', roleData)
|
|
197
|
-
).rejects.toThrow();
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe('listOrganizationRoles', () => {
|
|
202
|
-
it('should list all organization roles', async () => {
|
|
203
|
-
// Create a test organization role first
|
|
204
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
205
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
206
|
-
testOrgRoleName = createResponse.role?.name || null;
|
|
207
|
-
|
|
208
|
-
const response = await client.role.listOrganizationRoles(testOrg);
|
|
209
|
-
|
|
210
|
-
expect(response).toBeDefined();
|
|
211
|
-
expect(response.roles).toBeDefined();
|
|
212
|
-
expect(Array.isArray(response.roles)).toBe(true);
|
|
213
|
-
expect(response.roles.length).toBeGreaterThan(0);
|
|
214
|
-
|
|
215
|
-
// Verify our test role is in the list
|
|
216
|
-
const testRole = response.roles.find(role => role.name === testOrgRoleName);
|
|
217
|
-
expect(testRole).toBeDefined();
|
|
218
|
-
expect(testRole?.isOrgRole).toBe(true);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe('getOrganizationRole', () => {
|
|
223
|
-
it('should get organization role by name', async () => {
|
|
224
|
-
// Create a test organization role first
|
|
225
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
226
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
227
|
-
testOrgRoleName = createResponse.role?.name || null;
|
|
228
|
-
|
|
229
|
-
const response = await client.role.getOrganizationRole(testOrg, testOrgRoleName!);
|
|
230
|
-
|
|
231
|
-
expect(response).toBeDefined();
|
|
232
|
-
expect(response.role).toBeDefined();
|
|
233
|
-
expect(response.role?.name).toBe(testOrgRoleName);
|
|
234
|
-
expect(response.role?.displayName).toBe(roleData.displayName);
|
|
235
|
-
expect(response.role?.isOrgRole).toBe(true);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe('updateOrganizationRole', () => {
|
|
240
|
-
it('should update an existing organization role', async () => {
|
|
241
|
-
// Create a test organization role first
|
|
242
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
243
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
244
|
-
testOrgRoleName = createResponse.role?.name || null;
|
|
245
|
-
|
|
246
|
-
const updateData = TestDataGenerator.generateRoleUpdateData();
|
|
247
|
-
const response = await client.role.updateOrganizationRole(testOrg, testOrgRoleName!, updateData);
|
|
248
|
-
|
|
249
|
-
expect(response).toBeDefined();
|
|
250
|
-
expect(response.role).toBeDefined();
|
|
251
|
-
expect(response.role?.name).toBe(testOrgRoleName);
|
|
252
|
-
expect(response.role?.displayName).toBe(updateData.displayName);
|
|
253
|
-
expect(response.role?.description).toBe(updateData.description);
|
|
254
|
-
expect(response.role?.isOrgRole).toBe(true);
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
describe('deleteOrganizationRole', () => {
|
|
259
|
-
it('should delete an existing organization role', async () => {
|
|
260
|
-
// Create a test organization role first
|
|
261
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
262
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
263
|
-
const roleName = createResponse.role?.name || null;
|
|
264
|
-
|
|
265
|
-
const response = await client.role.deleteOrganizationRole(testOrg, roleName!);
|
|
266
|
-
|
|
267
|
-
expect(response).toBeDefined();
|
|
268
|
-
|
|
269
|
-
// Verify role is deleted
|
|
270
|
-
await expect(
|
|
271
|
-
client.role.getOrganizationRole(testOrg, roleName!)
|
|
272
|
-
).rejects.toThrow();
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
describe('getOrganizationRoleUsersCount', () => {
|
|
277
|
-
it('should get user count for an organization role', async () => {
|
|
278
|
-
// Create a test organization role first
|
|
279
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
280
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
281
|
-
testOrgRoleName = createResponse.role?.name || null;
|
|
282
|
-
|
|
283
|
-
const response = await client.role.getOrganizationRoleUsersCount(testOrg, testOrgRoleName!);
|
|
284
|
-
|
|
285
|
-
expect(response).toBeDefined();
|
|
286
|
-
expect(Number(response.count)).toBeGreaterThanOrEqual(0);
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
describe('updateDefaultOrganizationRoles', () => {
|
|
291
|
-
it('should update default organization roles', async () => {
|
|
292
|
-
// Create a test organization role first
|
|
293
|
-
const roleData = TestDataGenerator.generateOrganizationRoleData();
|
|
294
|
-
const createResponse = await client.role.createOrganizationRole(testOrg, roleData);
|
|
295
|
-
testOrgRoleName = createResponse.role?.name || null;
|
|
296
|
-
|
|
297
|
-
const response = await client.role.updateDefaultOrganizationRoles(testOrg, testOrgRoleName!);
|
|
298
|
-
|
|
299
|
-
expect(response).toBeDefined();
|
|
300
|
-
expect(response.defaultMember).toBeDefined();
|
|
301
|
-
expect(response.defaultMember?.name).toBe(testOrgRoleName);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
describe('deleteOrganizationRoleBase', () => {
|
|
306
|
-
it('should delete organization role base relationship', async () => {
|
|
307
|
-
// Create base org role
|
|
308
|
-
const baseRoleData = TestDataGenerator.generateOrganizationRoleData();
|
|
309
|
-
const baseResp = await client.role.createOrganizationRole(testOrg, baseRoleData);
|
|
310
|
-
const baseRoleName = baseResp.role?.name!;
|
|
311
|
-
|
|
312
|
-
// Create extended org role which extends base
|
|
313
|
-
const extendedRoleData = TestDataGenerator.generateOrganizationRoleData({ extends: baseRoleName });
|
|
314
|
-
const extResp = await client.role.createOrganizationRole(testOrg, extendedRoleData);
|
|
315
|
-
testOrgRoleName = extResp.role?.name || null;
|
|
316
|
-
|
|
317
|
-
const response = await client.role.deleteOrganizationRoleBase(testOrg, testOrgRoleName!);
|
|
318
|
-
|
|
319
|
-
expect(response).toBeDefined();
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
});
|
package/tests/scalekit.test.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { AuthenticationOptions } from '../src/types/scalekit';
|
|
3
|
-
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
4
|
-
import { TestDataGenerator } from './utils/test-data';
|
|
5
|
-
|
|
6
|
-
describe('ScalekitClient', () => {
|
|
7
|
-
let client: ScalekitClient;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// Use global client
|
|
11
|
-
client = global.client;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('constructor', () => {
|
|
15
|
-
it('should initialize with correct parameters', () => {
|
|
16
|
-
expect(client).toBeInstanceOf(ScalekitClient);
|
|
17
|
-
expect(client.organization).toBeDefined();
|
|
18
|
-
expect(client.user).toBeDefined();
|
|
19
|
-
expect(client.connection).toBeDefined();
|
|
20
|
-
expect(client.directory).toBeDefined();
|
|
21
|
-
expect(client.passwordless).toBeDefined();
|
|
22
|
-
expect(client.domain).toBeDefined();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('getAuthorizationUrl', () => {
|
|
27
|
-
it('should generate authorization URL with basic parameters', () => {
|
|
28
|
-
const redirectUri = 'https://example.com/callback';
|
|
29
|
-
const url = client.getAuthorizationUrl(redirectUri);
|
|
30
|
-
|
|
31
|
-
expect(url).toContain('oauth/authorize');
|
|
32
|
-
expect(url).toContain(`redirect_uri=${encodeURIComponent(redirectUri)}`);
|
|
33
|
-
expect(url).toContain('response_type=code');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should include optional parameters when provided', () => {
|
|
37
|
-
const redirectUri = 'https://example.com/callback';
|
|
38
|
-
const options = TestDataGenerator.generateAuthorizationUrlOptions();
|
|
39
|
-
|
|
40
|
-
const url = client.getAuthorizationUrl(redirectUri, options);
|
|
41
|
-
|
|
42
|
-
expect(url).toContain('scope=openid%20profile');
|
|
43
|
-
expect(url).toContain('state=test-state');
|
|
44
|
-
expect(url).toContain('nonce=test-nonce');
|
|
45
|
-
expect(url).toContain('prompt=login');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should handle PKCE parameters', () => {
|
|
49
|
-
const redirectUri = 'https://example.com/callback';
|
|
50
|
-
const options = TestDataGenerator.generatePKCEParams();
|
|
51
|
-
|
|
52
|
-
const url = client.getAuthorizationUrl(redirectUri, options);
|
|
53
|
-
|
|
54
|
-
expect(url).toContain('code_challenge=test-challenge');
|
|
55
|
-
expect(url).toContain('code_challenge_method=S256');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('verifyWebhookPayload', () => {
|
|
60
|
-
it('should verify valid webhook payload', () => {
|
|
61
|
-
const webhookData = TestDataGenerator.generateWebhookData();
|
|
62
|
-
|
|
63
|
-
const result = client.verifyWebhookPayload(webhookData.secret, webhookData.headers, webhookData.payload);
|
|
64
|
-
expect(result).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should throw error for invalid signature', () => {
|
|
68
|
-
const webhookData = TestDataGenerator.generateWebhookData();
|
|
69
|
-
|
|
70
|
-
// Generate invalid signature using wrong payload data
|
|
71
|
-
const crypto = require('crypto');
|
|
72
|
-
const wrongData = `${webhookData.webhookId}.${webhookData.timestamp}.wrong-payload`;
|
|
73
|
-
const hmac = crypto.createHmac('sha256', Buffer.from('test-secret', 'base64'));
|
|
74
|
-
hmac.update(wrongData);
|
|
75
|
-
const wrongSignature = hmac.digest('base64');
|
|
76
|
-
const signature = `v1,${wrongSignature}`;
|
|
77
|
-
|
|
78
|
-
const headers = {
|
|
79
|
-
'webhook-id': webhookData.webhookId,
|
|
80
|
-
'webhook-timestamp': webhookData.timestamp,
|
|
81
|
-
'webhook-signature': signature
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
expect(() => {
|
|
85
|
-
client.verifyWebhookPayload(webhookData.secret, headers, webhookData.payload);
|
|
86
|
-
}).toThrow('Invalid Signature');
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('validateAccessToken', () => {
|
|
91
|
-
it('should validate access token', async () => {
|
|
92
|
-
// Mock token for testing - expected to fail
|
|
93
|
-
const token = 'mock-token';
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const result = await client.validateAccessToken(token);
|
|
97
|
-
expect(typeof result).toBe('boolean');
|
|
98
|
-
} catch (error) {
|
|
99
|
-
// Expected failure with mock token
|
|
100
|
-
expect(error).toBeDefined();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
package/tests/setup.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
|
|
4
|
-
// Import Jest globals
|
|
5
|
-
import { beforeAll } from '@jest/globals';
|
|
6
|
-
|
|
7
|
-
// Load environment variables
|
|
8
|
-
dotenv.config();
|
|
9
|
-
|
|
10
|
-
// Global test configuration
|
|
11
|
-
declare global {
|
|
12
|
-
var client: ScalekitClient;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
beforeAll(() => {
|
|
16
|
-
// Validate required environment variables
|
|
17
|
-
const environmentUrl = process.env.SCALEKIT_ENVIRONMENT_URL;
|
|
18
|
-
const clientId = process.env.SCALEKIT_CLIENT_ID;
|
|
19
|
-
const clientSecret = process.env.SCALEKIT_CLIENT_SECRET;
|
|
20
|
-
|
|
21
|
-
// Check for required environment variables
|
|
22
|
-
if (!environmentUrl) {
|
|
23
|
-
throw new Error('SCALEKIT_ENVIRONMENT_URL environment variable is required');
|
|
24
|
-
}
|
|
25
|
-
if (!clientId) {
|
|
26
|
-
throw new Error('SCALEKIT_CLIENT_ID environment variable is required');
|
|
27
|
-
}
|
|
28
|
-
if (!clientSecret) {
|
|
29
|
-
throw new Error('SCALEKIT_CLIENT_SECRET environment variable is required');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Initialize test client
|
|
33
|
-
global.client = new ScalekitClient(environmentUrl, clientId, clientSecret);
|
|
34
|
-
});
|
package/tests/users.test.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import ScalekitClient from '../src/scalekit';
|
|
2
|
-
import { CreateUserRequest, UpdateUserRequest } from '../src/types/user';
|
|
3
|
-
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
4
|
-
import { TestDataGenerator, TestOrganizationManager, TestUserManager } from './utils/test-data';
|
|
5
|
-
|
|
6
|
-
describe('Users', () => {
|
|
7
|
-
let client: ScalekitClient;
|
|
8
|
-
let testOrg: string;
|
|
9
|
-
let userId: string | null = null;
|
|
10
|
-
let sharedUserData: CreateUserRequest;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
// Use global client
|
|
14
|
-
client = global.client;
|
|
15
|
-
|
|
16
|
-
// Create test organization for each test
|
|
17
|
-
testOrg = await TestOrganizationManager.createTestOrganization(client);
|
|
18
|
-
|
|
19
|
-
// Create a shared user for testing
|
|
20
|
-
sharedUserData = TestDataGenerator.generateUserData();
|
|
21
|
-
const createResponse = await client.user.createUserAndMembership(testOrg, sharedUserData);
|
|
22
|
-
userId = createResponse.user?.id || null;
|
|
23
|
-
expect(userId).toBeDefined();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(async () => {
|
|
27
|
-
// Clean up test resources
|
|
28
|
-
if (userId) {
|
|
29
|
-
await TestUserManager.cleanupTestUser(client, testOrg, userId);
|
|
30
|
-
userId = null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Clean up test organization
|
|
34
|
-
await TestOrganizationManager.cleanupTestOrganization(client, testOrg);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('listOrganizationUsers', () => {
|
|
38
|
-
it('should list users by organization', async () => {
|
|
39
|
-
// List users in the organization
|
|
40
|
-
const usersList = await client.user.listOrganizationUsers(testOrg, TestDataGenerator.generatePaginationParams());
|
|
41
|
-
|
|
42
|
-
expect(usersList).toBeDefined();
|
|
43
|
-
expect(usersList.users).toBeDefined();
|
|
44
|
-
expect(Array.isArray(usersList.users)).toBe(true);
|
|
45
|
-
expect(usersList.users.length).toBeGreaterThan(0);
|
|
46
|
-
|
|
47
|
-
// Verify basic user attributes
|
|
48
|
-
const firstUser = usersList.users[0];
|
|
49
|
-
expect(firstUser.id).toBeDefined();
|
|
50
|
-
expect(firstUser.email).toBeDefined();
|
|
51
|
-
expect(firstUser.environmentId).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should handle pagination', async () => {
|
|
55
|
-
const firstPage = await client.user.listOrganizationUsers(testOrg, TestDataGenerator.generatePaginationParams(5));
|
|
56
|
-
|
|
57
|
-
expect(firstPage).toBeDefined();
|
|
58
|
-
expect(firstPage.users.length).toBeLessThanOrEqual(5);
|
|
59
|
-
|
|
60
|
-
if (firstPage.nextPageToken) {
|
|
61
|
-
const secondPage = await client.user.listOrganizationUsers(testOrg, {
|
|
62
|
-
pageSize: 5,
|
|
63
|
-
pageToken: firstPage.nextPageToken
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(secondPage).toBeDefined();
|
|
67
|
-
expect(secondPage.users).toBeDefined();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('getUser', () => {
|
|
73
|
-
it('should get user by ID', async () => {
|
|
74
|
-
// Retrieve the user by ID
|
|
75
|
-
const user = await client.user.getUser(userId!);
|
|
76
|
-
|
|
77
|
-
expect(user).toBeDefined();
|
|
78
|
-
expect(user.user).toBeDefined();
|
|
79
|
-
expect(user.user?.id).toBe(userId);
|
|
80
|
-
expect(user.user?.email).toBe(sharedUserData.email);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('createUserAndMembership', () => {
|
|
85
|
-
it('should create user and membership', async () => {
|
|
86
|
-
// Create a new user for this specific test
|
|
87
|
-
const userData = TestDataGenerator.generateUserData();
|
|
88
|
-
let newUserId: string | null = null;
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const response = await client.user.createUserAndMembership(testOrg, userData);
|
|
92
|
-
|
|
93
|
-
expect(response).toBeDefined();
|
|
94
|
-
expect(response.user).toBeDefined();
|
|
95
|
-
expect(response.user?.id).toBeDefined();
|
|
96
|
-
expect(response.user?.email).toBe(userData.email);
|
|
97
|
-
expect(response.user?.metadata?.source).toBe('test');
|
|
98
|
-
|
|
99
|
-
newUserId = response.user?.id || null;
|
|
100
|
-
} finally {
|
|
101
|
-
// Clean up the new user created in this test
|
|
102
|
-
if (newUserId) {
|
|
103
|
-
await TestUserManager.cleanupTestUser(client, testOrg, newUserId);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should throw error when email is missing', async () => {
|
|
109
|
-
const userData = TestDataGenerator.generateUserData({ email: '' }); // Empty email
|
|
110
|
-
|
|
111
|
-
await expect(
|
|
112
|
-
client.user.createUserAndMembership(testOrg, userData)
|
|
113
|
-
).rejects.toThrow('email is required');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should throw error when organizationId is missing', async () => {
|
|
117
|
-
const userData = TestDataGenerator.generateUserData({ email: 'test@example.com' });
|
|
118
|
-
|
|
119
|
-
await expect(
|
|
120
|
-
client.user.createUserAndMembership('', userData)
|
|
121
|
-
).rejects.toThrow('organizationId is required');
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('updateUser', () => {
|
|
126
|
-
it('should update user', async () => {
|
|
127
|
-
// Modify the shared user
|
|
128
|
-
const updateData = TestDataGenerator.generateUserUpdateData();
|
|
129
|
-
|
|
130
|
-
const updatedUser = await client.user.updateUser(userId!, updateData);
|
|
131
|
-
|
|
132
|
-
expect(updatedUser).toBeDefined();
|
|
133
|
-
expect(updatedUser.user).toBeDefined();
|
|
134
|
-
expect(updatedUser.user?.id).toBe(userId);
|
|
135
|
-
expect(updatedUser.user?.userProfile?.firstName).toBe('Updated');
|
|
136
|
-
expect(updatedUser.user?.userProfile?.lastName).toBe('Name');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('resendInvite', () => {
|
|
141
|
-
it('should resend invite to user', async () => {
|
|
142
|
-
// Resend invite to the shared user
|
|
143
|
-
const resendResponse = await client.user.resendInvite(testOrg, userId!);
|
|
144
|
-
|
|
145
|
-
// Verify the response structure
|
|
146
|
-
expect(resendResponse).toBeDefined();
|
|
147
|
-
expect(resendResponse.invite).toBeDefined();
|
|
148
|
-
expect(resendResponse.invite?.userId).toBe(userId);
|
|
149
|
-
expect(resendResponse.invite?.organizationId).toBe(testOrg);
|
|
150
|
-
expect(resendResponse.invite?.status).toBe('PENDING_INVITE');
|
|
151
|
-
expect(resendResponse.invite?.createdAt).toBeDefined();
|
|
152
|
-
expect(resendResponse.invite?.expiresAt).toBeDefined();
|
|
153
|
-
expect(resendResponse.invite?.resentCount).toBe(1);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should throw error when organizationId is missing', async () => {
|
|
157
|
-
await expect(
|
|
158
|
-
client.user.resendInvite('', userId!)
|
|
159
|
-
).rejects.toThrow('organizationId is required');
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should throw error when userId is missing', async () => {
|
|
163
|
-
await expect(
|
|
164
|
-
client.user.resendInvite(testOrg, '')
|
|
165
|
-
).rejects.toThrow('userId is required');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|