@schmock/faker 2.3.0 → 2.4.0
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.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/constants.d.ts +82 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/field-name-matcher.d.ts +19 -0
- package/dist/field-name-matcher.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/jsf-config.d.ts +19 -4
- package/dist/jsf-config.d.ts.map +1 -1
- package/dist/output-limits.d.ts +3 -0
- package/dist/output-limits.d.ts.map +1 -0
- package/dist/overrides.d.ts +2 -1
- package/dist/overrides.d.ts.map +1 -1
- package/dist/schema-children.d.ts +14 -0
- package/dist/schema-children.d.ts.map +1 -0
- package/dist/schema-enhancement.d.ts +1 -0
- package/dist/schema-enhancement.d.ts.map +1 -1
- package/dist/validation.d.ts +24 -5
- package/dist/validation.d.ts.map +1 -1
- package/package.json +21 -7
- package/dist/constants.js +0 -8
- package/dist/field-mappings.js +0 -1114
- package/dist/field-name-matcher.js +0 -148
- package/dist/jsf-config.js +0 -117
- package/dist/overrides.js +0 -137
- package/dist/schema-enhancement.js +0 -104
- package/dist/test-utils.d.ts +0 -57
- package/dist/test-utils.d.ts.map +0 -1
- package/dist/test-utils.js +0 -284
- package/dist/validation.js +0 -300
- package/src/advanced-features.test.ts +0 -912
- package/src/audit-faker-args.test.ts +0 -97
- package/src/constants.d.ts.map +0 -1
- package/src/constants.ts +0 -9
- package/src/data-quality.test.ts +0 -415
- package/src/error-handling.test.ts +0 -504
- package/src/field-mappings.test.ts +0 -351
- package/src/field-mappings.ts +0 -1148
- package/src/field-name-matcher.test.ts +0 -292
- package/src/field-name-matcher.ts +0 -187
- package/src/index.d.ts.map +0 -1
- package/src/index.test.ts +0 -1320
- package/src/index.ts +0 -185
- package/src/integration.test.ts +0 -634
- package/src/jsf-config.d.ts.map +0 -1
- package/src/jsf-config.test.ts +0 -65
- package/src/jsf-config.ts +0 -156
- package/src/overrides.d.ts.map +0 -1
- package/src/overrides.property.test.ts +0 -172
- package/src/overrides.test.ts +0 -38
- package/src/overrides.ts +0 -179
- package/src/performance.test.ts +0 -441
- package/src/plugin-integration.test.ts +0 -575
- package/src/post-process.test.ts +0 -177
- package/src/real-world.test.ts +0 -636
- package/src/schema-enhancement.d.ts.map +0 -1
- package/src/schema-enhancement.test.ts +0 -222
- package/src/schema-enhancement.ts +0 -144
- package/src/steps/deterministic-seeds.steps.ts +0 -112
- package/src/steps/faker-plugin.steps.ts +0 -301
- package/src/test-utils.ts +0 -385
- package/src/validation.d.ts.map +0 -1
- package/src/validation.ts +0 -417
package/src/performance.test.ts
DELETED
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import type { JSONSchema7 } from "json-schema";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { fakerPlugin, generateFromSchema } from "./index";
|
|
4
|
-
import { generate, schemas } from "./test-utils";
|
|
5
|
-
|
|
6
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
7
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function expectRecord(
|
|
11
|
-
value: unknown,
|
|
12
|
-
): asserts value is Record<string, unknown> {
|
|
13
|
-
expect(isRecord(value)).toBe(true);
|
|
14
|
-
if (!isRecord(value)) throw new Error("Expected generated object data");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function expectGeneratedUser(value: unknown): void {
|
|
18
|
-
expectRecord(value);
|
|
19
|
-
expect(value.id).toEqual(expect.any(String));
|
|
20
|
-
expect(value.email).toEqual(expect.any(String));
|
|
21
|
-
expect(value.firstName).toEqual(expect.any(String));
|
|
22
|
-
expect(value.lastName).toEqual(expect.any(String));
|
|
23
|
-
expect(value.createdAt).toEqual(expect.any(String));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function pluginContext(): Schmock.PluginContext {
|
|
27
|
-
return {
|
|
28
|
-
method: "GET",
|
|
29
|
-
path: "/test",
|
|
30
|
-
params: {},
|
|
31
|
-
query: {},
|
|
32
|
-
state: new Map(),
|
|
33
|
-
routeState: {},
|
|
34
|
-
headers: {},
|
|
35
|
-
body: null,
|
|
36
|
-
route: {},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("Faker generation workload reliability", () => {
|
|
41
|
-
describe("Representative schema workloads", () => {
|
|
42
|
-
it("preserves simple object shape across repeated generation", async () => {
|
|
43
|
-
const schema = schemas.simple.object({
|
|
44
|
-
id: schemas.simple.number(),
|
|
45
|
-
name: schemas.simple.string(),
|
|
46
|
-
active: { type: "boolean" },
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
for (let seed = 0; seed < 10; seed += 1) {
|
|
50
|
-
const result = await generateFromSchema({ schema, seed });
|
|
51
|
-
expectRecord(result);
|
|
52
|
-
expect(result.id).toEqual(expect.any(Number));
|
|
53
|
-
expect(result.name).toEqual(expect.any(String));
|
|
54
|
-
expect(result.active).toEqual(expect.any(Boolean));
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("preserves a three-level nested object shape", async () => {
|
|
59
|
-
const schema = schemas.nested.deep(
|
|
60
|
-
3,
|
|
61
|
-
schemas.simple.object({
|
|
62
|
-
id: schemas.simple.number(),
|
|
63
|
-
value: schemas.simple.string(),
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
let level = await generateFromSchema({ schema, seed: 42 });
|
|
68
|
-
for (let depth = 0; depth < 3; depth += 1) {
|
|
69
|
-
expectRecord(level);
|
|
70
|
-
level = level.nested;
|
|
71
|
-
}
|
|
72
|
-
expectRecord(level);
|
|
73
|
-
expect(level.id).toEqual(expect.any(Number));
|
|
74
|
-
expect(level.value).toEqual(expect.any(String));
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("generates every item in a fixed-size object array", async () => {
|
|
78
|
-
const schema = schemas.simple.array(
|
|
79
|
-
schemas.simple.object({
|
|
80
|
-
id: schemas.simple.number(),
|
|
81
|
-
name: schemas.simple.string(),
|
|
82
|
-
}),
|
|
83
|
-
{ minItems: 50, maxItems: 50 },
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
87
|
-
expect(Array.isArray(result)).toBe(true);
|
|
88
|
-
if (!Array.isArray(result)) throw new Error("Expected generated array");
|
|
89
|
-
expect(result).toHaveLength(50);
|
|
90
|
-
for (const item of result) {
|
|
91
|
-
expectRecord(item);
|
|
92
|
-
expect(item.id).toEqual(expect.any(Number));
|
|
93
|
-
expect(item.name).toEqual(expect.any(String));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("honors constraints in a complex collection schema", async () => {
|
|
98
|
-
const schema: JSONSchema7 = {
|
|
99
|
-
type: "object",
|
|
100
|
-
properties: {
|
|
101
|
-
users: {
|
|
102
|
-
type: "array",
|
|
103
|
-
items: {
|
|
104
|
-
type: "object",
|
|
105
|
-
properties: {
|
|
106
|
-
id: { type: "string", format: "uuid" },
|
|
107
|
-
email: { type: "string", format: "email" },
|
|
108
|
-
age: { type: "integer", minimum: 18, maximum: 100 },
|
|
109
|
-
tags: {
|
|
110
|
-
type: "array",
|
|
111
|
-
items: { type: "string", pattern: "^[a-z]+$" },
|
|
112
|
-
maxItems: 5,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
required: ["id", "email"],
|
|
116
|
-
},
|
|
117
|
-
minItems: 10,
|
|
118
|
-
maxItems: 10,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
required: ["users"],
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
125
|
-
expectRecord(result);
|
|
126
|
-
expect(Array.isArray(result.users)).toBe(true);
|
|
127
|
-
if (!Array.isArray(result.users)) {
|
|
128
|
-
throw new Error("Expected users collection");
|
|
129
|
-
}
|
|
130
|
-
expect(result.users).toHaveLength(10);
|
|
131
|
-
for (const user of result.users) {
|
|
132
|
-
expectRecord(user);
|
|
133
|
-
expect(user.id).toMatch(
|
|
134
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
135
|
-
);
|
|
136
|
-
expect(user.email).toEqual(expect.any(String));
|
|
137
|
-
expect(user.age).toBeGreaterThanOrEqual(18);
|
|
138
|
-
expect(user.age).toBeLessThanOrEqual(100);
|
|
139
|
-
expect(Array.isArray(user.tags)).toBe(true);
|
|
140
|
-
if (!Array.isArray(user.tags)) throw new Error("Expected user tags");
|
|
141
|
-
expect(user.tags.length).toBeLessThanOrEqual(5);
|
|
142
|
-
for (const tag of user.tags) expect(tag).toMatch(/^[a-z]+$/);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("handles both small and large fixed array workloads", async () => {
|
|
147
|
-
const sizes = [50, 500];
|
|
148
|
-
|
|
149
|
-
for (const size of sizes) {
|
|
150
|
-
const schema = schemas.simple.array(schemas.simple.string(), {
|
|
151
|
-
minItems: size,
|
|
152
|
-
maxItems: size,
|
|
153
|
-
});
|
|
154
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
155
|
-
expect(Array.isArray(result)).toBe(true);
|
|
156
|
-
if (!Array.isArray(result)) throw new Error("Expected generated array");
|
|
157
|
-
expect(result).toHaveLength(size);
|
|
158
|
-
expect(result.every((item) => typeof item === "string")).toBe(true);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("handles both narrow and wide object workloads", async () => {
|
|
163
|
-
for (const width of [20, 100]) {
|
|
164
|
-
const result = await generateFromSchema({
|
|
165
|
-
schema: schemas.nested.wide(width),
|
|
166
|
-
seed: 42,
|
|
167
|
-
});
|
|
168
|
-
expectRecord(result);
|
|
169
|
-
expect(Object.keys(result)).toHaveLength(width);
|
|
170
|
-
expect(
|
|
171
|
-
Object.values(result).every((value) => typeof value === "string"),
|
|
172
|
-
).toBe(true);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe("Plugin workloads", () => {
|
|
178
|
-
it("constructs a plugin with stable metadata", () => {
|
|
179
|
-
const plugin = fakerPlugin({ schema: schemas.complex.user() });
|
|
180
|
-
|
|
181
|
-
expect(plugin.name).toBe("faker");
|
|
182
|
-
expect(plugin.version).toMatch(/^\d+\.\d+\.\d+/);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("generates a complete response through repeated plugin processing", async () => {
|
|
186
|
-
const plugin = fakerPlugin({
|
|
187
|
-
schema: schemas.complex.apiResponse(),
|
|
188
|
-
seed: 42,
|
|
189
|
-
});
|
|
190
|
-
const context = pluginContext();
|
|
191
|
-
let firstResponse: unknown;
|
|
192
|
-
|
|
193
|
-
for (let iteration = 0; iteration < 10; iteration += 1) {
|
|
194
|
-
const result = await plugin.process(context);
|
|
195
|
-
expect(result.context).toBe(context);
|
|
196
|
-
expectRecord(result.response);
|
|
197
|
-
expect(result.response.success).toEqual(expect.any(Boolean));
|
|
198
|
-
expect(Array.isArray(result.response.data)).toBe(true);
|
|
199
|
-
if (iteration === 0) firstResponse = result.response;
|
|
200
|
-
else expect(result.response).toEqual(firstResponse);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("applies template overrides under a representative workload", async () => {
|
|
205
|
-
const schema = schemas.simple.object({
|
|
206
|
-
id: schemas.simple.string(),
|
|
207
|
-
userId: schemas.simple.string(),
|
|
208
|
-
timestamp: schemas.simple.string(),
|
|
209
|
-
message: schemas.simple.string(),
|
|
210
|
-
});
|
|
211
|
-
const timestamp = "2026-07-12T12:00:00.000Z";
|
|
212
|
-
|
|
213
|
-
const result = await generateFromSchema({
|
|
214
|
-
schema,
|
|
215
|
-
seed: 42,
|
|
216
|
-
overrides: {
|
|
217
|
-
id: "{{params.id}}",
|
|
218
|
-
userId: "{{state.user.id}}",
|
|
219
|
-
timestamp: "{{state.timestamp}}",
|
|
220
|
-
message: "User {{params.id}} at {{state.timestamp}}",
|
|
221
|
-
},
|
|
222
|
-
params: { id: "123" },
|
|
223
|
-
state: { user: { id: "user-456" }, timestamp },
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
expect(result).toEqual({
|
|
227
|
-
id: "123",
|
|
228
|
-
userId: "user-456",
|
|
229
|
-
timestamp,
|
|
230
|
-
message: `User 123 at ${timestamp}`,
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe("Concurrent and repeated workloads", () => {
|
|
236
|
-
it("keeps twenty concurrent generations isolated and well formed", async () => {
|
|
237
|
-
const schema = schemas.complex.user();
|
|
238
|
-
const results = await Promise.all(
|
|
239
|
-
Array.from({ length: 20 }, (_, seed) =>
|
|
240
|
-
generateFromSchema({ schema, seed }),
|
|
241
|
-
),
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
expect(results).toHaveLength(20);
|
|
245
|
-
for (const result of results) expectGeneratedUser(result);
|
|
246
|
-
expect(
|
|
247
|
-
new Set(results.map((result) => JSON.stringify(result))).size,
|
|
248
|
-
).toBe(20);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it("preserves shape under a hundred sequential generations", async () => {
|
|
252
|
-
const schema = schemas.simple.object({
|
|
253
|
-
id: schemas.simple.number(),
|
|
254
|
-
data: schemas.simple.string(),
|
|
255
|
-
});
|
|
256
|
-
const results: unknown[] = [];
|
|
257
|
-
|
|
258
|
-
for (let seed = 0; seed < 100; seed += 1) {
|
|
259
|
-
const result = await generateFromSchema({ schema, seed });
|
|
260
|
-
expectRecord(result);
|
|
261
|
-
expect(result.id).toEqual(expect.any(Number));
|
|
262
|
-
expect(result.data).toEqual(expect.any(String));
|
|
263
|
-
results.push(result);
|
|
264
|
-
}
|
|
265
|
-
expect(
|
|
266
|
-
new Set(results.map((result) => JSON.stringify(result))).size,
|
|
267
|
-
).toBe(100);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it("preserves generated shape across a thousand calls", async () => {
|
|
271
|
-
const schema = schemas.simple.object({
|
|
272
|
-
id: schemas.simple.number(),
|
|
273
|
-
name: schemas.simple.string(),
|
|
274
|
-
});
|
|
275
|
-
const serializedResults = new Set<string>();
|
|
276
|
-
|
|
277
|
-
for (let seed = 0; seed < 1_000; seed += 1) {
|
|
278
|
-
const result = await generateFromSchema({ schema, seed });
|
|
279
|
-
expectRecord(result);
|
|
280
|
-
expect(result.id).toEqual(expect.any(Number));
|
|
281
|
-
expect(result.name).toEqual(expect.any(String));
|
|
282
|
-
serializedResults.add(JSON.stringify(result));
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
expect(serializedResults.size).toBe(1_000);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("generates a thousand-item data structure", async () => {
|
|
289
|
-
const schema = schemas.simple.array(
|
|
290
|
-
schemas.simple.object({
|
|
291
|
-
id: schemas.simple.string(),
|
|
292
|
-
data: schemas.simple.string(),
|
|
293
|
-
}),
|
|
294
|
-
{ minItems: 1_000, maxItems: 1_000 },
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
298
|
-
expect(Array.isArray(result)).toBe(true);
|
|
299
|
-
if (!Array.isArray(result)) throw new Error("Expected generated array");
|
|
300
|
-
expect(result).toHaveLength(1_000);
|
|
301
|
-
for (const item of result) {
|
|
302
|
-
expectRecord(item);
|
|
303
|
-
expect(item.id).toEqual(expect.any(String));
|
|
304
|
-
expect(item.data).toEqual(expect.any(String));
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("recovers after repeated resource-limit failures", async () => {
|
|
309
|
-
const oversizedSchema = schemas.simple.array(schemas.simple.string(), {
|
|
310
|
-
minItems: 50_001,
|
|
311
|
-
maxItems: 50_001,
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
for (let iteration = 0; iteration < 100; iteration += 1) {
|
|
315
|
-
await expect(
|
|
316
|
-
generateFromSchema({ schema: oversizedSchema }),
|
|
317
|
-
).rejects.toThrow("array_max_items");
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
const recovered = await generateFromSchema({
|
|
321
|
-
schema: schemas.simple.object({ id: schemas.simple.number() }),
|
|
322
|
-
seed: 42,
|
|
323
|
-
});
|
|
324
|
-
expectRecord(recovered);
|
|
325
|
-
expect(recovered.id).toEqual(expect.any(Number));
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
describe("Repeated mapping and edge-case workloads", () => {
|
|
330
|
-
it("keeps smart field mapping valid across multiple seeds", async () => {
|
|
331
|
-
const schema = schemas.simple.object({
|
|
332
|
-
email: schemas.simple.string(),
|
|
333
|
-
firstName: schemas.simple.string(),
|
|
334
|
-
phone: schemas.simple.string(),
|
|
335
|
-
});
|
|
336
|
-
const results: Record<string, unknown>[] = [];
|
|
337
|
-
|
|
338
|
-
for (let seed = 0; seed < 10; seed += 1) {
|
|
339
|
-
const result = await generateFromSchema({ schema, seed });
|
|
340
|
-
expectRecord(result);
|
|
341
|
-
expect(result.email).toEqual(expect.any(String));
|
|
342
|
-
expect(result.firstName).toEqual(expect.any(String));
|
|
343
|
-
expect(result.phone).toEqual(expect.any(String));
|
|
344
|
-
results.push(result);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
expect(new Set(results.map((result) => result.email)).size).toBe(10);
|
|
348
|
-
expect(new Set(results.map((result) => result.firstName)).size).toBe(10);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
it("reuses one plugin without changing seeded output", async () => {
|
|
352
|
-
const plugin = fakerPlugin({ schema: schemas.complex.user(), seed: 42 });
|
|
353
|
-
const context = pluginContext();
|
|
354
|
-
const responses: unknown[] = [];
|
|
355
|
-
|
|
356
|
-
for (let iteration = 0; iteration < 15; iteration += 1) {
|
|
357
|
-
const result = await plugin.process(context);
|
|
358
|
-
expectGeneratedUser(result.response);
|
|
359
|
-
responses.push(result.response);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
expect(responses).toEqual(Array.from({ length: 15 }, () => responses[0]));
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it("handles an empty object schema", async () => {
|
|
366
|
-
await expect(
|
|
367
|
-
generateFromSchema({ schema: schemas.simple.object({}), seed: 42 }),
|
|
368
|
-
).resolves.toEqual({});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("selects only declared values from a large enum", async () => {
|
|
372
|
-
const countries = Array.from(
|
|
373
|
-
{ length: 200 },
|
|
374
|
-
(_, index) => `country-${index}`,
|
|
375
|
-
);
|
|
376
|
-
const schema = schemas.simple.object({
|
|
377
|
-
country: { type: "string", enum: countries },
|
|
378
|
-
});
|
|
379
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
380
|
-
|
|
381
|
-
expectRecord(result);
|
|
382
|
-
expect(countries).toContain(result.country);
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it("generates samples matching a complex pattern", async () => {
|
|
386
|
-
const pattern = /^[A-Z]{2}-[0-9]{4}-[a-z]{2}-[0-9A-F]{8}$/;
|
|
387
|
-
const schema = schemas.simple.object({
|
|
388
|
-
code: { type: "string", pattern: pattern.source },
|
|
389
|
-
});
|
|
390
|
-
const results = await generate.samples(schema, 10, { seed: 42 });
|
|
391
|
-
|
|
392
|
-
expect(results).toHaveLength(10);
|
|
393
|
-
for (const result of results) {
|
|
394
|
-
expectRecord(result);
|
|
395
|
-
expect(result.code).toMatch(pattern);
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it("satisfies one branch of a mixed constraint schema", async () => {
|
|
400
|
-
const schema: JSONSchema7 = {
|
|
401
|
-
anyOf: [
|
|
402
|
-
{
|
|
403
|
-
type: "object",
|
|
404
|
-
properties: {
|
|
405
|
-
type: { const: "A" },
|
|
406
|
-
data: { type: "string", minLength: 100 },
|
|
407
|
-
},
|
|
408
|
-
required: ["type", "data"],
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
type: "array",
|
|
412
|
-
items: { type: "number", minimum: 0, maximum: 1_000 },
|
|
413
|
-
minItems: 50,
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
type: "string",
|
|
417
|
-
pattern: "^[A-Za-z0-9+/]{100,}={0,2}$",
|
|
418
|
-
},
|
|
419
|
-
],
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
const result = await generateFromSchema({ schema, seed: 42 });
|
|
423
|
-
const isValidObject =
|
|
424
|
-
isRecord(result) &&
|
|
425
|
-
result.type === "A" &&
|
|
426
|
-
typeof result.data === "string" &&
|
|
427
|
-
result.data.length >= 100;
|
|
428
|
-
const isValidArray =
|
|
429
|
-
Array.isArray(result) &&
|
|
430
|
-
result.length >= 50 &&
|
|
431
|
-
result.every(
|
|
432
|
-
(value) => typeof value === "number" && value >= 0 && value <= 1_000,
|
|
433
|
-
);
|
|
434
|
-
const isValidString =
|
|
435
|
-
typeof result === "string" &&
|
|
436
|
-
/^[A-Za-z0-9+/]{100,}={0,2}$/.test(result);
|
|
437
|
-
|
|
438
|
-
expect(isValidObject || isValidArray || isValidString).toBe(true);
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
});
|