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