@go-mondo/identity-sdk 0.0.2-beta.74 → 0.0.2-beta.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/.tsbuildinfo/cjs.json +1 -1
  3. package/.tsbuildinfo/esm.json +1 -1
  4. package/CHANGELOG.md +14 -0
  5. package/dist/cjs/app/authorization/schema.d.ts +14 -23
  6. package/dist/cjs/app/authorization/schema.d.ts.map +1 -1
  7. package/dist/cjs/app/authorization/schema.js +5 -3
  8. package/dist/cjs/app/authorization/schema.test.js +26 -0
  9. package/dist/cjs/common/schema/jwt.d.ts +0 -6
  10. package/dist/cjs/common/schema/jwt.d.ts.map +1 -1
  11. package/dist/cjs/common/schema/jwt.js +0 -3
  12. package/dist/cjs/common/schema/jwt.test.js +0 -8
  13. package/dist/cjs/workspace/authorization/schema.d.ts +0 -9
  14. package/dist/cjs/workspace/authorization/schema.d.ts.map +1 -1
  15. package/dist/esm/app/authorization/schema.d.ts +14 -23
  16. package/dist/esm/app/authorization/schema.d.ts.map +1 -1
  17. package/dist/esm/app/authorization/schema.js +5 -3
  18. package/dist/esm/app/authorization/schema.test.js +26 -0
  19. package/dist/esm/common/schema/jwt.d.ts +0 -6
  20. package/dist/esm/common/schema/jwt.d.ts.map +1 -1
  21. package/dist/esm/common/schema/jwt.js +0 -3
  22. package/dist/esm/common/schema/jwt.test.js +0 -8
  23. package/dist/esm/workspace/authorization/schema.d.ts +0 -9
  24. package/dist/esm/workspace/authorization/schema.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/action/schema/operations/sign-up-verification.test.ts.bak +0 -163
  27. package/src/action/schema/operations/sign-up.test.ts.bak +0 -203
  28. package/src/action/schema/operations/user-attribute-verification.test.ts.bak +0 -148
  29. package/src/activity/schema/base.test.ts.bak +0 -291
  30. package/src/activity/schema/schema.test.ts.bak +0 -392
  31. package/src/activity/schema/types/authentication.test.ts.bak +0 -337
  32. package/src/activity/schema/types/authorization.test.ts.bak +0 -379
  33. package/src/activity/schema/types/note.test.ts.bak +0 -367
  34. package/src/activity/schema/types/operation.test.ts.bak +0 -379
  35. package/src/activity/schema/types/unknown.test.ts.bak +0 -304
  36. package/src/app/authorization/schema.test.ts.bak +0 -412
  37. package/src/app/oidc/schema.test.ts.bak +0 -117
  38. package/src/app/registration/schema.test.ts.bak +0 -308
  39. package/src/app/schema.test.ts.bak +0 -221
  40. package/src/association/schema.test.ts.bak +0 -148
  41. package/src/authentication/factors/schema.test.ts.bak +0 -174
  42. package/src/authentication/settings/schema.test.ts.bak +0 -91
  43. package/src/authorization/permissions/schema.test.ts.bak +0 -267
  44. package/src/authorization/roles/schema.test.ts.bak +0 -283
  45. package/src/common/schema/aggregate.test.ts.bak +0 -89
  46. package/src/common/schema/collection.test.ts.bak +0 -116
  47. package/src/common/schema/dates.test.ts.bak +0 -49
  48. package/src/common/schema/id.test.ts.bak +0 -149
  49. package/src/common/schema/jwt.test.ts.bak +0 -61
  50. package/src/common/schema/metadata.test.ts.bak +0 -141
  51. package/src/common/schema/pagination.test.ts.bak +0 -80
  52. package/src/common/schema/schema.test.ts.bak +0 -41
  53. package/src/customer/users/schema.test.ts.bak +0 -138
  54. package/src/identity/schema.test.ts.bak +0 -48
  55. package/src/oauth/token/schema/schema.test.ts.bak +0 -142
  56. package/src/workspace/settings/schema.test.ts.bak +0 -88
