@mikemajesty/zod-mock-schema 1.0.13 → 1.0.15

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 (42) hide show
  1. package/README.md +162 -57
  2. package/dist/__tests__/advanced-schemas.spec.d.ts +1 -0
  3. package/dist/__tests__/advanced-schemas.spec.js +149 -0
  4. package/dist/__tests__/advanced-schemas.spec.js.map +1 -0
  5. package/dist/__tests__/brazilian-formats.spec.d.ts +1 -0
  6. package/dist/__tests__/brazilian-formats.spec.js +205 -0
  7. package/dist/__tests__/brazilian-formats.spec.js.map +1 -0
  8. package/dist/__tests__/complex-intersections.spec.d.ts +1 -0
  9. package/dist/__tests__/complex-intersections.spec.js +176 -0
  10. package/dist/__tests__/complex-intersections.spec.js.map +1 -0
  11. package/dist/__tests__/edge-cases.spec.d.ts +1 -0
  12. package/dist/__tests__/edge-cases.spec.js +206 -0
  13. package/dist/__tests__/edge-cases.spec.js.map +1 -0
  14. package/dist/__tests__/faker-injection.spec.d.ts +1 -0
  15. package/dist/__tests__/faker-injection.spec.js +110 -0
  16. package/dist/__tests__/faker-injection.spec.js.map +1 -0
  17. package/dist/__tests__/overrides-all-types.spec.d.ts +1 -0
  18. package/dist/__tests__/overrides-all-types.spec.js +283 -0
  19. package/dist/__tests__/overrides-all-types.spec.js.map +1 -0
  20. package/dist/__tests__/overrides.spec.d.ts +1 -0
  21. package/dist/__tests__/overrides.spec.js +345 -0
  22. package/dist/__tests__/overrides.spec.js.map +1 -0
  23. package/dist/__tests__/unsupported-types.spec.d.ts +1 -0
  24. package/dist/__tests__/unsupported-types.spec.js +27 -0
  25. package/dist/__tests__/unsupported-types.spec.js.map +1 -0
  26. package/dist/__tests__/{zod-mock-schema.spec.d.ts → zod-types.spec.d.ts} +8 -8
  27. package/dist/__tests__/zod-types.spec.js +526 -0
  28. package/dist/__tests__/zod-types.spec.js.map +1 -0
  29. package/dist/constants.d.ts +46 -0
  30. package/dist/constants.js +83 -0
  31. package/dist/constants.js.map +1 -0
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.js +1 -5
  34. package/dist/index.js.map +1 -1
  35. package/dist/types.d.ts +29 -15
  36. package/dist/types.js +1 -2
  37. package/dist/zod-mock-schema.d.ts +17 -20
  38. package/dist/zod-mock-schema.js +324 -236
  39. package/dist/zod-mock-schema.js.map +1 -1
  40. package/package.json +14 -4
  41. package/dist/__tests__/zod-mock-schema.spec.js +0 -357
  42. package/dist/__tests__/zod-mock-schema.spec.js.map +0 -1
