-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
110 lines (107 loc) · 1.98 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const mongoose = require('mongoose');
const { Decimal128 } = mongoose;
const { generateMock } = require('./index');
// Example usage
const addressSchema = new mongoose.Schema({
street: String,
city: String,
zipCode: {
type: String,
required: true,
},
});
const fiel931Schema = new mongoose.Schema({
field9311: {
type: String,
enum: ['Hey', 'there'],
},
field9312: {
type: Number,
min: 10,
max: 12,
required: true,
},
field9313: {
type: String,
minLength: 5,
maxLength: 15,
},
});
const field9Schema = new mongoose.Schema({
field91: {
type: Number,
enum: [42, 69, 420],
},
field92: {
type: Number,
min: 1000,
max: 1050,
},
field93: {
field931: {
type: fiel931Schema,
required: true,
},
},
field94: {
type: String,
minLength: 50,
maxLength: 500,
},
});
const userSchema = new mongoose.Schema({
email: { type: String, required: true },
phoneNumber: String,
firstName: { type: String, required: true },
lastName: {
type: String,
minLength: 5,
maxLength: 200,
},
age: {
type: Number,
min: [10, 'Become an adult bruh'],
max: 100,
},
birthDate: Date,
isActive: Boolean,
address: {
type: addressSchema,
required: true,
},
hobbies: {
type: [
{
name: {
type: String,
required: true,
},
years: {
type: Number,
enum: [1995, 2000, 2010, 2020, 2025],
},
},
],
required: true,
},
salary: Decimal128,
accountBalance: Decimal128,
field1: {
field2: {
field4: Date,
field6: {
field7: {
type: String,
enum: ['either this', 'or that'],
},
field9: {
type: field9Schema,
required: true,
},
},
},
field3: Number,
},
});
const mockUserAllFields = generateMock(userSchema, { requiredOnly: false });
console.log(JSON.stringify(mockUserAllFields, null, 2));