@nestia/e2e 7.0.0 → 7.0.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.
@@ -1,82 +1,379 @@
1
1
  /**
2
- * Random data generator.
2
+ * Comprehensive random data generation utilities for testing and development.
3
+ *
4
+ * RandomGenerator provides a collection of functions for generating random data
5
+ * including strings, names, content, dates, and array sampling. All functions
6
+ * are designed to be deterministic within a single execution but produce varied
7
+ * output across different runs, making them ideal for testing scenarios.
8
+ *
9
+ * The namespace includes specialized generators for:
10
+ *
11
+ * - Text content (alphabets, alphanumeric, names, paragraphs)
12
+ * - Phone numbers and contact information
13
+ * - Date ranges and time-based data
14
+ * - Array sampling and element selection
3
15
  *
4
16
  * @author Jeongho Nam - https://github.com/samchon
17
+ * @example
18
+ * ```typescript
19
+ * // Generate test user data
20
+ * const testUser = {
21
+ * id: RandomGenerator.alphaNumeric(8),
22
+ * name: RandomGenerator.name(),
23
+ * bio: RandomGenerator.paragraph(3)(5, 10),
24
+ * phone: RandomGenerator.mobile(),
25
+ * createdAt: RandomGenerator.date(new Date())(1000 * 60 * 60 * 24 * 30) // 30 days
26
+ * };
27
+ *
28
+ * // Sample data for testing
29
+ * const testSample = RandomGenerator.sample(allUsers)(5);
30
+ * ```;
5
31
  */