package/README.md CHANGED
@@ -4,21 +4,29 @@
4
4
  ![License](https://img.shields.io/badge/License-MIT-yellow.svg)
5
5
  ![TypeScript Ready](https://img.shields.io/badge/TypeScript-Ready-blue.svg)
6
6
 
7
- A powerful and flexible class‑based utility for generating realistic mock data directly from Zod schemas — ideal for testing, prototyping, fixtures, and CI automation.
8
-
9
- ## ✨ Features
10
-
11
- - ✅ Class-based API for full control and extensibility
12
- - ✅ Faker.js integration for realistic fake data
13
- - ✅ Type‑safe overrides with full TypeScript support
14
- - ✅ Deep Zod schema integration with nested object support
15
- - ✅ Custom formats: **CPF, CNPJ, RG, CEP, phone BR**
16
- - ✅ Deterministic generation via Faker seeding
17
- - ✅ Batch creation with `generateMany`
18
- - ✅ Smart prefixing for unique, identifiable data
19
- - ✅ Index‑based generation for sequential data
20
- - ✅ Flexible field customization
21
- - ✅ Full Zod schema support (Union, Intersection, Record, Lazy, Pipe, etc.)
7
+ **Simple, type-safe mock data generator for Zod schemas with built-in Brazilian format support 🇧🇷**
8
+
9
+ A developer-friendly, class-based utility for generating realistic test data from Zod schemas. Perfect for testing, prototyping, and fixtures — with zero configuration and maximum type safety.
10
+
11
+ ## ✨ Why Choose This Library?
12
+
13
+ ### 🎯 **Simplicity First**
14
+ - **Clean class-based API** — instantiate once, generate many times
15
+ - **Zero configuration** — works out of the box with any Zod schema
16
+ - **Type-safe overrides** — full TypeScript intellisense and validation
17
+ - **Intuitive seeding** — `mock.seed(123)` for deterministic tests
18
+
19
+ ### 🇧🇷 **Brazilian Format Support** (Unique Feature)
20
+ - **CPF, CNPJ, RG** — built-in Brazilian document formats
21
+ - **CEP** — postal code generation
22
+ - **Phone BR** — Brazilian phone numbers
23
+ - **Zero dependencies** — no extra libraries needed
24
+
25
+ ### ⚡ **Developer Experience**
26
+ - **Faker.js integration** — realistic, locale-aware fake data
27
+ - **Custom Faker injection** — use different locales per test
28
+ - **Batch generation** — `generateMany()` for multiple mocks
29
+ - **Full Zod v4 support** — Union, Intersection, Record, Lazy, Pipe, and more
22
30
 
23
31
  ---
24
32
 
@@ -52,7 +60,7 @@ const userSchema = z.object({
52
60
  age: z.number().int().min(18).max(99),
53
61
  isActive: z.boolean(),
54
62
  createdAt: z.date(),
55
- });
63
+ });x
56
64
 
57
65
  const userMock = new ZodMockSchema(userSchema);
58
66
 
@@ -98,7 +106,6 @@ userMock.generateMany(3, {
98
106
  overrides: { department: 'Engineering' }
99
107
  });
100
108
  ```
101
-
102
109
  ---
103
110
 
104
111
  ## 🎯 Smart Prefixing System
@@ -127,9 +134,56 @@ userMock.generateMany(3, {
127
134
 
128
135
  ---
129
136
 
130
- ## 🧠 Advanced Zod Schema Support
137
+ ## 🇧🇷 Brazilian Formats (Unique Feature)
138
+
139
+ Generate valid Brazilian documents and identifiers with zero configuration:
140
+
141
+ ```ts
142
+ import { ZodMockSchema, BrazilianFormat } from '@mikemajesty/zod-mock-schema';
143
+
144
+ const userSchema = z.object({
145
+ cpf: z.string().meta({ format: 'cpf' }), // 11-digit CPF
146
+ cnpj: z.string().meta({ format: 'cnpj' }), // 14-digit CNPJ
147
+ rg: z.string().meta({ format: 'rg' }), // Brazilian ID
148
+ phone: z.string().meta({ format: 'phoneBR' }), // BR phone number
149
+ cep: z.string().meta({ format: 'cep' }), // Postal code
150
+ });
151
+
152
+ const mock = new ZodMockSchema(userSchema);
153
+ const user = mock.generate();
154
+ // {
155
+ // cpf: "52998224725",
156
+ // cnpj: "60676960000106",
157
+ // rg: "238192611",
158
+ // phone: "11987654321",
159
+ // cep: "01001000"
160
+ // }
161
+
162
+ // TypeScript support for format validation
163
+ const format: BrazilianFormat = 'cpf'; // Type-safe!
164
+ ```
165
+ ```
166
+
167
+ ### Why This Matters
168
+
169
+ Brazilian formats require specific validation rules that generic mock generators don't understand. This library provides:
170
+
171
+ - ✅ **Pre-validated samples** — all generated values pass real validation
172
+ - ✅ **No external APIs** — works offline, no rate limits
173
+ - ✅ **Deterministic with seeds** — same seed = same CPF/CNPJ
174
+ - ✅ **Works in arrays and nested objects** — generate multiple documents easily
175
+
176
+ ```ts
177
+ // Generate multiple users with valid Brazilian docs
178
+ const users = mock.generateMany(10);
179
+ users.forEach(u => console.log(u.cpf)); // All valid CPFs
180
+ ```
181
+
182
+ ---
183
+
184
+ ## 🧠 Full Zod Schema Support
131
185
 
