@olane/o-test 0.7.12

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 (60) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +400 -0
  3. package/dist/src/builders/index.d.ts +7 -0
  4. package/dist/src/builders/index.d.ts.map +1 -0
  5. package/dist/src/builders/index.js +6 -0
  6. package/dist/src/builders/leader-child-builder.d.ts +50 -0
  7. package/dist/src/builders/leader-child-builder.d.ts.map +1 -0
  8. package/dist/src/builders/leader-child-builder.js +59 -0
  9. package/dist/src/builders/manager-worker-builder.d.ts +49 -0
  10. package/dist/src/builders/manager-worker-builder.d.ts.map +1 -0
  11. package/dist/src/builders/manager-worker-builder.js +79 -0
  12. package/dist/src/builders/simple-node-builder.d.ts +49 -0
  13. package/dist/src/builders/simple-node-builder.d.ts.map +1 -0
  14. package/dist/src/builders/simple-node-builder.js +66 -0
  15. package/dist/src/example-tool.tool.d.ts +58 -0
  16. package/dist/src/example-tool.tool.d.ts.map +1 -0
  17. package/dist/src/example-tool.tool.js +89 -0
  18. package/dist/src/fixtures/index.d.ts +6 -0
  19. package/dist/src/fixtures/index.d.ts.map +1 -0
  20. package/dist/src/fixtures/index.js +5 -0
  21. package/dist/src/fixtures/mock-data.d.ts +201 -0
  22. package/dist/src/fixtures/mock-data.d.ts.map +1 -0
  23. package/dist/src/fixtures/mock-data.js +180 -0
  24. package/dist/src/fixtures/test-methods.d.ts +33 -0
  25. package/dist/src/fixtures/test-methods.d.ts.map +1 -0
  26. package/dist/src/fixtures/test-methods.js +185 -0
  27. package/dist/src/index.d.ts +18 -0
  28. package/dist/src/index.d.ts.map +1 -0
  29. package/dist/src/index.js +25 -0
  30. package/dist/src/methods/example.methods.d.ts +9 -0
  31. package/dist/src/methods/example.methods.d.ts.map +1 -0
  32. package/dist/src/methods/example.methods.js +50 -0
  33. package/dist/src/test-environment.d.ts +185 -0
  34. package/dist/src/test-environment.d.ts.map +1 -0
  35. package/dist/src/test-environment.js +260 -0
  36. package/dist/src/utils/assertions.d.ts +159 -0
  37. package/dist/src/utils/assertions.d.ts.map +1 -0
  38. package/dist/src/utils/assertions.js +201 -0
  39. package/dist/src/utils/chunk-capture.d.ts +108 -0
  40. package/dist/src/utils/chunk-capture.d.ts.map +1 -0
  41. package/dist/src/utils/chunk-capture.js +156 -0
  42. package/dist/src/utils/index.d.ts +8 -0
  43. package/dist/src/utils/index.d.ts.map +1 -0
  44. package/dist/src/utils/index.js +7 -0
  45. package/dist/src/utils/mock-factories.d.ts +211 -0
  46. package/dist/src/utils/mock-factories.d.ts.map +1 -0
  47. package/dist/src/utils/mock-factories.js +181 -0
  48. package/dist/src/utils/wait-for.d.ts +42 -0
  49. package/dist/src/utils/wait-for.d.ts.map +1 -0
  50. package/dist/src/utils/wait-for.js +59 -0
  51. package/dist/test/example.spec.d.ts +1 -0
  52. package/dist/test/example.spec.d.ts.map +1 -0
  53. package/dist/test/example.spec.js +240 -0
  54. package/dist/test/fixtures/mock-data.d.ts +1 -0
  55. package/dist/test/fixtures/mock-data.d.ts.map +1 -0
  56. package/dist/test/fixtures/mock-data.js +90 -0
  57. package/dist/test/test-environment.spec.d.ts +8 -0
  58. package/dist/test/test-environment.spec.d.ts.map +1 -0
  59. package/dist/test/test-environment.spec.js +393 -0
  60. package/package.json +87 -0