@@ -1,283 +0,0 @@
1
- import { type } from 'arktype';
2
- import { describe, expect, test } from 'vitest';
3
- import { generateAppId } from '../../app/utils.js';
4
- import { generateUserId } from '../../customer/schema.js';
5
- import { generatePermissionId, generateRoleId } from '../schema.js';
6
- import {
7
- type InsertRolePayload,
8
- InsertRolePayloadSchema,
9
- type RoleAssociationReference,
10
- RoleAssociationReferenceSchema,
11
- RoleAssociationsSchema,
12
- RoleIdPropertySchema,
13
- RoleSchema,
14
- RoleStatus,
15
- UpdateRolePayloadSchema,
16
- } from './schema.js';
17
-
18
- describe('Authorization Roles - Schema', () => {
19
- describe('RoleStatus constants', () => {
20
- test('should have correct status values', () => {
21
- expect(RoleStatus.ENABLED).toBe('enabled');
22
- expect(RoleStatus.DISABLED).toBe('disabled');
23
- });
24
- });
25
-
26
- describe('RoleIdPropertySchema', () => {
27
- test('should accept valid id property', () => {
28
- const payload = { id: generateRoleId() };
29
- const result = RoleIdPropertySchema(payload);
30
- expect(result).not.toBeInstanceOf(type.errors);
31
- expect(result).toEqual({ id: payload.id });
32
- });
33
-
34
- test('should reject missing id', () => {
35
- const result = RoleIdPropertySchema({});
36
- expect(result).toBeInstanceOf(type.errors);
37
- });
38
- });
39
-
40
- describe('RoleAssociationsSchema', () => {
41
- test('should accept valid associations', () => {
42
- const payload = {
43
- apps: [generateAppId(), generateAppId()],
44
- permissions: [generatePermissionId(), generatePermissionId()],
45
- users: [generateUserId(), generateUserId()],
46
- };
47
-
48
- const result = RoleAssociationsSchema(payload);
49
- expect(result).not.toBeInstanceOf(type.errors);
50
- expect(result).toEqual({
51
- apps: payload.apps,
52
- permissions: payload.permissions,
53
- users: payload.users,
54
- });
55
- });
56
-
57
- test('should accept optional associations', () => {
58
- const result = RoleAssociationsSchema({});
59
- expect(result).not.toBeInstanceOf(type.errors);
60
- expect(result).toEqual({});
61
- });
62
-
63
- test('should accept partial associations', () => {
64
- const result = RoleAssociationsSchema({
65
- permissions: [generatePermissionId()],
66
- users: undefined,
67
- });
68
- expect(result).not.toBeInstanceOf(type.errors);
69
- });
70
-
71
- test('should reject non-array associations', () => {
72
- const result = RoleAssociationsSchema({
73
- apps: 'not-an-array',
74
- });
75
- expect(result).toBeInstanceOf(type.errors);
76
- });
77
- });
78
-
79
- describe('RoleSchema', () => {
80
- test('should accept complete role object', () => {
81
- const role = {
82
- id: generateRoleId(),
83
- name: 'admin',
84
- status: 'enabled' as const,
85
- description: 'Administrator role',
86
- apps: { ids: [generateAppId()], count: 1 },
87
- users: { ids: [generateUserId()], count: 1 },
88
- permissions: { ids: [generatePermissionId()], count: 1 },
89
- createdAt: new Date(),
90
- updatedAt: new Date(),
91
- metadata: { key: 'value' },
92
- };
93
-
94
- const result = RoleSchema(role);
95
- expect(result).not.toBeInstanceOf(type.errors);
96
- });
97
-
98
- test('should accept minimal role object', () => {
99
- const role = {
100
- id: generateRoleId(),
101
- name: 'user',
102
- status: 'enabled' as const,
103
- createdAt: new Date(),
104
- updatedAt: new Date(),
105
- metadata: {},
106
- };
107
-
108
- const result = RoleSchema(role);
109
- expect(result).not.toBeInstanceOf(type.errors);
110
- });
111
-
112
- test('should accept role with optional dates', () => {
113
- const role = {
114
- id: generateRoleId(),
115
- name: 'user',
116
- status: 'disabled' as const,
117
- createdAt: new Date(),
118
- updatedAt: new Date(),
119
- deletedAt: new Date(),
120
- deactivatedAt: new Date(),
121
- metadata: {},
122
- };
123
-
124
- const result = RoleSchema(role);
125
- expect(result).not.toBeInstanceOf(type.errors);
126
- });
127
-
128
- test('should reject invalid status', () => {
129
- const role = {
130
- id: generateRoleId(),
131
- name: 'admin',
132
- status: 'invalid',
133
- createdAt: new Date(),
134
- updatedAt: new Date(),
135
- metadata: {},
136
- };
137
-
138
- const result = RoleSchema(role);
139
- expect(result).toBeInstanceOf(type.errors);
140
- });
141
-
142
- test('should reject missing required fields', () => {
143
- const role = {
144
- id: generateRoleId(),
145
- name: 'admin',
146
- };
147
-
148
- const result = RoleSchema(role);
149
- expect(result).toBeInstanceOf(type.errors);
150
- });
151
- });
152
-
153
- describe('InsertRolePayloadSchema', () => {
154
- test('should accept complete insert payload', () => {
155
- const payload = {
156
- id: generateRoleId(),
157
- name: 'admin',
158
- status: 'enabled' as const,
159
- description: 'Administrator role',
160
- apps: [generateAppId()],
161
- permissions: [generatePermissionId()],
162
- users: [generateUserId()],
163
- metadata: { key: 'value' },
164
- };
165
-
166
- const result = InsertRolePayloadSchema(payload);
167
- expect(result).not.toBeInstanceOf(type.errors);
168
- });
169
-
170
- test('should accept minimal insert payload', () => {
171
- const payload = {
172
- name: 'user',
173
- };
174
-
175
- const result = InsertRolePayloadSchema(payload);
176
- expect(result).not.toBeInstanceOf(type.errors);
177
- expect((result as InsertRolePayload).status).toBe('enabled'); // default value
178
- });
179
-
180
- test('should generate default ID when not provided', () => {
181
- const payload = { name: 'admin' };
182
- const result = InsertRolePayloadSchema(payload);
183
-
184
- expect(result).not.toBeInstanceOf(type.errors);
185
- expect((result as InsertRolePayload).id).toMatch(/^rol_/);
186
- });
187
-
188
- test('should reject missing name', () => {
189
- const result = InsertRolePayloadSchema({});
190
- expect(result).toBeInstanceOf(type.errors);
191
- });
192
-
193
- test('should accept associations in insert payload', () => {
194
- const payload = {
195
- name: 'moderator',
196
- apps: [generateAppId(), generateAppId()],
197
- permissions: [generatePermissionId(), generatePermissionId()],
198
- users: [generateUserId()],
199
- };
200
-
201
- const result = InsertRolePayloadSchema(payload);
202
- expect(result).not.toBeInstanceOf(type.errors);
203
- });
204
- });
205
-
206
- describe('UpdateRolePayloadSchema', () => {
207
- test('should accept all optional fields', () => {
208
- const payload = {
209
- name: 'updated-role',
210
- status: 'disabled' as const,
211
- description: 'Updated description',
212
- metadata: { updated: true },
213
- };
214
-
215
- const result = UpdateRolePayloadSchema(payload);
216
- expect(result).not.toBeInstanceOf(type.errors);
217
- expect(result).toEqual(payload);
218
- });
219
-
220
- test('should accept empty update payload', () => {
221
- const result = UpdateRolePayloadSchema({});
222
- expect(result).not.toBeInstanceOf(type.errors);
223
- expect(result).toEqual({});
224
- });
225
-
226
- test('should accept partial updates', () => {
227
- const payload = { name: 'new-name' };
228
- const result = UpdateRolePayloadSchema(payload);
229
- expect(result).not.toBeInstanceOf(type.errors);
230
- expect(result).toEqual(payload);
231
- });
232
-
233
- test('should reject invalid status', () => {
234
- const payload = { status: 'invalid-status' };
235
- const result = UpdateRolePayloadSchema(payload);
236
- expect(result).toBeInstanceOf(type.errors);
237
- });
238
- });
239
-
240
- describe('RoleAssociationReferenceSchema', () => {
241
- test('should accept complete association reference', () => {
242
- const reference = {
243
- id: generateRoleId(),
244
- name: 'admin',
245
- status: 'enabled' as const,
246
- model: 'Role' as const,
247
- };
248
-
249
- const result = RoleAssociationReferenceSchema(reference);
250
- expect(result).not.toBeInstanceOf(type.errors);
251
- expect(result).toEqual(reference);
252
- });
253
-
254
- test('should use default status when not provided', () => {
255
- const reference = {
256
- id: generateRoleId(),
257
- name: 'admin',
258
- model: 'Role' as const,
259
- };
260
-
261
- const result = RoleAssociationReferenceSchema(reference);
262
- expect(result).not.toBeInstanceOf(type.errors);
263
- expect((result as RoleAssociationReference).status).toBe('disabled'); // default value
264
- });
265
-
266
- test('should reject missing required fields', () => {
267
- const reference = { id: generateRoleId() };
268
- const result = RoleAssociationReferenceSchema(reference);
269
- expect(result).toBeInstanceOf(type.errors);
270
- });
271
-
272
- test('should reject invalid model value', () => {
273
- const reference = {
274
- id: generateRoleId(),
275
- name: 'admin',
276
- model: 'InvalidModel',
277
- };
278
-
279
- const result = RoleAssociationReferenceSchema(reference);
280
- expect(result).toBeInstanceOf(type.errors);
281
- });
282
- });
283
- });
@@ -1,89 +0,0 @@
1
- import { type } from 'arktype';
2
- import { describe, expect, test } from 'vitest';
3
- import { AggregateSchema } from './aggregate.js';
4
-
5
- describe('Common Schema - Aggregate', () => {
6
- describe('AggregateSchema', () => {
7
- test('should accept valid aggregate with ids and count', () => {
8
- const result = AggregateSchema({
9
- ids: ['id1', 'id2', 'id3'],
10
- count: 25,
11
- });
12
-
13
- expect(result).not.toBeInstanceOf(type.errors);
14
- expect(result).toEqual({
15
- ids: ['id1', 'id2', 'id3'],
16
- count: 25,
17
- });
18
- });
19
-
20
- test('should accept aggregate with only ids', () => {
21
- const result = AggregateSchema({
22
- ids: ['id1', 'id2'],
23
- });
24
-
25
- expect(result).not.toBeInstanceOf(type.errors);
26
- expect(result).toEqual({
27
- ids: ['id1', 'id2'],
28
- });
29
- });
30
-
31
- test('should accept aggregate with only count', () => {
32
- const result = AggregateSchema({
33
- count: 42,
34
- });
35
-
36
- expect(result).not.toBeInstanceOf(type.errors);
37
- expect(result).toEqual({
38
- count: 42,
39
- });
40
- });
41
-
42
- test('should accept empty aggregate', () => {
43
- const result = AggregateSchema({});
44
-
45
- expect(result).not.toBeInstanceOf(type.errors);
46
- expect(result).toEqual({});
47
- });
48
-
49
- test('should accept aggregate with empty ids array', () => {
50
- const result = AggregateSchema({
51
- ids: [],
52
- count: 0,
53
- });
54
-
55
- expect(result).not.toBeInstanceOf(type.errors);
56
- expect(result).toEqual({
57
- ids: [],
58
- count: 0,
59
- });
60
- });
61
-
62
- test('should reject invalid ids type', () => {
63
- const result = AggregateSchema({
64
- ids: 'not-an-array',
65
- count: 10,
66
- });
67
-
68
- expect(result).toBeInstanceOf(type.errors);
69
- });
70
-
71
- test('should reject invalid count type', () => {
72
- const result = AggregateSchema({
73
- ids: ['id1'],
74
- count: 'not-a-number',
75
- });
76
-
77
- expect(result).toBeInstanceOf(type.errors);
78
- });
79
-
80
- test('should reject non-string items in ids array', () => {
81
- const result = AggregateSchema({
82
- ids: ['id1', 123, 'id3'],
83
- count: 3,
84
- });
85
-
86
- expect(result).toBeInstanceOf(type.errors);
87
- });
88
- });
89
- });
@@ -1,116 +0,0 @@
1
- import { type } from 'arktype';
2
- import { describe, expect, test } from 'vitest';
3
- import { CollectionSchema, PaginationCollectionSchema } from './collection.js';
4
-
5
- describe('Common Schema - Collection', () => {
6
- describe('CollectionSchema', () => {
7
- test('should accept valid collection with string items', () => {
8
- const StringCollectionSchema = CollectionSchema('string');
9
- const result = StringCollectionSchema({
10
- items: ['item1', 'item2', 'item3'],
11
- });
12
-
13
- expect(result).not.toBeInstanceOf(type.errors);
14
- expect(result).toEqual({
15
- items: ['item1', 'item2', 'item3'],
16
- });
17
- });
18
-
19
- test('should accept valid collection with number items', () => {
20
- const NumberCollectionSchema = CollectionSchema('number');
21
- const result = NumberCollectionSchema({
22
- items: [1, 2, 3],
23
- });
24
-
25
- expect(result).not.toBeInstanceOf(type.errors);
26
- expect(result).toEqual({
27
- items: [1, 2, 3],
28
- });
29
- });
30
-
31
- test('should accept empty collection', () => {
32
- const StringCollectionSchema = CollectionSchema('string');
33
- const result = StringCollectionSchema({
34
- items: [],
35
- });
36
-
37
- expect(result).not.toBeInstanceOf(type.errors);
38
- expect(result).toEqual({
39
- items: [],
40
- });
41
- });
42
-
43
- test('should reject invalid items type', () => {
44
- const StringCollectionSchema = CollectionSchema('string');
45
- const result = StringCollectionSchema({
46
- items: 'not-an-array',
47
- });
48
-
49
- expect(result).toBeInstanceOf(type.errors);
50
- });
51
- });
52
-
53
- describe('PaginationCollectionSchema', () => {
54
- test('should accept valid paginated collection', () => {
55
- const StringPaginationCollectionSchema =
56
- PaginationCollectionSchema('string');
57
- const result = StringPaginationCollectionSchema({
58
- items: ['item1', 'item2'],
59
- pagination: {
60
- pageSize: '10',
61
- nextToken: 'token123',
62
- },
63
- });
64
-
65
- expect(result).not.toBeInstanceOf(type.errors);
66
- expect(result).toEqual({
67
- items: ['item1', 'item2'],
68
- pagination: {
69
- pageSize: '10',
70
- nextToken: 'token123',
71
- },
72
- });
73
- });
74
-
75
- test('should accept collection without pagination', () => {
76
- const StringPaginationCollectionSchema =
77
- PaginationCollectionSchema('string');
78
- const result = StringPaginationCollectionSchema({
79
- items: ['item1', 'item2'],
80
- });
81
-
82
- expect(result).not.toBeInstanceOf(type.errors);
83
- expect(result).toEqual({
84
- items: ['item1', 'item2'],
85
- });
86
- });
87
-
88
- test('should accept collection with empty pagination', () => {
89
- const StringPaginationCollectionSchema =
90
- PaginationCollectionSchema('string');
91
- const result = StringPaginationCollectionSchema({
92
- items: ['item1'],
93
- pagination: {},
94
- });
95
-
96
- expect(result).not.toBeInstanceOf(type.errors);
97
- expect(result).toEqual({
98
- items: ['item1'],
99
- pagination: {},
100
- });
101
- });
102
-
103
- test('should reject invalid pagination', () => {
104
- const StringPaginationCollectionSchema =
105
- PaginationCollectionSchema('string');
106
- const result = StringPaginationCollectionSchema({
107
- items: ['item1'],
108
- pagination: {
109
- pageSize: true,
110
- },
111
- });
112
-
113
- expect(result).toBeInstanceOf(type.errors);
114
- });
115
- });
116
- });
@@ -1,49 +0,0 @@
1
- import { type } from 'arktype';
2
- import { describe, expect, test } from 'vitest';
3
- import { RequiredDatePayloadSchema, RequiredDateSchema } from './dates.js';
4
-
5
- describe('Common - Dates', () => {
6
- describe('Date Schema', () => {
7
- test('should accept an iso string', async () => {
8
- const result = RequiredDateSchema(
9
- new Date().toISOString()
10
- ) as typeof RequiredDateSchema.inferOut;
11
-
12
- expect(result).not.toBeInstanceOf(type.errors);
13
- expect(result).toBeInstanceOf(Date);
14
- });
15
-
16
- test('should accept a Date object', async () => {
17
- const result = RequiredDateSchema(
18
- new Date()
19
- ) as typeof RequiredDateSchema.inferOut;
20
-
21
- expect(result).not.toBeInstanceOf(type.errors);
22
- expect(result).toBeInstanceOf(Date);
23
- });
24
- });
25
-
26
- describe('Payload Schema', () => {
27
- test('should parse a Date to an ISO string', async () => {
28
- const iso = new Date().toISOString();
29
-
30
- const result = RequiredDatePayloadSchema(
31
- new Date(iso)
32
- ) as typeof RequiredDatePayloadSchema.inferOut;
33
-
34
- expect(result).not.toBeInstanceOf(type.errors);
35
- expect(result).to.equal(iso);
36
- });
37
-
38
- test('should parse an ISO to an ISO string', async () => {
39
- const iso = new Date().toISOString();
40
-
41
- const result = RequiredDatePayloadSchema(
42
- iso
43
- ) as typeof RequiredDatePayloadSchema.inferOut;
44
-
45
- expect(result).not.toBeInstanceOf(type.errors);
46
- expect(result).to.equal(iso);
47
- });
48
- });
49
- });
@@ -1,149 +0,0 @@
1
- import { type } from 'arktype';
2
- import { describe, expect, test } from 'vitest';
3
- import { KSUIDSchema } from './id.js';
4
-
5
- describe('Common Schema - ID', () => {
6
- describe('KSUIDSchema', () => {
7
- test('should accept valid KSUID with correct prefix', () => {
8
- const schema = KSUIDSchema('usr');
9
- const validId = 'usr_123456789012345678901234567';
10
-
11
- const result = schema(validId);
12
- expect(result).toBe(validId);
13
- });
14
-
15
- test('should accept KSUID with different prefixes', () => {
16
- const userSchema = KSUIDSchema('usr');
17
- const appSchema = KSUIDSchema('app');
18
- const activitySchema = KSUIDSchema('act');
19
-
20
- const userId = 'usr_abcdefghijklmnopqrstuvwxy12';
21
- const appId = 'app_1234567890ABCDEFGHIJKLMNOP1';
22
- const activityId = 'act_abcDEF123456789012345678901';
23
-
24
- expect(userSchema(userId)).toBe(userId);
25
- expect(appSchema(appId)).toBe(appId);
26
- expect(activitySchema(activityId)).toBe(activityId);
27
- });
28
-
29
- test('should accept KSUID with mixed alphanumeric characters', () => {
30
- const schema = KSUIDSchema('test');
31
- const mixedId = 'test_1a2B3c4D5e6F7g8H9i0JkLmNoPq';
32
-
33
- const result = schema(mixedId);
34
- expect(result).toBe(mixedId);
35
- });
36
-
37
- test('should reject KSUID with wrong prefix', () => {
38
- const schema = KSUIDSchema('usr');
39
- const wrongPrefixId = 'app_123456789012345678901234567';
40
-
41
- const result = schema(wrongPrefixId);
42
- expect(result).toBeInstanceOf(type.errors);
43
- });
44
-
45
- test('should reject KSUID with missing prefix', () => {
46
- const schema = KSUIDSchema('usr');
47
- const noPrefixId = '123456789012345678901234567';
48
-
49
- const result = schema(noPrefixId);
50
- expect(result).toBeInstanceOf(type.errors);
51
- });
52
-
53
- test('should reject KSUID with missing underscore', () => {
54
- const schema = KSUIDSchema('usr');
55
- const noUnderscoreId = 'usr123456789012345678901234567';
56
-
57
- const result = schema(noUnderscoreId);
58
- expect(result).toBeInstanceOf(type.errors);
59
- });
60
-
61
- test('should reject KSUID with incorrect suffix length (too short)', () => {
62
- const schema = KSUIDSchema('usr');
63
- const shortId = 'usr_12345678901234567890123456';
64
-
65
- const result = schema(shortId);
66
- expect(result).toBeInstanceOf(type.errors);
67
- });
68
-
69
- test('should reject KSUID with incorrect suffix length (too long)', () => {
70
- const schema = KSUIDSchema('usr');
71
- const longId = 'usr_1234567890123456789012345678';
72
-
73
- const result = schema(longId);
74
- expect(result).toBeInstanceOf(type.errors);
75
- });
76
-
77
- test('should reject KSUID with invalid characters in suffix', () => {
78
- const schema = KSUIDSchema('usr');
79
- const invalidCharsId = 'usr_123456789012345678901234_*';
80
-
81
- const result = schema(invalidCharsId);
82
- expect(result).toBeInstanceOf(type.errors);
83
- });
84
-
85
- test('should reject KSUID with special characters in suffix', () => {
86
- const schema = KSUIDSchema('usr');
87
- const specialCharsId = 'usr_12345678901234567890123456@';
88
-
89
- const result = schema(specialCharsId);
90
- expect(result).toBeInstanceOf(type.errors);
91
- });
92
-
93
- test('should reject KSUID with spaces', () => {
94
- const schema = KSUIDSchema('usr');
95
- const spaceId = 'usr_1234567890123456789012345 7';
96
-
97
- const result = schema(spaceId);
98
- expect(result).toBeInstanceOf(type.errors);
99
- });
100
-
101
- test('should reject empty string', () => {
102
- const schema = KSUIDSchema('usr');
103
-
104
- const result = schema('');
105
- expect(result).toBeInstanceOf(type.errors);
106
- });
107
-
108
- test('should reject non-string values', () => {
109
- const schema = KSUIDSchema('usr');
110
-
111
- expect(schema(123)).toBeInstanceOf(type.errors);
112
- expect(schema(null)).toBeInstanceOf(type.errors);
113
- expect(schema(undefined)).toBeInstanceOf(type.errors);
114
- expect(schema({})).toBeInstanceOf(type.errors);
115
- });
116
-
117
- test('should work with complex prefixes', () => {
118
- const complexSchema = KSUIDSchema('app_config');
119
- const validComplexId = 'app_config_123456789012345678901234567';
120
-
121
- const result = complexSchema(validComplexId);
122
- expect(result).toBe(validComplexId);
123
- });
124
-
125
- test('should work with single character prefix', () => {
126
- const singleCharSchema = KSUIDSchema('a');
127
- const validSingleCharId = 'a_123456789012345678901234567';
128
-
129
- const result = singleCharSchema(validSingleCharId);
130
- expect(result).toBe(validSingleCharId);
131
- });
132
-
133
- test('should create different schemas for different prefixes', () => {
134
- const userSchema = KSUIDSchema('usr');
135
- const orgSchema = KSUIDSchema('org');
136
-
137
- const userId = 'usr_123456789012345678901234567';
138
- const orgId = 'org_123456789012345678901234567';
139
-
140
- // User schema should accept user ID but reject org ID
141
- expect(userSchema(userId)).toBe(userId);
142
- expect(userSchema(orgId)).toBeInstanceOf(type.errors);
143
-
144
- // Org schema should accept org ID but reject user ID
145
- expect(orgSchema(orgId)).toBe(orgId);
146
- expect(orgSchema(userId)).toBeInstanceOf(type.errors);
147
- });
148
- });
149
- });