132
- ### Complex Zod Types
186
+ Supports all Zod types including advanced patterns:
133
187
 
134
188
  ```ts
135
189
  const complexSchema = z.object({
@@ -149,22 +203,6 @@ complexMock.generate();
149
203
 
150
204
  ---
151
205
 
152
- ## 🇧🇷 Custom Brazilian Formats
153
-
154
- ```ts
155
- const brazilSchema = z.object({
156
- cpf: z.string().meta({ format: 'cpf' }),
157
- cnpj: z.string().meta({ format: 'cnpj' }),
158
- rg: z.string().meta({ format: 'rg' }),
159
- phone: z.string().meta({ format: 'phoneBR' }),
160
- cep: z.string().meta({ format: 'cep' }),
161
- });
162
-
163
- new ZodMockSchema(brazilSchema).generate();
164
- ```
165
-
166
- ---
167
-
168
206
  ## 🛒 E-commerce Example
169
207
 
170
208
  ```ts
@@ -188,10 +226,6 @@ orderMock.generateMany(5, {
188
226
  overrides: {
189
227
  status: 'processing',
190
228
  total: 1399.97,
191
- },
192
- prefix: {
193
- options: { useIndex: true },
194
- for: 'id'
195
229
  }
196
230
  });
197
231
  ```
@@ -214,11 +248,7 @@ export class UserFactory {
214
248
 
215
249
  createAdmins(count: number) {
216
250
  return this.mock.generateMany(count, {
217
- overrides: { role: 'admin' },
218
- prefix: {
219
- options: ['ADM', 'ADMIN'],
220
- for: 'username'
221
- }
251
+ overrides: { role: 'admin' }
222
252
  });
223
253
  }
224
254
  }
@@ -231,10 +261,38 @@ export class UserFactory {
231
261
  ### Deterministic Tests
232
262
 
233
263
  ```ts
234
- faker.seed(123);
264
+ const userMock = new ZodMockSchema(userSchema);
265
+ userMock.seed(123);
235
266
  const user = userMock.generate();
236
267
  ```
237
268
 
269
+ ### Custom Faker Instance
270
+
271
+ Inject a custom Faker instance with different locales or configurations:
272
+
273
+ ```ts
274
+ import { Faker, pt_BR } from '@faker-js/faker';
275
+
276
+ const customFaker = new Faker({ locale: pt_BR });
277
+ const user = userMock.generate({ faker: customFaker });
278
+ ```
279
+
280
+ ### Parallel Tests with Isolated Faker Instances
281
+
282
+ ```ts
283
+ test('parallel test 1', () => {
284
+ const faker1 = new Faker({ locale: en });
285
+ faker1.seed(100);
286
+ const user = userMock.generate({ faker: faker1 });
287
+ });
288
+
289
+ test('parallel test 2', () => {
290
+ const faker2 = new Faker({ locale: es });
291
+ faker2.seed(200);
292
+ const user = userMock.generate({ faker: faker2 });
293
+ });
294
+ ```
295
+
238
296
  ### Integration Testing
239
297
 
240
298
  ```ts