@@ -0,0 +1,108 @@
1
+ /**
2
+ * ChunkCapture - Utility for capturing and validating streaming chunks
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const capture = new ChunkCapture();
7
+ *
8
+ * await tool.useSelf({
9
+ * method: 'stream_data',
10
+ * params: {},
11
+ * onChunk: capture.onChunk.bind(capture)
12
+ * });
13
+ *
14
+ * expect(capture.chunkCount).to.equal(5);
15
+ * expect(capture.lastChunk).to.deep.equal({ done: true });
16
+ * ```
17
+ */
18
+ export declare class ChunkCapture<T = any> {
19
+ /**
20
+ * All captured chunks in order
21
+ */
22
+ allChunks: T[];
23
+ /**
24
+ * Total number of chunks captured
25
+ */
26
+ get chunkCount(): number;
27
+ /**
28
+ * Last chunk received (undefined if no chunks)
29
+ */
30
+ get lastChunk(): T | undefined;
31
+ /**
32
+ * First chunk received (undefined if no chunks)
33
+ */
34
+ get firstChunk(): T | undefined;
35
+ /**
36
+ * Callback to capture chunks
37
+ *
38
+ * @param chunk - Chunk data
39
+ */
40
+ onChunk(chunk: T): void;
41
+ /**
42
+ * Clear all captured chunks
43
+ */
44
+ clear(): void;
45
+ /**
46
+ * Wait for a specific number of chunks
47
+ *
48
+ * @param count - Expected chunk count
49
+ * @param timeoutMs - Maximum wait time (default: 5000ms)
50
+ * @returns Promise that resolves when count is reached
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * await capture.waitForChunks(10);
55
+ * ```
56
+ */
57
+ waitForChunks(count: number, timeoutMs?: number): Promise<void>;
58
+ /**
59
+ * Wait for chunks to stop arriving
60
+ *
61
+ * @param quietMs - Milliseconds of no new chunks (default: 500ms)
62
+ * @param timeoutMs - Maximum wait time (default: 10000ms)
63
+ * @returns Promise that resolves when streaming appears complete
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * await capture.waitForComplete();
68
+ * ```
69
+ */
70
+ waitForComplete(quietMs?: number, timeoutMs?: number): Promise<void>;
71
+ /**
72
+ * Find chunks matching a predicate
73
+ *
74
+ * @param predicate - Filter function
75
+ * @returns Array of matching chunks
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const errors = capture.findChunks(chunk => chunk.type === 'error');
80
+ * ```
81
+ */
82
+ findChunks(predicate: (chunk: T) => boolean): T[];
83
+ /**
84
+ * Check if any chunk matches a predicate
85
+ *
86
+ * @param predicate - Test function
87
+ * @returns True if any chunk matches
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const hasError = capture.hasChunk(chunk => chunk.error);
92
+ * ```
93
+ */
94
+ hasChunk(predicate: (chunk: T) => boolean): boolean;
95
+ /**
96
+ * Get chunks as a string (useful for text streams)
97
+ *
98
+ * @param separator - String to join chunks (default: '')
99
+ * @returns Concatenated string
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const fullText = capture.asString();
104
+ * ```
105
+ */
106
+ asString(separator?: string): string;
107
+ }
108
+ //# sourceMappingURL=chunk-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-capture.d.ts","sourceRoot":"","sources":["../../../src/utils/chunk-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,qBAAa,YAAY,CAAC,CAAC,GAAG,GAAG;IAC/B;;OAEG;IACI,SAAS,EAAE,CAAC,EAAE,CAAM;IAE3B;;OAEG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,CAAC,GAAG,SAAS,CAEpC;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,CAAC,GAAG,SAAS,CAErC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAI9B;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB;;;;;;;;;;;OAWG;IACU,aAAa,CACxB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAa,GACvB,OAAO,CAAC,IAAI,CAAC;IAQhB;;;;;;;;;;;OAWG;IACU,eAAe,CAC1B,OAAO,GAAE,MAAY,EACrB,SAAS,GAAE,MAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IA2BhB;;;;;;;;;;OAUG;IACI,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,CAAC,EAAE;IAIxD;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO;IAI1D;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,SAAS,GAAE,MAAW,GAAG,MAAM;CAWhD"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * ChunkCapture - Utility for capturing and validating streaming chunks
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const capture = new ChunkCapture();
7
+ *
8
+ * await tool.useSelf({
9
+ * method: 'stream_data',
10
+ * params: {},
11
+ * onChunk: capture.onChunk.bind(capture)
12
+ * });
13
+ *
14
+ * expect(capture.chunkCount).to.equal(5);
15
+ * expect(capture.lastChunk).to.deep.equal({ done: true });
16
+ * ```
17
+ */
18
+ import { waitFor } from './wait-for.js';
19
+ export class ChunkCapture {
20
+ constructor() {
21
+ /**
22
+ * All captured chunks in order
23
+ */
24
+ this.allChunks = [];
25
+ }
26
+ /**
27
+ * Total number of chunks captured
28
+ */
29
+ get chunkCount() {
30
+ return this.allChunks.length;
31
+ }
32
+ /**
33
+ * Last chunk received (undefined if no chunks)
34
+ */
35
+ get lastChunk() {
36
+ return this.allChunks[this.allChunks.length - 1];
37
+ }
38
+ /**
39
+ * First chunk received (undefined if no chunks)
40
+ */
41
+ get firstChunk() {
42
+ return this.allChunks[0];
43
+ }
44
+ /**
45
+ * Callback to capture chunks
46
+ *
47
+ * @param chunk - Chunk data
48
+ */
49
+ onChunk(chunk) {
50
+ this.allChunks.push(chunk);
51
+ }
52
+ /**
53
+ * Clear all captured chunks
54
+ */
55
+ clear() {
56
+ this.allChunks = [];
57
+ }
58
+ /**
59
+ * Wait for a specific number of chunks
60
+ *
61
+ * @param count - Expected chunk count
62
+ * @param timeoutMs - Maximum wait time (default: 5000ms)
63
+ * @returns Promise that resolves when count is reached
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * await capture.waitForChunks(10);
68
+ * ```
69
+ */
70
+ async waitForChunks(count, timeoutMs = 5000) {
71
+ await waitFor(() => this.chunkCount >= count, timeoutMs, 50);
72
+ }
73
+ /**
74
+ * Wait for chunks to stop arriving
75
+ *
76
+ * @param quietMs - Milliseconds of no new chunks (default: 500ms)
77
+ * @param timeoutMs - Maximum wait time (default: 10000ms)
78
+ * @returns Promise that resolves when streaming appears complete
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * await capture.waitForComplete();
83
+ * ```
84
+ */
85
+ async waitForComplete(quietMs = 500, timeoutMs = 10000) {
86
+ const startTime = Date.now();
87
+ let lastCount = this.chunkCount;
88
+ let quietStart = Date.now();
89
+ while (true) {
90
+ if (Date.now() - startTime > timeoutMs) {
91
+ throw new Error(`Timeout: Stream did not complete after ${timeoutMs}ms`);
92
+ }
93
+ // Check if count changed
94
+ if (this.chunkCount !== lastCount) {
95
+ lastCount = this.chunkCount;
96
+ quietStart = Date.now();
97
+ }
98
+ // Check if quiet period reached
99
+ if (Date.now() - quietStart >= quietMs) {
100
+ return;
101
+ }
102
+ await new Promise(resolve => setTimeout(resolve, 100));
103
+ }
104
+ }
105
+ /**
106
+ * Find chunks matching a predicate
107
+ *
108
+ * @param predicate - Filter function
109
+ * @returns Array of matching chunks
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const errors = capture.findChunks(chunk => chunk.type === 'error');
114
+ * ```
115
+ */
116
+ findChunks(predicate) {
117
+ return this.allChunks.filter(predicate);
118
+ }
119
+ /**
120
+ * Check if any chunk matches a predicate
121
+ *
122
+ * @param predicate - Test function
123
+ * @returns True if any chunk matches
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const hasError = capture.hasChunk(chunk => chunk.error);
128
+ * ```
129
+ */
130
+ hasChunk(predicate) {
131
+ return this.allChunks.some(predicate);
132
+ }
133
+ /**
134
+ * Get chunks as a string (useful for text streams)
135
+ *
136
+ * @param separator - String to join chunks (default: '')
137
+ * @returns Concatenated string
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const fullText = capture.asString();
142
+ * ```
143
+ */
144
+ asString(separator = '') {
145
+ return this.allChunks
146
+ .map(chunk => {
147
+ if (typeof chunk === 'string')
148
+ return chunk;
149
+ if (typeof chunk === 'object' && chunk !== null) {
150
+ return chunk.text || chunk.content || JSON.stringify(chunk);
151
+ }
152
+ return String(chunk);
153
+ })
154
+ .join(separator);
155
+ }
156
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Test utilities - Common helpers for O-Network testing
3
+ */
4
+ export { waitFor, waitForAsync, sleep } from './wait-for.js';
5
+ export { ChunkCapture } from './chunk-capture.js';
6
+ export * from './assertions.js';
7
+ export * from './mock-factories.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test utilities - Common helpers for O-Network testing
3
+ */
4
+ export { waitFor, waitForAsync, sleep } from './wait-for.js';
5
+ export { ChunkCapture } from './chunk-capture.js';
6
+ export * from './assertions.js';
7
+ export * from './mock-factories.js';
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Mock factories for common test data
3
+ *
4
+ * Provides factory functions for creating consistent test data
5
+ */
6
+ /**
7
+ * Generate a random ID
8
+ *
9
+ * @param prefix - Optional prefix for the ID
10
+ * @returns Random ID string
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const userId = generateId('user'); // "user-1234567890-abc"
15
+ * ```
16
+ */
17
+ export declare function generateId(prefix?: string): string;
18
+ /**
19
+ * Create a mock user object
20
+ *
21
+ * @param overrides - Properties to override
22
+ * @returns Mock user object
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const user = createMockUser({ email: 'custom@example.com' });
27
+ * ```
28
+ */
29
+ export declare function createMockUser(overrides?: Partial<{
30
+ userId: string;
31
+ username: string;
32
+ email: string;
33
+ role: string;
34
+ active: boolean;
35
+ }>): {
36
+ userId: string;
37
+ username: string;
38
+ email: string;
39
+ role: string;
40
+ active: boolean;
41
+ };
42
+ /**
43
+ * Create a mock task object
44
+ *
45
+ * @param overrides - Properties to override
46
+ * @returns Mock task object
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const task = createMockTask({ status: 'completed' });
51
+ * ```
52
+ */
53
+ export declare function createMockTask(overrides?: Partial<{
54
+ taskId: string;
55
+ title: string;
56
+ description: string;
57
+ status: string;
58
+ createdAt: number;
59
+ updatedAt: number;
60
+ }>): {
61
+ taskId: string;
62
+ title: string;
63
+ description: string;
64
+ status: string;
65
+ createdAt: number;
66
+ updatedAt: number;
67
+ };
68
+ /**
69
+ * Create a mock session object
70
+ *
71
+ * @param overrides - Properties to override
72
+ * @returns Mock session object
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const session = createMockSession({ userId: 'user-123' });
77
+ * ```
78
+ */
79
+ export declare function createMockSession(overrides?: Partial<{
80
+ sessionId: string;
81
+ userId: string;
82
+ createdAt: number;
83
+ expiresAt: number;
84
+ active: boolean;
85
+ }>): {
86
+ sessionId: string;
87
+ userId: string;
88
+ createdAt: number;
89
+ expiresAt: number;
90
+ active: boolean;
91
+ };
92
+ /**
93
+ * Create mock request parameters
94
+ *
95
+ * @param params - Parameters to include
96
+ * @returns Mock oRequest-compatible object
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const request = createMockRequest({ userId: 'user-123' });
101
+ * ```
102
+ */
103
+ export declare function createMockRequest(params?: Record<string, any>): {
104
+ method: string;
105
+ params: Record<string, any>;
106
+ timestamp: number;
107
+ };
108
+ /**
109
+ * Create mock tool response (success)
110
+ *
111
+ * @param data - Response data
112
+ * @returns Mock successful response
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const response = createMockSuccessResponse({ userId: 'user-123' });
117
+ * ```
118
+ */
119
+ export declare function createMockSuccessResponse(data?: any): {
120
+ success: boolean;
121
+ result: {
122
+ data: any;
123
+ };
124
+ };
125
+ /**
126
+ * Create mock tool response (error)
127
+ *
128
+ * @param error - Error message
129
+ * @returns Mock error response
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const response = createMockErrorResponse('User not found');
134
+ * ```
135
+ */
136
+ export declare function createMockErrorResponse(error?: string): {
137
+ success: boolean;
138
+ error: string;
139
+ };
140
+ /**
141
+ * Common invalid parameter sets for validation testing
142
+ */
143
+ export declare const INVALID_PARAMS: {
144
+ empty: {};
145
+ nullValue: {
146
+ param: null;
147
+ };
148
+ undefinedValue: {
149
+ param: undefined;
150
+ };
151
+ wrongTypeString: {
152
+ param: string;
153
+ };
154
+ wrongTypeNumber: {
155
+ param: number;
156
+ };
157
+ wrongTypeBoolean: {
158
+ param: boolean;
159
+ };
160
+ emptyString: {
161
+ param: string;
162
+ };
163
+ emptyArray: {
164
+ param: never[];
165
+ };
166
+ emptyObject: {
167
+ param: {};
168
+ };
169
+ };
170
+ /**
171
+ * Common valid parameter sets
172
+ */
173
+ export declare const VALID_PARAMS: {
174
+ basic: {
175
+ param1: string;
176
+ param2: string;
177
+ };
178
+ withNumbers: {
179
+ count: number;
180
+ timeout: number;
181
+ };
182
+ withBoolean: {
183
+ enabled: boolean;
184
+ verified: boolean;
185
+ };
186
+ withArray: {
187
+ items: string[];
188
+ };
189
+ withObject: {
190
+ config: {
191
+ key: string;
192
+ nested: {
193
+ deep: boolean;
194
+ };
195
+ };
196
+ };
197
+ };
198
+ /**
199
+ * Generate an array of mock items
200
+ *
201
+ * @param factory - Factory function to create each item
202
+ * @param count - Number of items to generate
203
+ * @returns Array of mock items
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const users = generateMockArray(() => createMockUser(), 10);
208
+ * ```
209
+ */
210
+ export declare function generateMockArray<T>(factory: (index: number) => T, count: number): T[];
211
+ //# sourceMappingURL=mock-factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-factories.d.ts","sourceRoot":"","sources":["../../../src/utils/mock-factories.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAa,GAAG,MAAM,CAIxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,OAAO,CAAC;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB,CAAM;;;;;;EAUN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,SAAS,GAAE,OAAO,CAAC;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAM;;;;;;;EAYN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,OAAO,CAAC;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAM;;;;;;EAYN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;;;;EAMjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,GAAE,GAAQ;;;;;EAOvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,GAAE,MAAqB;;;EAKnE;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CAU1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;CAMxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,EAC7B,KAAK,EAAE,MAAM,GACZ,CAAC,EAAE,CAEL"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Mock factories for common test data
3
+ *
4
+ * Provides factory functions for creating consistent test data
5
+ */
6
+ /**
7
+ * Generate a random ID
8
+ *
9
+ * @param prefix - Optional prefix for the ID
10
+ * @returns Random ID string
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const userId = generateId('user'); // "user-1234567890-abc"
15
+ * ```
16
+ */
17
+ export function generateId(prefix = 'id') {
18
+ const timestamp = Date.now();
19
+ const random = Math.random().toString(36).substring(2, 11);
20
+ return `${prefix}-${timestamp}-${random}`;
21
+ }
22
+ /**
23
+ * Create a mock user object
24
+ *
25
+ * @param overrides - Properties to override
26
+ * @returns Mock user object
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const user = createMockUser({ email: 'custom@example.com' });
31
+ * ```
32
+ */
33
+ export function createMockUser(overrides = {}) {
34
+ const userId = overrides.userId || generateId('user');
35
+ return {
36
+ userId,
37
+ username: overrides.username || `user${userId.slice(-8)}`,
38
+ email: overrides.email || `${userId}@test.example.com`,
39
+ role: overrides.role || 'user',
40
+ active: overrides.active !== undefined ? overrides.active : true,
41
+ };
42
+ }
43
+ /**
44
+ * Create a mock task object
45
+ *
46
+ * @param overrides - Properties to override
47
+ * @returns Mock task object
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const task = createMockTask({ status: 'completed' });
52
+ * ```
53
+ */
54
+ export function createMockTask(overrides = {}) {
55
+ const taskId = overrides.taskId || generateId('task');
56
+ const now = Date.now();
57
+ return {
58
+ taskId,
59
+ title: overrides.title || 'Test Task',
60
+ description: overrides.description || 'A test task for unit testing',
61
+ status: overrides.status || 'pending',
62
+ createdAt: overrides.createdAt || now,
63
+ updatedAt: overrides.updatedAt || now,
64
+ };
65
+ }
66
+ /**
67
+ * Create a mock session object
68
+ *
69
+ * @param overrides - Properties to override
70
+ * @returns Mock session object
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const session = createMockSession({ userId: 'user-123' });
75
+ * ```
76
+ */
77
+ export function createMockSession(overrides = {}) {
78
+ const sessionId = overrides.sessionId || generateId('session');
79
+ const now = Date.now();
80
+ const oneHour = 3600000;
81
+ return {
82
+ sessionId,
83
+ userId: overrides.userId || generateId('user'),
84
+ createdAt: overrides.createdAt || now,
85
+ expiresAt: overrides.expiresAt || now + oneHour,
86
+ active: overrides.active !== undefined ? overrides.active : true,
87
+ };
88
+ }
89
+ /**
90
+ * Create mock request parameters
91
+ *
92
+ * @param params - Parameters to include
93
+ * @returns Mock oRequest-compatible object
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const request = createMockRequest({ userId: 'user-123' });
98
+ * ```
99
+ */
100
+ export function createMockRequest(params = {}) {
101
+ return {
102
+ method: 'test_method',
103
+ params,
104
+ timestamp: Date.now(),
105
+ };
106
+ }
107
+ /**
108
+ * Create mock tool response (success)
109
+ *
110
+ * @param data - Response data
111
+ * @returns Mock successful response
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const response = createMockSuccessResponse({ userId: 'user-123' });
116
+ * ```
117
+ */
118
+ export function createMockSuccessResponse(data = {}) {
119
+ return {
120
+ success: true,
121
+ result: {
122
+ data,
123
+ },
124
+ };
125
+ }
126
+ /**
127
+ * Create mock tool response (error)
128
+ *
129
+ * @param error - Error message
130
+ * @returns Mock error response
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const response = createMockErrorResponse('User not found');
135
+ * ```
136
+ */
137
+ export function createMockErrorResponse(error = 'Test error') {
138
+ return {
139
+ success: false,
140
+ error,
141
+ };
142
+ }
143
+ /**
144
+ * Common invalid parameter sets for validation testing
145
+ */
146
+ export const INVALID_PARAMS = {
147
+ empty: {},
148
+ nullValue: { param: null },
149
+ undefinedValue: { param: undefined },
150
+ wrongTypeString: { param: 'should-be-number' },
151
+ wrongTypeNumber: { param: 123 },
152
+ wrongTypeBoolean: { param: true },
153
+ emptyString: { param: '' },
154
+ emptyArray: { param: [] },
155
+ emptyObject: { param: {} },
156
+ };
157
+ /**
158
+ * Common valid parameter sets
159
+ */
160
+ export const VALID_PARAMS = {
161
+ basic: { param1: 'value1', param2: 'value2' },
162
+ withNumbers: { count: 5, timeout: 1000 },
163
+ withBoolean: { enabled: true, verified: false },
164
+ withArray: { items: ['item1', 'item2', 'item3'] },
165
+ withObject: { config: { key: 'value', nested: { deep: true } } },
166
+ };
167
+ /**
168
+ * Generate an array of mock items
169
+ *
170
+ * @param factory - Factory function to create each item
171
+ * @param count - Number of items to generate
172
+ * @returns Array of mock items
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const users = generateMockArray(() => createMockUser(), 10);
177
+ * ```
178
+ */
179
+ export function generateMockArray(factory, count) {
180
+ return Array.from({ length: count }, (_, i) => factory(i));
181
+ }