6
32
  export declare namespace RandomGenerator {
7
33
  /**
8
- * Generate random alphabets
34
+ * Generates a random string containing only lowercase alphabetical
35
+ * characters.
36
+ *
37
+ * Creates a string of specified length using only characters a-z. Each
38
+ * character is independently randomly selected, so the same character may
39
+ * appear multiple times. Useful for generating random identifiers, test
40
+ * names, or placeholder text.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * RandomGenerator.alphabets(5); // "hello"
45
+ * RandomGenerator.alphabets(3); // "abc"
46
+ * RandomGenerator.alphabets(10); // "randomtext"
47
+ *
48
+ * // Generate random CSS class names
49
+ * const className = `test-${RandomGenerator.alphabets(6)}`;
50
+ *
51
+ * // Create random variable names for testing
52
+ * const varName = RandomGenerator.alphabets(8);
53
+ * ```
9
54
  *
10
- * @param length Length of alphabets
11
- * @returns Generated alphabets
55
+ * @param length - The desired length of the generated alphabetic string
56
+ * @returns A string containing only lowercase letters of the specified length
12
57
  */
13
58
  const alphabets: (length: number) => string;
14
59
  /**
15
- * Generate random alpha-numeric characters.
60
+ * Generates a random alphanumeric string containing digits and lowercase
61
+ * letters.
16
62
  *
17
- * Generate random string constructed with only alphabets and numbers.
63
+ * Creates a string of specified length using characters from 0-9 and a-z.
64
+ * Each position is independently randomly selected from the combined
65
+ * character set. Ideal for generating random IDs, tokens, passwords, or
66
+ * unique identifiers that need both numeric and alphabetic characters.
18
67
  *
19
- * @param length Length of characters
20
- * @returns Generated string
68
+ * @example
69
+ * ```typescript
70
+ * RandomGenerator.alphaNumeric(8); // "a1b2c3d4"
71
+ * RandomGenerator.alphaNumeric(12); // "x9y8z7w6v5u4"
72
+ *
73
+ * // Generate random API keys
74
+ * const apiKey = RandomGenerator.alphaNumeric(32);
75
+ *
76
+ * // Create session tokens
77
+ * const sessionId = `sess_${RandomGenerator.alphaNumeric(16)}`;
78
+ *
79
+ * // Generate test database IDs
80
+ * const testId = RandomGenerator.alphaNumeric(10);
81
+ * ```
82
+ *
83
+ * @param length - The desired length of the generated alphanumeric string
84
+ * @returns A string containing digits and lowercase letters of the specified
85
+ * length
21
86
  */
22
87
  const alphaNumeric: (length: number) => string;
23
88
  /**
24
- * Generate random name.
89
+ * Generates a random name-like string with realistic length variation.
90
+ *
91
+ * Creates a name by generating a paragraph with 2-3 words (randomly chosen).
92
+ * The resulting string resembles typical human names in structure and length.
93
+ * Each word is between 3-7 characters by default, creating realistic-looking
94
+ * names.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * RandomGenerator.name(); // "john doe"
99
+ * RandomGenerator.name(1); // "alice"
100
+ * RandomGenerator.name(3); // "jane mary smith"
101
+ *
102
+ * // Generate test user names
103
+ * const users = Array.from({ length: 10 }, () => ({
104
+ * id: RandomGenerator.alphaNumeric(8),
105
+ * name: RandomGenerator.name(),
106
+ * email: `${RandomGenerator.name(1)}@test.com`
107
+ * }));
108
+ *
109
+ * // Create random author names for blog posts
110
+ * const authorName = RandomGenerator.name();
111
+ * ```
25
112
  *
26
- * @param length Length of paragraph, default is 2 or 3
27
- * @returns Generated name
113
+ * @param length - Number of words in the name (default: random between 2-3)
114
+ * @returns A space-separated string resembling a human name
28
115
  */
29
116
  const name: (length?: number) => string;
30
117
  /**
31
- * Generate random paragraph.
118
+ * Generates a random paragraph with configurable sentence structure.
32
119
  *
33
- * @param sentences Number of sentences
34
- * @returns Paragraph generator
120
+ * Creates a paragraph consisting of a specified number of "sentences"
121
+ * (words). Each sentence is a random alphabetic string, and sentences are
122
+ * joined with spaces. Returns a currying function to allow configuration of
123
+ * word length ranges.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Generate with default word lengths (3-7 characters)
128
+ * RandomGenerator.paragraph(3)(); // "hello world test"
129
+ * RandomGenerator.paragraph(5)(); // "lorem ipsum dolor sit amet"
130
+ *
131
+ * // Custom word length ranges
132
+ * RandomGenerator.paragraph(4)(2, 5); // "ab cd ef gh"
133
+ * RandomGenerator.paragraph(6)(8, 12); // "verylongword anotherlongword..."
134
+ *
135
+ * // Generate product descriptions
136
+ * const description = RandomGenerator.paragraph(8)(4, 8);
137
+ *
138
+ * // Create test content for forms
139
+ * const placeholder = RandomGenerator.paragraph(3)(5, 10);
140
+ *
141
+ * // Generate variable-length test data
142
+ * const testTexts = Array.from({ length: 5 }, (_, i) =>
143
+ * RandomGenerator.paragraph(i + 2)(3, 6)
144
+ * );
145
+ * ```;
146
+ *
147
+ * @param sentences - Number of sentences (words) in the paragraph (default:
148
+ * random 2-5)
149
+ * @returns A currying function that accepts word length parameters
35
150
  */
36
151
  const paragraph: (sentences?: number) => (wordMin?: number, wordMax?: number) => string;
37
152
  /**
38
- * Generate random content.
153
+ * Generates random multi-paragraph content with customizable structure.
154
+ *
155
+ * Creates content consisting of multiple paragraphs separated by double
156
+ * newlines. Uses a triple-currying pattern to allow fine-grained control over
157
+ * content structure: paragraphs count → sentences per paragraph → word
158
+ * character lengths. Ideal for generating realistic-looking text content for
159
+ * testing.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Generate with all defaults
164
+ * const article = RandomGenerator.content()()();
39
165
  *
40
- * @param paragraphs Number of paragraphs
41
- * @returns Currying function
166
+ * // Specific structure: 5 paragraphs, 15-25 sentences each, 4-8 char words
167
+ * const longContent = RandomGenerator.content(5)(15, 25)(4, 8);
168
+ *
169
+ * // Short content with brief sentences
170
+ * const shortContent = RandomGenerator.content(2)(5, 8)(2, 4);
171
+ *
172
+ * // Generate blog post content
173
+ * const blogPost = {
174
+ * title: RandomGenerator.name(3),
175
+ * content: RandomGenerator.content(4)(10, 20)(3, 7),
176
+ * summary: RandomGenerator.paragraph(2)(5, 10)
177
+ * };
178
+ *
179
+ * // Create test data for CMS
180
+ * const pages = Array.from({ length: 10 }, () => ({
181
+ * id: RandomGenerator.alphaNumeric(8),
182
+ * content: RandomGenerator.content(randint(2, 6))(8, 15)(4, 9)
183
+ * }));
184
+ *
185
+ * // Generate email content for testing
186
+ * const emailBody = RandomGenerator.content(3)(5, 12)(3, 8);
187
+ * ```;
188
+ *
189
+ * @param paragraphs - Number of paragraphs to generate (default: random 3-8)
190
+ * @returns A currying function that accepts sentence count parameters
42
191
  */
43
192
  const content: (paragraphs?: number) => (sentenceMin?: number, sentenceMax?: number) => (wordMin?: number, wordMax?: number) => string;
44
193
  /**
45
- * Generate random substring.
194
+ * Extracts a random substring from the provided content string.
195
+ *
196
+ * Selects two random positions within the content and returns the substring
197
+ * between them. The starting position is always before the ending position.
198
+ * Automatically trims whitespace from the beginning and end of the result.
199
+ * Useful for creating excerpts, search terms, or partial content samples.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const text = "The quick brown fox jumps over the lazy dog";
46
204
  *
47
- * @param content Target content
48
- * @returns Random substring
205
+ * RandomGenerator.substring(text); // "quick brown fox"
206
+ * RandomGenerator.substring(text); // "jumps over"
207
+ * RandomGenerator.substring(text); // "fox jumps over the lazy"
208
+ *
209
+ * // Generate search terms from content
210
+ * const searchQuery = RandomGenerator.substring(articleContent);
211
+ *
212
+ * // Create excerpts for previews
213
+ * const excerpt = RandomGenerator.substring(fullBlogPost);
214
+ *
215
+ * // Generate partial matches for testing search functionality
216
+ * const partialMatch = RandomGenerator.substring(productDescription);
217
+ *
218
+ * // Create random selections for highlight testing
219
+ * const selectedText = RandomGenerator.substring(documentContent);
220
+ * ```;
221
+ *
222
+ * @param content - The source string to extract a substring from
223
+ * @returns A trimmed substring of the original content
49
224
  */
50
225
  const substring: (content: string) => string;
51
226
  /**
52
- * Generate random mobile number.
227
+ * Generates a random mobile phone number with customizable prefix.
228
+ *
229
+ * Creates a mobile phone number in the format: [prefix][3-4 digits][4
230
+ * digits]. The middle section is 3 digits if the random number is less than
231
+ * 1000, otherwise 4 digits. The last section is always 4 digits, zero-padded
232
+ * if necessary. Commonly used for generating Korean mobile phone numbers or
233
+ * similar formats.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * RandomGenerator.mobile(); // "0103341234"
238
+ * RandomGenerator.mobile("011"); // "0119876543"
239
+ * RandomGenerator.mobile("+82"); // "+8233412345"
240
+ *
241
+ * // Generate test user phone numbers
242
+ * const testUsers = Array.from({ length: 100 }, () => ({
243
+ * name: RandomGenerator.name(),
244
+ * phone: RandomGenerator.mobile(),
245
+ * altPhone: RandomGenerator.mobile("011")
246
+ * }));
53
247
  *
54
- * @param prefix Prefix string, default is "010"
55
- * @returns Random mobile number
56
- * @example 0103340067
248
+ * // Create international phone numbers
249
+ * const internationalPhone = RandomGenerator.mobile("+821");
250
+ *
251
+ * // Generate contact list for testing
252
+ * const contacts = ["010", "011", "016", "017", "018", "019"].map(prefix => ({
253
+ * carrier: prefix,
254
+ * number: RandomGenerator.mobile(prefix)
255
+ * }));
256
+ * ```;
257
+ *
258
+ * @param prefix - The prefix string for the phone number (default: "010")
259
+ * @returns A formatted mobile phone number string
57
260
  */
58
261
  const mobile: (prefix?: string) => string;
59
262
  /**
60
- * Generate random date.
263
+ * Generates a random date within a specified range from a starting point.
264
+ *
265
+ * Creates a currying function that accepts a range in milliseconds and
266
+ * returns a random date between the start date and start date + range. The
267
+ * range represents the maximum number of milliseconds to add to the starting
268
+ * date. Useful for generating timestamps, creation dates, or scheduling test
269
+ * data.
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const now = new Date();
274
+ * const oneDay = 24 * 60 * 60 * 1000;
275
+ * const oneMonth = 30 * oneDay;
276
+ *
277
+ * // Random date within the next 30 days
278
+ * const futureDate = RandomGenerator.date(now)(oneMonth);
279
+ *
280
+ * // Random date within the past week
281
+ * const pastWeek = new Date(now.getTime() - 7 * oneDay);
282
+ * const recentDate = RandomGenerator.date(pastWeek)(7 * oneDay);
283
+ *
284
+ * // Generate random creation dates for test data
285
+ * const startOfYear = new Date(2024, 0, 1);
286
+ * const endOfYear = new Date(2024, 11, 31).getTime() - startOfYear.getTime();
287
+ * const randomCreationDate = RandomGenerator.date(startOfYear)(endOfYear);
61
288
  *
62
- * @param from Start date
63
- * @param range Range of random milliseconds
64
- * @returns Random date
289
+ * // Create test events with random timestamps
290
+ * const events = Array.from({ length: 50 }, () => ({
291
+ * id: RandomGenerator.alphaNumeric(8),
292
+ * title: RandomGenerator.name(2),
293
+ * createdAt: RandomGenerator.date(new Date())(oneMonth),
294
+ * scheduledFor: RandomGenerator.date(new Date())(oneMonth * 3)
295
+ * }));
296
+ * ```;
297
+ *
298
+ * @param from - The starting date for the random range
299
+ * @returns A currying function that accepts a range in milliseconds
65
300
  */
66
301
  const date: (from: Date) => (range: number) => Date;
67
302
  /**
68
- * Pick random elements from an array.
303
+ * Randomly samples a specified number of unique elements from an array.
304
+ *
305
+ * Selects random elements from the input array without replacement, ensuring
306
+ * all returned elements are unique. The sample size is automatically capped
307
+ * at the array length to prevent errors. Uses a Set-based approach to
308
+ * guarantee uniqueness of selected indices. Ideal for creating test datasets
309
+ * or selecting random subsets for validation.
310
+ *
311
+ * @example
312
+ * ```typescript
313
+ * const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
314
+ *
315
+ * RandomGenerator.sample(numbers)(3); // [2, 7, 9]
316
+ * RandomGenerator.sample(numbers)(5); // [1, 4, 6, 8, 10]
317
+ * RandomGenerator.sample(numbers)(15); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (capped at array length)
318
+ *
319
+ * // Sample users for testing
320
+ * const allUsers = await getUsersFromDatabase();
321
+ * const testUsers = RandomGenerator.sample(allUsers)(10);
322
+ *
323
+ * // Create random product selections
324
+ * const featuredProducts = RandomGenerator.sample(allProducts)(5);
325
+ *
326
+ * // Generate test data subsets
327
+ * const validationSet = RandomGenerator.sample(trainingData)(100);
328
+ *
329
+ * // Random A/B testing groups
330
+ * const groupA = RandomGenerator.sample(allParticipants)(50);
331
+ * const remaining = allParticipants.filter(p => !groupA.includes(p));
332
+ * const groupB = RandomGenerator.sample(remaining)(50);
333
+ * ```;
69
334
  *
70
- * @param array Target array
71
- * @param count Number of count to pick
72
- * @returns Sampled array
335
+ * @param array - The source array to sample from
336
+ * @returns A currying function that accepts the desired sample count
73
337
  */
74
338
  const sample: <T>(array: T[]) => (count: number) => T[];
75
339
  /**
76
- * Pick random element from an array.
340
+ * Randomly selects a single element from an array.
341
+ *
342
+ * Chooses one element at random from the provided array using uniform
343
+ * distribution. Each element has an equal probability of being selected. This
344
+ * is a convenience function equivalent to sampling with a count of 1, but
345
+ * returns the element directly rather than an array containing one element.
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
350
+ * const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
351
+ *
352
+ * RandomGenerator.pick(colors); // "blue"
353
+ * RandomGenerator.pick(fruits); // "apple"
354
+ *
355
+ * // Select random configuration options
356
+ * const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
357
+ * const randomLocale = RandomGenerator.pick(['en', 'ko', 'ja', 'zh']);
358
+ *
359
+ * // Choose random test scenarios
360
+ * const testScenario = RandomGenerator.pick([
361
+ * 'happy_path',
362
+ * 'edge_case',
363
+ * 'error_condition',
364
+ * 'boundary_test'
365
+ * ]);
366
+ *
367
+ * // Random user role assignment
368
+ * const userRole = RandomGenerator.pick(['admin', 'user', 'moderator']);
369
+ *
370
+ * // Select random API endpoints for testing
371
+ * const endpoints = ['/users', '/posts', '/comments', '/categories'];
372
+ * const randomEndpoint = RandomGenerator.pick(endpoints);
373
+ * ```;
77
374
  *
78
- * @param array Target array
79
- * @returns picked element
375
+ * @param array - The source array to pick an element from
376
+ * @returns A randomly selected element from the array
80
377
  */
81
378
  const pick: <T>(array: T[]) => T;
82
379
  }