Skip to content

Commit e2e25df

Browse files
committed
chore: use faker for mock data
1 parent e69208f commit e2e25df

File tree

3 files changed

+90
-71
lines changed

3 files changed

+90
-71
lines changed

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"devDependencies": {
5050
"@eslint/js": "^9.21.0",
51+
"@faker-js/faker": "^9.6.0",
5152
"@hey-api/openapi-ts": "^0.64.10",
5253
"@mswjs/data": "^0.16.2",
5354
"@testing-library/jest-dom": "^6.6.3",

src/mocks/db.ts

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { factory, nullable, oneOf, primaryKey } from "@mswjs/data"
2+
import { faker } from '@faker-js/faker'
3+
4+
// Seed `faker` to ensure reproducible random values of model properties.
5+
faker.seed(21_000_000)
26

37
export const db = factory({
48
info: {
@@ -9,22 +13,23 @@ export const db = factory({
913
},
1014
quotes: {
1115
id: primaryKey(String),
12-
bill: {
13-
id: nullable(String),
14-
drawee: nullable(oneOf('identity_public_data')),
15-
drawer: nullable(oneOf('identity_public_data')),
16-
holder: nullable(oneOf('identity_public_data')),
17-
payee: nullable(oneOf('identity_public_data')),
18-
sum: Number,
19-
maturity_date: String,
20-
},
16+
bill: oneOf('bill'),
2117
status: nullable(String),
2218
submitted: nullable(String), // pending
2319
suggested_expiration: nullable(String), // pending
2420
ttl: nullable(String), // offered
2521
signatures: Array<string>, // accepted
2622
tstamp: nullable(String), // rejected
2723
},
24+
bill: {
25+
id: primaryKey(String),
26+
drawee: nullable(oneOf('identity_public_data')),
27+
drawer: nullable(oneOf('identity_public_data')),
28+
holder: nullable(oneOf('identity_public_data')),
29+
payee: nullable(oneOf('identity_public_data')),
30+
sum: Number,
31+
maturity_date: String,
32+
},
2833
identity_public_data: {
2934
node_id: primaryKey(String),
3035
name: String,
@@ -36,92 +41,87 @@ export const db = factory({
3641
country: String,
3742
zip: nullable(String),
3843
},
44+
})
3945

46+
db.info.create({
47+
id: "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
48+
name: "Bob's Wildcat mint",
49+
pubkey: "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
50+
version: "Nutshell/0.15.0",
4051
})
4152

4253
const ALICE = db.identity_public_data.create({
4354
node_id: "02544d32dee119cd518cec548abeb2e8c3bcc8bd2dd5b9f1200794746d2cf8d8da",
4455
name: "Alice",
56+
email: faker.internet.exampleEmail({ firstName: "Alice" }),
4557
type: "Person",
46-
address: "Street 1",
47-
city: "London",
48-
country: "UK",
58+
address: faker.location.streetAddress(),
59+
city: faker.location.city(),
60+
country: faker.location.country(),
61+
zip: faker.location.zipCode()
4962
})
5063

5164
const BOB = db.identity_public_data.create({
5265
node_id: "03ebc85dd13b60a850a3274b367acd25a8c12e7c348428a1981212a5d556a746de",
5366
name: "Bob",
67+
email: faker.internet.exampleEmail({ firstName: "Bob" }),
5468
type: "Person",
55-
address: "Street 2",
56-
city: "London",
57-
country: "UK",
69+
address: faker.location.streetAddress(),
70+
city: faker.location.city(),
71+
country: faker.location.country(),
72+
zip: faker.location.zipCode()
5873
})
5974

6075
const CHARLIE = db.identity_public_data.create({
6176
node_id: "035547a7c0c8638b2fe708eefa3fe6b51612d926ac209e009f49da37b25d558a36",
62-
name: "Charlie",
63-
type: "Person",
64-
address: "Street 3",
65-
city: "London",
66-
country: "UK",
67-
})
68-
69-
db.info.create({
70-
id: "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
71-
name: "Bob's Wildcat mint",
72-
pubkey: "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
73-
version: "Nutshell/0.15.0",
74-
})
75-
76-
db.quotes.create({
77-
id: "63777d15-ce53-4cca-94bf-7726c7930aab",
78-
status: "pending",
79-
bill: {
80-
id: "5bd3f9b8-85bd-488e-a7ca-2b35bd343e7c",
81-
sum: 42,
82-
maturity_date: "2025-01-01",
83-
drawee: ALICE,
84-
drawer: BOB,
85-
payee: ALICE,
86-
holder: CHARLIE
87-
},
88-
})
89-
90-
db.quotes.create({
91-
id: "cd3fc93c-4507-4154-b51b-215b6f360a53",
92-
status: "pending",
77+
name: `Charlie's ${faker.company.name()}`,
78+
email: faker.internet.exampleEmail({ firstName: "Charlie" }),
79+
type: "Company",
80+
address: faker.location.streetAddress(),
81+
city: faker.location.city(),
82+
country: faker.location.country(),
83+
zip: faker.location.zipCode()
9384
})
9485

95-
db.quotes.create({
96-
id: "d20ab61f-03c5-479f-930b-b6aca608b1e6",
97-
status: "pending",
98-
})
86+
const AMOUNT_OF_BILLS = 12
87+
const BILLS = Array.from(Array(AMOUNT_OF_BILLS).keys()).map(() => db.bill.create({
88+
id: faker.string.uuid(),
89+
sum: faker.number.int({ min: 21, max: 21 * 1_000}),
90+
maturity_date: faker.date.future({ years: 1 }).toUTCString(),
91+
drawee: ALICE,
92+
drawer: BOB,
93+
payee: ALICE,
94+
holder: CHARLIE
95+
}))
9996

100-
db.quotes.create({
101-
id: "57330ad9-30b1-45a7-b900-a37be37005d3",
102-
status: "offered",
97+
BILLS.slice(0, 3).forEach((bill) => {
98+
db.quotes.create({
99+
id: faker.string.uuid(),
100+
status: "pending",
101+
bill,
102+
})
103103
})
104104

105-
db.quotes.create({
106-
id: "62ea00be-66f2-4b04-b2c4-257d7409ce9f",
107-
status: "offered",
105+
BILLS.slice(3, 6).forEach((bill) => {
106+
db.quotes.create({
107+
id: faker.string.uuid(),
108+
status: "offered",
109+
bill,
110+
})
108111
})
109112

110-
db.quotes.create({
111-
id: "825e4fa8-dab3-4072-bb76-d58a975154af",
112-
status: "accepted",
113+
BILLS.slice(6, 9).forEach((bill) => {
114+
db.quotes.create({
115+
id: faker.string.uuid(),
116+
status: "accepted",
117+
bill,
118+
})
113119
})
114120

115-
db.quotes.create({
116-
id: "0e96e7cc-4327-41c6-87bf-8096fd880117",
117-
status: "accepted",
118-
})
119-
120-
db.quotes.create({
121-
id: "38b835a4-dc5d-4433-8592-81c49c94d505",
122-
status: "rejected",
123-
})
124-
db.quotes.create({
125-
id: "2f5bc589-9bca-4899-adbf-76c881a4e418",
126-
status: "rejected",
121+
BILLS.slice(9, 12).forEach((bill) => {
122+
db.quotes.create({
123+
id: faker.string.uuid(),
124+
status: "rejected",
125+
bill,
126+
})
127127
})

0 commit comments

Comments
 (0)