@@ -242,12 +300,7 @@ describe('User Service', () => {
242
300
  const userMock = new ZodMockSchema(userSchema);
243
301
 
244
302
  test('should create multiple unique users', () => {
245
- const users = userMock.generateMany(5, {
246
- prefix: {
247
- options: { useIndex: true },
248
- for: 'email'
249
- }
250
- });
303
+ const users = userMock.generateMany(5);
251
304
 
252
305
  const emails = users.map(u => u.email);
253
306
  expect(new Set(emails).size).toBe(5);
@@ -271,6 +324,22 @@ Generates a single mock object.
271
324
  #### `generateMany(count: number, options?: MockManyOptions<T>): T[]`
272
325
  Generates multiple mock objects.
273
326
 
327
+ ### Exported Types
328
+
329
+ #### `MockOptions<T>`
330
+ Configuration options for generating a single mock object.
331
+ - `overrides?: Partial<T>` — Override specific properties
332
+ - `faker?: Faker` — Custom Faker instance for localization
333
+
334
+ #### `MockManyOptions<T>`
335
+ Extends `MockOptions<T>` for batch generation.
336
+
337
+ #### `BrazilianFormat`
338
+ Type-safe union of Brazilian format identifiers:
339
+ ```ts
340
+ type BrazilianFormat = 'cpf' | 'cnpj' | 'rg' | 'phoneBR' | 'cep';
341
+ ```
342
+
274
343
  ---
275
344
 
276
345
  ## 🔄 Supported Zod Types
@@ -285,14 +354,50 @@ Generates multiple mock objects.
285
354
 
286
355
  ## 🧹 Best Practices
287
356
 
288
- - Reuse mock instances
289
- - Use overrides for business rules
290
- - Centralize factories
291
- - Use prefixing for unique data
292
- - Seed Faker for deterministic tests
357
+ ### Keep It Simple
358
+ ```ts
359
+ // ✅ Good: Reuse instances
360
+ const userMock = new ZodMockSchema(userSchema);
361
+ const user1 = userMock.generate();
362
+ const user2 = userMock.generate();
363
+
364
+ // ❌ Avoid: Creating new instances every time
365
+ const user1 = new ZodMockSchema(userSchema).generate();
366
+ const user2 = new ZodMockSchema(userSchema).generate();
367
+ ```
368
+
369
+ ### Use Overrides for Business Logic
370
+ ```ts
371
+ // ✅ Good: Override specific fields
372
+ userMock.generate({ overrides: { role: 'admin', status: 'active' } });
373
+
374
+ // ❌ Avoid: Manually modifying generated data
375
+ const user = userMock.generate();
376
+ user.role = 'admin'; // Bypasses Zod validation
377
+ ```
378
+
379
+ ### Centralize Test Factories
380
+ ```ts
381
+ // ✅ Good: Single source of truth
382
+ export const UserFactory = new ZodMockSchema(userSchema);
383
+
384
+ // In tests:
385
+ import { UserFactory } from './factories';
386
+ const admin = UserFactory.generate({ overrides: { role: 'admin' } });
387
+ ```
388
+
389
+ ### Use Seeds for Deterministic Tests
390
+ ```ts
391
+ // ✅ Good: Reproducible tests
392
+ test('user creation', () => {
393
+ userMock.seed(12345);
394
+ const user = userMock.generate();
395
+ expect(user.name).toBe('Alice'); // Always the same with same seed
396
+ });
397
+ ```
293
398
 
294
399
  ---
295
400
 
296
401
  ## 📄 License
297
402
 
298
- MIT © Mike Majesty
403
+ MIT © Mike Majesty
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,149 @@
1
+ import { z } from 'zod';
2
+ import { ZodMockSchema } from '../zod-mock-schema.js';
3
+ const AdvancedUserSchema = z.object({
4
+ tags: z.set(z.string()),
5
+ metadata: z.map(z.string(), z.number()),
6
+ coordinates: z.tuple([z.number(), z.number(), z.string()]),
7
+ preferences: z.object({
8
+ notifications: z.boolean(),
9
+ theme: z.string()
10
+ }).readonly(),
11
+ name: z.string().min(3).max(50),
12
+ email: z.email(),
13
+ website: z.url(),
14
+ userId: z.uuid(),
15
+ code: z.string().regex(/^[A-Z]{3}-[0-9]{4}$/),
16
+ age: z.number().int().positive().min(18).max(120),
17
+ balance: z.number().nonnegative(),
18
+ score: z.number().min(0).max(100),
19
+ createdAt: z.date().min(new Date('2020-01-01')),
20
+ updatedAt: z.date().max(new Date()),
21
+ eventDate: z.date().min(new Date(Date.now() - 365 * 24 * 60 * 60 * 1000)).max(new Date()),
22
+ status: z.string().default('active'),
23
+ level: z.number().default(1),
24
+ contact: z.discriminatedUnion('type', [
25
+ z.object({ type: z.literal('email'), address: z.email() }),
26
+ z.object({ type: z.literal('phone'), number: z.string() })
27
+ ]),
28
+ username: z.string().transform((val) => val.toLowerCase()),
29
+ rating: z.number().min(0).max(5)
30
+ });
31
+ const ComplexSystemSchema = z.object({
32
+ users: z.set(z.object({ id: z.number(), name: z.string() })).min(1),
33
+ permissions: z.map(z.string(), z.object({ read: z.boolean(), write: z.boolean() })),
34
+ logEntry: z.tuple([z.date(), z.string(), z.number()]).rest(z.any()),
35
+ immutableList: z.array(z.string()).readonly(),
36
+ events: z.array(z.discriminatedUnion('eventType', [
37
+ z.object({ eventType: z.literal('login'), timestamp: z.date(), userId: z.string() }),
38
+ z.object({ eventType: z.literal('logout'), timestamp: z.date(), userId: z.string() }),
39
+ z.object({ eventType: z.literal('error'), timestamp: z.date(), message: z.string() })
40
+ ]))
41
+ });
42
+ describe('New Types Support - Advanced Schemas', () => {
43
+ describe('AdvancedUserSchema', () => {
44
+ it('should generate complete user with all new types and improved constraints', () => {
45
+ const result = new ZodMockSchema(AdvancedUserSchema).generate();
46
+ expect(result.tags).toBeInstanceOf(Set);
47
+ expect(result.tags.size).toBeGreaterThan(0);
48
+ expect(result.metadata).toBeInstanceOf(Map);
49
+ expect(result.metadata.size).toBeGreaterThan(0);
50
+ expect(Array.isArray(result.coordinates)).toBe(true);
51
+ expect(result.coordinates.length).toBe(3);
52
+ expect(typeof result.coordinates[0]).toBe('number');
53
+ expect(typeof result.coordinates[1]).toBe('number');
54
+ expect(typeof result.coordinates[2]).toBe('string');
55
+ expect(result.preferences).toHaveProperty('notifications');
56
+ expect(result.preferences).toHaveProperty('theme');
57
+ expect(result.name.length).toBeGreaterThanOrEqual(3);
58
+ expect(result.name.length).toBeLessThanOrEqual(50);
59
+ expect(result.email).toMatch(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
60
+ expect(result.website).toMatch(/^https?:\/\//);
61
+ expect(result.userId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
62
+ expect(result.code).toMatch(/^[A-Z]{3}-[0-9]{4}$/);
63
+ expect(result.age).toBeGreaterThanOrEqual(18);
64
+ expect(result.age).toBeLessThanOrEqual(120);
65
+ expect(Number.isInteger(result.age)).toBe(true);
66
+ expect(result.balance).toBeGreaterThanOrEqual(0);
67
+ expect(result.score).toBeGreaterThanOrEqual(0);
68
+ expect(result.score).toBeLessThanOrEqual(100);
69
+ expect(result.createdAt).toBeInstanceOf(Date);
70
+ expect(result.createdAt.getTime()).toBeGreaterThanOrEqual(new Date('2020-01-01').getTime());
71
+ expect(result.updatedAt).toBeInstanceOf(Date);
72
+ expect(result.updatedAt.getTime()).toBeLessThanOrEqual(new Date().getTime());
73
+ expect(result.eventDate).toBeInstanceOf(Date);
74
+ expect(result.eventDate.getTime()).toBeGreaterThanOrEqual(Date.now() - 365 * 24 * 60 * 60 * 1000);
75
+ expect(result.eventDate.getTime()).toBeLessThanOrEqual(Date.now());
76
+ expect(result.status).toBe('active');
77
+ expect(result.level).toBe(1);
78
+ expect(result.contact).toHaveProperty('type');
79
+ expect(['email', 'phone']).toContain(result.contact.type);
80
+ expect(typeof result.username).toBe('string');
81
+ expect(typeof result.rating).toBe('number');
82
+ });
83
+ it('should generate multiple users consistently', () => {
84
+ const users = new ZodMockSchema(AdvancedUserSchema).generateMany(3);
85
+ expect(users).toHaveLength(3);
86
+ users.forEach(user => {
87
+ expect(user.age).toBeGreaterThanOrEqual(18);
88
+ expect(user.status).toBe('active');
89
+ expect(user.level).toBe(1);
90
+ });
91
+ });
92
+ it('should respect overrides for simple fields', () => {
93
+ const result = new ZodMockSchema(AdvancedUserSchema).generate({
94
+ overrides: {
95
+ name: 'Custom Name',
96
+ age: 25
97
+ }
98
+ });
99
+ expect(result.name).toBe('Custom Name');
100
+ expect(result.age).toBe(25);
101
+ expect(result.status).toBe('active');
102
+ });
103
+ });
104
+ describe('ComplexSystemSchema', () => {
105
+ it('should generate system with complex nested types', () => {
106
+ const result = new ZodMockSchema(ComplexSystemSchema).generate();
107
+ expect(result.users).toBeInstanceOf(Set);
108
+ expect(result.users.size).toBeGreaterThanOrEqual(1);
109
+ result.users.forEach(user => {
110
+ expect(user).toHaveProperty('id');
111
+ expect(user).toHaveProperty('name');
112
+ expect(typeof user.id).toBe('number');
113
+ expect(typeof user.name).toBe('string');
114
+ });
115
+ expect(result.permissions).toBeInstanceOf(Map);
116
+ result.permissions.forEach((value, key) => {
117
+ expect(typeof key).toBe('string');
118
+ expect(value).toHaveProperty('read');
119
+ expect(value).toHaveProperty('write');
120
+ expect(typeof value.read).toBe('boolean');
121
+ expect(typeof value.write).toBe('boolean');
122
+ });
123
+ expect(Array.isArray(result.logEntry)).toBe(true);
124
+ expect(result.logEntry.length).toBeGreaterThanOrEqual(3);
125
+ expect(result.logEntry[0]).toBeInstanceOf(Date);
126
+ expect(typeof result.logEntry[1]).toBe('string');
127
+ expect(typeof result.logEntry[2]).toBe('number');
128
+ expect(Array.isArray(result.immutableList)).toBe(true);
129
+ expect(Array.isArray(result.events)).toBe(true);
130
+ result.events.forEach(event => {
131
+ expect(event).toHaveProperty('eventType');
132
+ expect(['login', 'logout', 'error']).toContain(event.eventType);
133
+ expect(event).toHaveProperty('timestamp');
134
+ expect(event.timestamp).toBeInstanceOf(Date);
135
+ });
136
+ });
137
+ });
138
+ describe('Seed Support with New Types', () => {
139
+ it('should generate consistent data when using same seed', () => {
140
+ const SimpleSchema = z.object({
141
+ code: z.string().regex(/^[A-Z]{3}-[0-9]{4}$/)
142
+ });
143
+ const result1 = new ZodMockSchema(SimpleSchema).seed(999).generate();
144
+ const result2 = new ZodMockSchema(SimpleSchema).seed(999).generate();
145
+ expect(result1.code).toBe(result2.code);
146
+ });
147
+ });
148
+ });
149
+ //# sourceMappingURL=advanced-schemas.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advanced-schemas.spec.js","sourceRoot":"","sources":["../../src/__tests__/advanced-schemas.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAElC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IACvC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,aAAa,EAAE,CAAC,CAAC,OAAO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schema.js';
3
+ describe('Brazilian Formats', () => {
4
+ describe('CPF Format', () => {
5
+ it('should generate valid CPF when using meta format', () => {
6
+ const schema = z.string().meta({ format: 'cpf' });
7
+ const mock = new ZodMockSchema(schema);
8
+ const result = mock.generate();
9
+ expect(typeof result).toBe('string');
10
+ expect(result).toMatch(/^\d{11}$/);
11
+ });
12
+ it('should generate multiple different CPFs', () => {
13
+ const schema = z.string().meta({ format: 'cpf' });
14
+ const mock = new ZodMockSchema(schema);
15
+ const results = Array.from({ length: 10 }, () => mock.generate());
16
+ const uniqueResults = new Set(results);
17
+ expect(uniqueResults.size).toBeGreaterThan(1);
18
+ });
19
+ it('should work in complex objects', () => {
20
+ const schema = z.object({
21
+ name: z.string(),
22
+ cpf: z.string().meta({ format: 'cpf' }),
23
+ age: z.number()
24
+ });
25
+ const mock = new ZodMockSchema(schema);
26
+ const result = mock.generate();
27
+ expect(result.cpf).toMatch(/^\d{11}$/);
28
+ });
29
+ });
30
+ describe('CNPJ Format', () => {
31
+ it('should generate valid CNPJ when using meta format', () => {
32
+ const schema = z.string().meta({ format: 'cnpj' });
33
+ const mock = new ZodMockSchema(schema);
34
+ const result = mock.generate();
35
+ expect(typeof result).toBe('string');
36
+ expect(result).toMatch(/^\d{14}$/);
37
+ });
38
+ it('should generate multiple different CNPJs', () => {
39
+ const schema = z.string().meta({ format: 'cnpj' });
40
+ const mock = new ZodMockSchema(schema);
41
+ const results = Array.from({ length: 10 }, () => mock.generate());
42
+ const uniqueResults = new Set(results);
43
+ expect(uniqueResults.size).toBeGreaterThan(1);
44
+ });
45
+ });
46
+ describe('RG Format', () => {
47
+ it('should generate valid RG when using meta format', () => {
48
+ const schema = z.string().meta({ format: 'rg' });
49
+ const mock = new ZodMockSchema(schema);
50
+ const result = mock.generate();
51
+ expect(typeof result).toBe('string');
52
+ expect(result).toMatch(/^\d{9}$/);
53
+ });
54
+ it('should generate multiple different RGs', () => {
55
+ const schema = z.string().meta({ format: 'rg' });
56
+ const mock = new ZodMockSchema(schema);
57
+ const results = Array.from({ length: 10 }, () => mock.generate());
58
+ const uniqueResults = new Set(results);
59
+ expect(uniqueResults.size).toBeGreaterThan(1);
60
+ });
61
+ });
62
+ describe('Brazilian Phone Format', () => {
63
+ it('should generate valid Brazilian phone when using meta format', () => {
64
+ const schema = z.string().meta({ format: 'phoneBR' });
65
+ const mock = new ZodMockSchema(schema);
66
+ const result = mock.generate();
67
+ expect(typeof result).toBe('string');
68
+ expect(result).toMatch(/^\d{11}$/);
69
+ });
70
+ it('should generate multiple different phone numbers', () => {
71
+ const schema = z.string().meta({ format: 'phoneBR' });
72
+ const mock = new ZodMockSchema(schema);
73
+ const results = Array.from({ length: 10 }, () => mock.generate());
74
+ const uniqueResults = new Set(results);
75
+ expect(uniqueResults.size).toBeGreaterThan(1);
76
+ });
77
+ });
78
+ describe('CEP Format', () => {
79
+ it('should generate valid CEP when using meta format', () => {
80
+ const schema = z.string().meta({ format: 'cep' });
81
+ const mock = new ZodMockSchema(schema);
82
+ const result = mock.generate();
83
+ expect(typeof result).toBe('string');
84
+ expect(result).toMatch(/^\d{8}$/);
85
+ });
86
+ it('should generate multiple different CEPs', () => {
87
+ const schema = z.string().meta({ format: 'cep' });
88
+ const mock = new ZodMockSchema(schema);
89
+ const results = Array.from({ length: 10 }, () => mock.generate());
90
+ const uniqueResults = new Set(results);
91
+ expect(uniqueResults.size).toBeGreaterThan(1);
92
+ });
93
+ });
94
+ describe('Complete Brazilian Person Schema', () => {
95
+ const BrazilianPersonSchema = z.object({
96
+ name: z.string().min(3).max(100),
97
+ cpf: z.string().meta({ format: 'cpf' }),
98
+ rg: z.string().meta({ format: 'rg' }),
99
+ phone: z.string().meta({ format: 'phoneBR' }),
100
+ address: z.object({
101
+ street: z.string(),
102
+ number: z.string(),
103
+ complement: z.string().optional(),
104
+ neighborhood: z.string(),
105
+ city: z.string(),
106
+ state: z.string().length(2),
107
+ cep: z.string().meta({ format: 'cep' })
108
+ }),
109
+ company: z.object({
110
+ name: z.string(),
111
+ cnpj: z.string().meta({ format: 'cnpj' }),
112
+ phone: z.string().meta({ format: 'phoneBR' })
113
+ }).optional()
114
+ });
115
+ it('should generate complete Brazilian person data', () => {
116
+ const mock = new ZodMockSchema(BrazilianPersonSchema);
117
+ const result = mock.generate();
118
+ expect(result.cpf).toMatch(/^\d{11}$/);
119
+ expect(result.rg).toMatch(/^\d{9}$/);
120
+ expect(result.phone).toMatch(/^\d{11}$/);
121
+ expect(result.address.cep).toMatch(/^\d{8}$/);
122
+ });
123
+ it('should generate multiple different people', () => {
124
+ const mock = new ZodMockSchema(BrazilianPersonSchema);
125
+ const results = mock.generateMany(5);
126
+ expect(results).toHaveLength(5);
127
+ const cpfs = results.map(r => r.cpf);
128
+ const uniqueCpfs = new Set(cpfs);
129
+ expect(uniqueCpfs.size).toBeGreaterThan(1);
130
+ });
131
+ it('should respect overrides with Brazilian formats', () => {
132
+ const mock = new ZodMockSchema(BrazilianPersonSchema);
133
+ const customCpf = '12345678909';
134
+ const result = mock.generate({
135
+ overrides: {
136
+ cpf: customCpf,
137
+ name: 'João Silva'
138
+ }
139
+ });
140
+ expect(result.cpf).toBe(customCpf);
141
+ expect(result.name).toBe('João Silva');
142
+ expect(result.rg).toMatch(/^\d{9}$/);
143
+ });
144
+ });
145
+ describe('Mixed Formats Schema', () => {
146
+ it('should handle mix of Brazilian and international formats', () => {
147
+ const schema = z.object({
148
+ cpf: z.string().meta({ format: 'cpf' }),
149
+ email: z.email(),
150
+ uuid: z.uuid(),
151
+ url: z.url(),
152
+ phone: z.string().meta({ format: 'phoneBR' }),
153
+ cep: z.string().meta({ format: 'cep' })
154
+ });
155
+ const mock = new ZodMockSchema(schema);
156
+ const result = mock.generate();
157
+ expect(result.cpf).toMatch(/^\d{11}$/);
158
+ expect(result.email).toContain('@');
159
+ expect(result.uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
160
+ expect(result.url).toMatch(/^https?:\/\//);
161
+ expect(result.phone).toMatch(/^\d{11}$/);
162
+ expect(result.cep).toMatch(/^\d{8}$/);
163
+ });
164
+ });
165
+ describe('Brazilian Formats in Arrays', () => {
166
+ it('should generate arrays of CPFs', () => {
167
+ const schema = z.array(z.string().meta({ format: 'cpf' })).min(3).max(3);
168
+ const mock = new ZodMockSchema(schema);
169
+ const result = mock.generate();
170
+ expect(result).toHaveLength(3);
171
+ result.forEach(cpf => {
172
+ expect(cpf).toMatch(/^\d{11}$/);
173
+ });
174
+ });
175
+ it('should generate arrays of mixed Brazilian formats', () => {
176
+ const schema = z.array(z.object({
177
+ type: z.enum(['cpf', 'cnpj']),
178
+ value: z.string()
179
+ }));
180
+ const mock = new ZodMockSchema(schema);
181
+ const result = mock.generate();
182
+ expect(Array.isArray(result)).toBe(true);
183
+ expect(result.length).toBeGreaterThan(0);
184
+ });
185
+ });
186
+ describe('Seed Consistency with Brazilian Formats', () => {
187
+ it('should generate same Brazilian data with same seed', () => {
188
+ const schema = z.object({
189
+ cpf: z.string().meta({ format: 'cpf' }),
190
+ cnpj: z.string().meta({ format: 'cnpj' }),
191
+ cep: z.string().meta({ format: 'cep' })
192
+ });
193
+ const mock1 = new ZodMockSchema(schema);
194
+ mock1.seed(12345);
195
+ const result1 = mock1.generate();
196
+ const mock2 = new ZodMockSchema(schema);
197
+ mock2.seed(12345);
198
+ const result2 = mock2.generate();
199
+ expect(result1.cpf).toBe(result2.cpf);
200
+ expect(result1.cnpj).toBe(result2.cnpj);
201
+ expect(result1.cep).toBe(result2.cep);
202
+ });
203
+ });
204
+ });
205
+ //# sourceMappingURL=brazilian-formats.spec.js.map