tuturuuu 0.0.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.
@@ -0,0 +1,562 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ createDocumentDataSchema,
4
+ listDocumentsOptionsSchema,
5
+ listStorageOptionsSchema,
6
+ shareOptionsSchema,
7
+ updateDocumentDataSchema,
8
+ uploadOptionsSchema,
9
+ } from './types';
10
+
11
+ describe('listStorageOptionsSchema', () => {
12
+ it('should validate empty options', () => {
13
+ const result = listStorageOptionsSchema.parse({});
14
+ expect(result).toEqual({});
15
+ });
16
+
17
+ it('should validate path option', () => {
18
+ const result = listStorageOptionsSchema.parse({ path: 'documents' });
19
+ expect(result.path).toBe('documents');
20
+ });
21
+
22
+ it('should validate search option', () => {
23
+ const result = listStorageOptionsSchema.parse({ search: 'report' });
24
+ expect(result.search).toBe('report');
25
+ });
26
+
27
+ it('should validate limit option', () => {
28
+ const result = listStorageOptionsSchema.parse({ limit: 50 });
29
+ expect(result.limit).toBe(50);
30
+ });
31
+
32
+ it('should validate offset option', () => {
33
+ const result = listStorageOptionsSchema.parse({ offset: 10 });
34
+ expect(result.offset).toBe(10);
35
+ });
36
+
37
+ it('should validate sortBy option', () => {
38
+ const validSortBy = ['name', 'created_at', 'updated_at', 'size'];
39
+ for (const sortBy of validSortBy) {
40
+ const result = listStorageOptionsSchema.parse({ sortBy });
41
+ expect(result.sortBy).toBe(sortBy);
42
+ }
43
+ });
44
+
45
+ it('should validate sortOrder option', () => {
46
+ const result1 = listStorageOptionsSchema.parse({ sortOrder: 'asc' });
47
+ expect(result1.sortOrder).toBe('asc');
48
+
49
+ const result2 = listStorageOptionsSchema.parse({ sortOrder: 'desc' });
50
+ expect(result2.sortOrder).toBe('desc');
51
+ });
52
+
53
+ it('should validate all options together', () => {
54
+ const result = listStorageOptionsSchema.parse({
55
+ path: 'documents',
56
+ search: 'report',
57
+ limit: 100,
58
+ offset: 50,
59
+ sortBy: 'created_at',
60
+ sortOrder: 'desc',
61
+ });
62
+ expect(result).toEqual({
63
+ path: 'documents',
64
+ search: 'report',
65
+ limit: 100,
66
+ offset: 50,
67
+ sortBy: 'created_at',
68
+ sortOrder: 'desc',
69
+ });
70
+ });
71
+
72
+ it('should reject limit less than 1', () => {
73
+ const result1 = listStorageOptionsSchema.safeParse({ limit: 0 });
74
+ expect(result1.success).toBe(false);
75
+ if (!result1.success) {
76
+ expect(result1.error.issues.length).toBeGreaterThan(0);
77
+ }
78
+
79
+ const result2 = listStorageOptionsSchema.safeParse({ limit: -1 });
80
+ expect(result2.success).toBe(false);
81
+ if (!result2.success) {
82
+ expect(result2.error.issues.length).toBeGreaterThan(0);
83
+ }
84
+ });
85
+
86
+ it('should reject limit greater than 100', () => {
87
+ const result = listStorageOptionsSchema.safeParse({ limit: 101 });
88
+ expect(result.success).toBe(false);
89
+ if (!result.success) {
90
+ expect(result.error.issues.length).toBeGreaterThan(0);
91
+ }
92
+ });
93
+
94
+ it('should reject negative offset', () => {
95
+ const result = listStorageOptionsSchema.safeParse({ offset: -1 });
96
+ expect(result.success).toBe(false);
97
+ if (!result.success) {
98
+ expect(result.error.issues.length).toBeGreaterThan(0);
99
+ }
100
+ });
101
+
102
+ it.each([Number.NaN, null])('should reject %p for limit', (value) => {
103
+ const result = listStorageOptionsSchema.safeParse({ limit: value });
104
+ expect(result.success).toBe(false);
105
+ if (!result.success) {
106
+ expect(result.error.issues.length).toBeGreaterThan(0);
107
+ }
108
+ });
109
+
110
+ it('should accept undefined for limit (optional field)', () => {
111
+ const result = listStorageOptionsSchema.safeParse({
112
+ limit: undefined,
113
+ });
114
+ expect(result.success).toBe(true);
115
+ });
116
+
117
+ it.each([Number.NaN, null])('should reject %p for offset', (value) => {
118
+ const result = listStorageOptionsSchema.safeParse({ offset: value });
119
+ expect(result.success).toBe(false);
120
+ if (!result.success) {
121
+ expect(result.error.issues.length).toBeGreaterThan(0);
122
+ }
123
+ });
124
+
125
+ it('should accept undefined for offset (optional field)', () => {
126
+ const result = listStorageOptionsSchema.safeParse({
127
+ offset: undefined,
128
+ });
129
+ expect(result.success).toBe(true);
130
+ });
131
+
132
+ it('should reject invalid sortBy', () => {
133
+ const result = listStorageOptionsSchema.safeParse({ sortBy: 'invalid' });
134
+ expect(result.success).toBe(false);
135
+ if (!result.success) {
136
+ expect(result.error.issues.length).toBeGreaterThan(0);
137
+ }
138
+ });
139
+
140
+ it('should reject invalid sortOrder', () => {
141
+ const result = listStorageOptionsSchema.safeParse({
142
+ sortOrder: 'invalid',
143
+ });
144
+ expect(result.success).toBe(false);
145
+ if (!result.success) {
146
+ expect(result.error.issues.length).toBeGreaterThan(0);
147
+ }
148
+ });
149
+
150
+ it('should reject non-integer limit', () => {
151
+ const result = listStorageOptionsSchema.safeParse({ limit: 10.5 });
152
+ expect(result.success).toBe(false);
153
+ if (!result.success) {
154
+ expect(result.error.issues.length).toBeGreaterThan(0);
155
+ }
156
+ });
157
+
158
+ it('should reject non-integer offset', () => {
159
+ const result = listStorageOptionsSchema.safeParse({ offset: 5.5 });
160
+ expect(result.success).toBe(false);
161
+ if (!result.success) {
162
+ expect(result.error.issues.length).toBeGreaterThan(0);
163
+ }
164
+ });
165
+ });
166
+
167
+ describe('uploadOptionsSchema', () => {
168
+ it('should validate empty options', () => {
169
+ const result = uploadOptionsSchema.parse({});
170
+ expect(result).toEqual({});
171
+ });
172
+
173
+ it('should validate path option', () => {
174
+ const result = uploadOptionsSchema.parse({ path: 'documents' });
175
+ expect(result.path).toBe('documents');
176
+ });
177
+
178
+ it('should validate upsert true', () => {
179
+ const result = uploadOptionsSchema.parse({ upsert: true });
180
+ expect(result.upsert).toBe(true);
181
+ });
182
+
183
+ it('should validate upsert false', () => {
184
+ const result = uploadOptionsSchema.parse({ upsert: false });
185
+ expect(result.upsert).toBe(false);
186
+ });
187
+
188
+ it('should validate all options together', () => {
189
+ const result = uploadOptionsSchema.parse({
190
+ path: 'documents',
191
+ upsert: true,
192
+ });
193
+ expect(result).toEqual({
194
+ path: 'documents',
195
+ upsert: true,
196
+ });
197
+ });
198
+ });
199
+
200
+ describe('shareOptionsSchema', () => {
201
+ it('should validate empty options', () => {
202
+ const result = shareOptionsSchema.parse({});
203
+ expect(result).toEqual({});
204
+ });
205
+
206
+ it('should validate minimum expiresIn (60 seconds)', () => {
207
+ const result = shareOptionsSchema.parse({ expiresIn: 60 });
208
+ expect(result.expiresIn).toBe(60);
209
+ });
210
+
211
+ it('should validate maximum expiresIn (604800 seconds / 7 days)', () => {
212
+ const result = shareOptionsSchema.parse({ expiresIn: 604800 });
213
+ expect(result.expiresIn).toBe(604800);
214
+ });
215
+
216
+ it('should validate common expiresIn values', () => {
217
+ const commonValues = [3600, 7200, 86400]; // 1 hour, 2 hours, 1 day
218
+ for (const value of commonValues) {
219
+ const result = shareOptionsSchema.parse({ expiresIn: value });
220
+ expect(result.expiresIn).toBe(value);
221
+ }
222
+ });
223
+
224
+ it('should reject expiresIn less than 60', () => {
225
+ const result1 = shareOptionsSchema.safeParse({ expiresIn: 59 });
226
+ expect(result1.success).toBe(false);
227
+ if (!result1.success) {
228
+ expect(result1.error.issues.length).toBeGreaterThan(0);
229
+ }
230
+
231
+ const result2 = shareOptionsSchema.safeParse({ expiresIn: 0 });
232
+ expect(result2.success).toBe(false);
233
+ if (!result2.success) {
234
+ expect(result2.error.issues.length).toBeGreaterThan(0);
235
+ }
236
+ });
237
+
238
+ it('should reject expiresIn greater than 604800', () => {
239
+ const result = shareOptionsSchema.safeParse({ expiresIn: 604801 });
240
+ expect(result.success).toBe(false);
241
+ if (!result.success) {
242
+ expect(result.error.issues.length).toBeGreaterThan(0);
243
+ }
244
+ });
245
+
246
+ it('should reject non-integer expiresIn', () => {
247
+ const result = shareOptionsSchema.safeParse({ expiresIn: 60.5 });
248
+ expect(result.success).toBe(false);
249
+ if (!result.success) {
250
+ expect(result.error.issues.length).toBeGreaterThan(0);
251
+ }
252
+ });
253
+
254
+ it.each([Number.NaN, null])('should reject %p for expiresIn', (value) => {
255
+ const result = shareOptionsSchema.safeParse({ expiresIn: value });
256
+ expect(result.success).toBe(false);
257
+ if (!result.success) {
258
+ expect(result.error.issues.length).toBeGreaterThan(0);
259
+ }
260
+ });
261
+
262
+ it('should accept undefined for expiresIn (optional field)', () => {
263
+ const result = shareOptionsSchema.safeParse({
264
+ expiresIn: undefined,
265
+ });
266
+ expect(result.success).toBe(true);
267
+ });
268
+ });
269
+
270
+ describe('listDocumentsOptionsSchema', () => {
271
+ it('should validate empty options', () => {
272
+ const result = listDocumentsOptionsSchema.parse({});
273
+ expect(result).toEqual({});
274
+ });
275
+
276
+ it('should validate search option', () => {
277
+ const result = listDocumentsOptionsSchema.parse({ search: 'meeting' });
278
+ expect(result.search).toBe('meeting');
279
+ });
280
+
281
+ it('should validate limit option', () => {
282
+ const result = listDocumentsOptionsSchema.parse({ limit: 20 });
283
+ expect(result.limit).toBe(20);
284
+ });
285
+
286
+ it('should validate offset option', () => {
287
+ const result = listDocumentsOptionsSchema.parse({ offset: 5 });
288
+ expect(result.offset).toBe(5);
289
+ });
290
+
291
+ it('should validate isPublic true', () => {
292
+ const result = listDocumentsOptionsSchema.parse({ isPublic: true });
293
+ expect(result.isPublic).toBe(true);
294
+ });
295
+
296
+ it('should validate isPublic false', () => {
297
+ const result = listDocumentsOptionsSchema.parse({ isPublic: false });
298
+ expect(result.isPublic).toBe(false);
299
+ });
300
+
301
+ it('should validate all options together', () => {
302
+ const result = listDocumentsOptionsSchema.parse({
303
+ search: 'meeting',
304
+ limit: 50,
305
+ offset: 10,
306
+ isPublic: false,
307
+ });
308
+ expect(result).toEqual({
309
+ search: 'meeting',
310
+ limit: 50,
311
+ offset: 10,
312
+ isPublic: false,
313
+ });
314
+ });
315
+
316
+ it('should reject limit less than 1', () => {
317
+ const result = listDocumentsOptionsSchema.safeParse({ limit: 0 });
318
+ expect(result.success).toBe(false);
319
+ if (!result.success) {
320
+ expect(result.error.issues.length).toBeGreaterThan(0);
321
+ }
322
+ });
323
+
324
+ it('should reject limit greater than 100', () => {
325
+ const result = listDocumentsOptionsSchema.safeParse({ limit: 101 });
326
+ expect(result.success).toBe(false);
327
+ if (!result.success) {
328
+ expect(result.error.issues.length).toBeGreaterThan(0);
329
+ }
330
+ });
331
+
332
+ it('should reject negative offset', () => {
333
+ const result = listDocumentsOptionsSchema.safeParse({ offset: -1 });
334
+ expect(result.success).toBe(false);
335
+ if (!result.success) {
336
+ expect(result.error.issues.length).toBeGreaterThan(0);
337
+ }
338
+ });
339
+
340
+ it('should reject non-integer limit', () => {
341
+ const result = listDocumentsOptionsSchema.safeParse({ limit: 10.5 });
342
+ expect(result.success).toBe(false);
343
+ if (!result.success) {
344
+ expect(result.error.issues.length).toBeGreaterThan(0);
345
+ }
346
+ });
347
+
348
+ it('should reject non-integer offset', () => {
349
+ const result = listDocumentsOptionsSchema.safeParse({ offset: 5.5 });
350
+ expect(result.success).toBe(false);
351
+ if (!result.success) {
352
+ expect(result.error.issues.length).toBeGreaterThan(0);
353
+ }
354
+ });
355
+
356
+ it.each([Number.NaN, null])('should reject %p for limit', (value) => {
357
+ const result = listDocumentsOptionsSchema.safeParse({ limit: value });
358
+ expect(result.success).toBe(false);
359
+ if (!result.success) {
360
+ expect(result.error.issues.length).toBeGreaterThan(0);
361
+ }
362
+ });
363
+
364
+ it('should reject explicit undefined for limit', () => {
365
+ const result = listDocumentsOptionsSchema.safeParse({
366
+ limit: undefined,
367
+ });
368
+ expect(result.success).toBe(false);
369
+ if (!result.success) {
370
+ expect(result.error.issues.length).toBeGreaterThan(0);
371
+ }
372
+ });
373
+
374
+ it.each([Number.NaN, null])('should reject %p for offset', (value) => {
375
+ const result = listDocumentsOptionsSchema.safeParse({ offset: value });
376
+ expect(result.success).toBe(false);
377
+ if (!result.success) {
378
+ expect(result.error.issues.length).toBeGreaterThan(0);
379
+ }
380
+ });
381
+
382
+ it('should reject explicit undefined for offset', () => {
383
+ const result = listDocumentsOptionsSchema.safeParse({
384
+ offset: undefined,
385
+ });
386
+ expect(result.success).toBe(false);
387
+ if (!result.success) {
388
+ expect(result.error.issues.length).toBeGreaterThan(0);
389
+ }
390
+ });
391
+
392
+ it('should accept omitted limit and offset fields', () => {
393
+ const result = listDocumentsOptionsSchema.safeParse({
394
+ search: 'test',
395
+ });
396
+ expect(result.success).toBe(true);
397
+ });
398
+ });
399
+
400
+ describe('createDocumentDataSchema', () => {
401
+ it('should validate minimal data (name only)', () => {
402
+ const result = createDocumentDataSchema.parse({ name: 'Test Document' });
403
+ expect(result.name).toBe('Test Document');
404
+ expect(result.content).toBeUndefined();
405
+ expect(result.isPublic).toBeUndefined();
406
+ });
407
+
408
+ it('should validate with content', () => {
409
+ const result = createDocumentDataSchema.parse({
410
+ name: 'Test Document',
411
+ content: 'Test content',
412
+ });
413
+ expect(result.content).toBe('Test content');
414
+ });
415
+
416
+ it('should validate with isPublic true', () => {
417
+ const result = createDocumentDataSchema.parse({
418
+ name: 'Test Document',
419
+ isPublic: true,
420
+ });
421
+ expect(result.isPublic).toBe(true);
422
+ });
423
+
424
+ it('should validate with isPublic false', () => {
425
+ const result = createDocumentDataSchema.parse({
426
+ name: 'Test Document',
427
+ isPublic: false,
428
+ });
429
+ expect(result.isPublic).toBe(false);
430
+ });
431
+
432
+ it('should validate all fields', () => {
433
+ const result = createDocumentDataSchema.parse({
434
+ name: 'Test Document',
435
+ content: 'Test content',
436
+ isPublic: true,
437
+ });
438
+ expect(result).toEqual({
439
+ name: 'Test Document',
440
+ content: 'Test content',
441
+ isPublic: true,
442
+ });
443
+ });
444
+
445
+ it('should reject empty name', () => {
446
+ const result = createDocumentDataSchema.safeParse({ name: '' });
447
+ expect(result.success).toBe(false);
448
+ if (!result.success) {
449
+ expect(result.error.issues.length).toBeGreaterThan(0);
450
+ }
451
+ });
452
+
453
+ it('should reject name longer than 255 characters', () => {
454
+ const longName = 'a'.repeat(256);
455
+ const result = createDocumentDataSchema.safeParse({ name: longName });
456
+ expect(result.success).toBe(false);
457
+ if (!result.success) {
458
+ expect(result.error.issues.length).toBeGreaterThan(0);
459
+ }
460
+ });
461
+
462
+ it('should accept name at maximum length (255 characters)', () => {
463
+ const maxName = 'a'.repeat(255);
464
+ const result = createDocumentDataSchema.parse({ name: maxName });
465
+ expect(result.name).toBe(maxName);
466
+ });
467
+
468
+ it('should reject missing name', () => {
469
+ const result = createDocumentDataSchema.safeParse({});
470
+ expect(result.success).toBe(false);
471
+ if (!result.success) {
472
+ expect(result.error.issues.length).toBeGreaterThan(0);
473
+ }
474
+ });
475
+
476
+ it('should accept empty content', () => {
477
+ const result = createDocumentDataSchema.parse({
478
+ name: 'Test',
479
+ content: '',
480
+ });
481
+ expect(result.content).toBe('');
482
+ });
483
+ });
484
+
485
+ describe('updateDocumentDataSchema', () => {
486
+ it('should validate empty update (all fields optional)', () => {
487
+ const result = updateDocumentDataSchema.parse({});
488
+ expect(result).toEqual({});
489
+ });
490
+
491
+ it('should validate name only', () => {
492
+ const result = updateDocumentDataSchema.parse({ name: 'Updated Name' });
493
+ expect(result.name).toBe('Updated Name');
494
+ });
495
+
496
+ it('should validate content only', () => {
497
+ const result = updateDocumentDataSchema.parse({
498
+ content: 'Updated content',
499
+ });
500
+ expect(result.content).toBe('Updated content');
501
+ });
502
+
503
+ it('should validate isPublic only', () => {
504
+ const result = updateDocumentDataSchema.parse({ isPublic: true });
505
+ expect(result.isPublic).toBe(true);
506
+ });
507
+
508
+ it('should validate all fields together', () => {
509
+ const result = updateDocumentDataSchema.parse({
510
+ name: 'Updated Name',
511
+ content: 'Updated content',
512
+ isPublic: false,
513
+ });
514
+ expect(result).toEqual({
515
+ name: 'Updated Name',
516
+ content: 'Updated content',
517
+ isPublic: false,
518
+ });
519
+ });
520
+
521
+ it('should reject empty name', () => {
522
+ const result = updateDocumentDataSchema.safeParse({ name: '' });
523
+ expect(result.success).toBe(false);
524
+ if (!result.success) {
525
+ expect(result.error.issues.length).toBeGreaterThan(0);
526
+ }
527
+ });
528
+
529
+ it('should reject name longer than 255 characters', () => {
530
+ const longName = 'a'.repeat(256);
531
+ const result = updateDocumentDataSchema.safeParse({ name: longName });
532
+ expect(result.success).toBe(false);
533
+ if (!result.success) {
534
+ expect(result.error.issues.length).toBeGreaterThan(0);
535
+ }
536
+ });
537
+
538
+ it('should accept name at maximum length (255 characters)', () => {
539
+ const maxName = 'a'.repeat(255);
540
+ const result = updateDocumentDataSchema.parse({ name: maxName });
541
+ expect(result.name).toBe(maxName);
542
+ });
543
+
544
+ it('should accept empty content', () => {
545
+ const result = updateDocumentDataSchema.parse({ content: '' });
546
+ expect(result.content).toBe('');
547
+ });
548
+
549
+ it('should accept partial updates', () => {
550
+ const result1 = updateDocumentDataSchema.parse({ name: 'Name' });
551
+ expect(result1.content).toBeUndefined();
552
+ expect(result1.isPublic).toBeUndefined();
553
+
554
+ const result2 = updateDocumentDataSchema.parse({ content: 'Content' });
555
+ expect(result2.name).toBeUndefined();
556
+ expect(result2.isPublic).toBeUndefined();
557
+
558
+ const result3 = updateDocumentDataSchema.parse({ isPublic: true });
559
+ expect(result3.name).toBeUndefined();
560
+ expect(result3.content).toBeUndefined();
561
+ });
562
+ });