qa-faker-factory 1.0.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/.github/workflows/ci.yml +24 -0
- package/LICENSE +21 -0
- package/README.md +321 -0
- package/__tests__/test-factory.test.js +196 -0
- package/index.js +181 -0
- package/package.json +18 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [18.x]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v3
|
|
19
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: ${{ matrix.node-version }}
|
|
23
|
+
- run: npm ci
|
|
24
|
+
- run: npm test
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Azu Patrick
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# qa-faker-factory
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/qa-faker-factory)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/azupatrick0/qa-faker-factory/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
A comprehensive, lightweight test data factory generating realistic fake data for Quality Assurance (QA) and testing workflows.
|
|
8
|
+
Built on [faker-js/faker](https://github.com/faker-js/faker) to produce diverse domain-specific mock data objects for rapid testing and prototyping.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Generate fake **Users**, **Addresses**, **Products**, **Orders**, **Companies**, **Vehicles**, **Bank Accounts**, and more
|
|
15
|
+
- Includes test data for specialized domains like **Medical Records**, **Travel Bookings**, **Support Tickets**, and **Subscription Plans**
|
|
16
|
+
- Customizable options (e.g., country codes for phone numbers)
|
|
17
|
+
- Lightweight and easy to integrate in Node.js projects
|
|
18
|
+
- CLI and mock JSON data generation (planned / extendable)
|
|
19
|
+
- Ideal for frontend, backend, and API testing
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install qa-faker-factory
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const {
|
|
36
|
+
generateUser,
|
|
37
|
+
generateAddress,
|
|
38
|
+
generateProduct,
|
|
39
|
+
generateOrder,
|
|
40
|
+
generateCompany,
|
|
41
|
+
generatePaymentCard,
|
|
42
|
+
generateVehicle,
|
|
43
|
+
generateBankAccount,
|
|
44
|
+
generateJobProfile,
|
|
45
|
+
generateEducationRecord,
|
|
46
|
+
generateSocialProfile,
|
|
47
|
+
generateMedicalRecord,
|
|
48
|
+
generateTravelBooking,
|
|
49
|
+
generateSupportTicket,
|
|
50
|
+
generateSubscriptionPlan,
|
|
51
|
+
generateChatMessage
|
|
52
|
+
} = require('qa-faker-factory');
|
|
53
|
+
|
|
54
|
+
// Generate a random user with default +1 country code for phone
|
|
55
|
+
const user = generateUser();
|
|
56
|
+
console.log(user);
|
|
57
|
+
|
|
58
|
+
// Generate an address with a specified country
|
|
59
|
+
const address = generateAddress({ country: 'United States' });
|
|
60
|
+
console.log(address);
|
|
61
|
+
|
|
62
|
+
// Generate an order with user's phone country code override
|
|
63
|
+
const order = generateOrder({ countryCode: '+1' });
|
|
64
|
+
console.log(order);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## API Reference
|
|
69
|
+
```js
|
|
70
|
+
generateUser(options) - Generate a random user object.
|
|
71
|
+
|
|
72
|
+
Parameters:
|
|
73
|
+
|
|
74
|
+
options (optional):
|
|
75
|
+
|
|
76
|
+
countryCode (string) - Country dialing code for phone number (default: '+1')
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
firstName: string,
|
|
82
|
+
lastName: string,
|
|
83
|
+
email: string,
|
|
84
|
+
phone: string, // formatted with countryCode
|
|
85
|
+
gender: 'Male' | 'Female' | 'Other'
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
```js
|
|
89
|
+
generateAddress(options) - Generate a random address.
|
|
90
|
+
|
|
91
|
+
Parameters:
|
|
92
|
+
|
|
93
|
+
options (optional):
|
|
94
|
+
|
|
95
|
+
country (string) - Country name (default: 'United States')
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
street: string,
|
|
101
|
+
city: string,
|
|
102
|
+
state: string,
|
|
103
|
+
postalCode: string,
|
|
104
|
+
country: string
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
generateProduct() - Generate a random product.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
|
|
113
|
+
{
|
|
114
|
+
name: string,
|
|
115
|
+
price: string, // in Currency e.g ($)
|
|
116
|
+
category: string,
|
|
117
|
+
stock: number
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
generateOrder(options) - Generate an order object including a user, product, quantity, and total price.
|
|
123
|
+
|
|
124
|
+
Parameters:
|
|
125
|
+
|
|
126
|
+
options (optional):
|
|
127
|
+
|
|
128
|
+
countryCode (string) - Passed to generateUser to generate a user based on the country
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
|
|
132
|
+
{
|
|
133
|
+
user: object,
|
|
134
|
+
product: object,
|
|
135
|
+
quantity: number,
|
|
136
|
+
total: string // total price string with currency symbol
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
```js
|
|
140
|
+
generateCompany() - Generate a random company.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
|
|
144
|
+
{
|
|
145
|
+
name: string,
|
|
146
|
+
catchPhrase: string,
|
|
147
|
+
industry: string,
|
|
148
|
+
website: string
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
```js
|
|
152
|
+
generatePaymentCard() - Generate a random payment card.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
type: string,
|
|
158
|
+
number: string,
|
|
159
|
+
cvv: string,
|
|
160
|
+
expiry: string // YYYY-MM-DD format
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
generateVehicle() - Generate a vehicle profile.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
|
|
169
|
+
{
|
|
170
|
+
make: string,
|
|
171
|
+
model: string,
|
|
172
|
+
type: string,
|
|
173
|
+
vin: string,
|
|
174
|
+
registrationNumber: string
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
```js
|
|
178
|
+
generateBankAccount() - Generate a bank account.
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
|
|
182
|
+
{
|
|
183
|
+
bankName: string,
|
|
184
|
+
accountNumber: string,
|
|
185
|
+
iban: string,
|
|
186
|
+
bic: string
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
```js
|
|
190
|
+
generateJobProfile() - Generate a job profile.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
|
|
194
|
+
{
|
|
195
|
+
title: string,
|
|
196
|
+
area: string,
|
|
197
|
+
type: string,
|
|
198
|
+
company: string
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
```js
|
|
202
|
+
generateEducationRecord() - Generate an education record.
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
|
|
206
|
+
{
|
|
207
|
+
institution: string,
|
|
208
|
+
degree: string,
|
|
209
|
+
field: string,
|
|
210
|
+
graduationYear: number
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
```js
|
|
214
|
+
generateSocialProfile() - Generate a social media profile.
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
username: string,
|
|
220
|
+
email: string,
|
|
221
|
+
avatar: string, // URL
|
|
222
|
+
url: string,
|
|
223
|
+
followers: number
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
```js
|
|
227
|
+
generateMedicalRecord() - Generate a medical record.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
|
|
231
|
+
{
|
|
232
|
+
patientId: string,
|
|
233
|
+
bloodType: string,
|
|
234
|
+
allergies: string[],
|
|
235
|
+
diagnosis: string,
|
|
236
|
+
lastVisit: string // YYYY-MM-DD format
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
```js
|
|
240
|
+
generateTravelBooking() - Generate a travel booking.
|
|
241
|
+
|
|
242
|
+
Returns:
|
|
243
|
+
|
|
244
|
+
{
|
|
245
|
+
destination: string,
|
|
246
|
+
departureDate: string, // YYYY-MM-DD
|
|
247
|
+
returnDate: string, // YYYY-MM-DD
|
|
248
|
+
airline: string,
|
|
249
|
+
bookingRef: string
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
```js
|
|
253
|
+
generateSupportTicket() - Generate a support ticket.
|
|
254
|
+
|
|
255
|
+
Returns:
|
|
256
|
+
|
|
257
|
+
{
|
|
258
|
+
ticketId: string,
|
|
259
|
+
subject: string,
|
|
260
|
+
status: 'open' | 'pending' | 'closed',
|
|
261
|
+
priority: 'low' | 'medium' | 'high',
|
|
262
|
+
createdAt: string // ISO timestamp
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
```js
|
|
266
|
+
generateSubscriptionPlan() - Generate a subscription plan.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
|
|
270
|
+
{
|
|
271
|
+
planName: string,
|
|
272
|
+
pricePerMonth: string, // e.g. "$19.99"
|
|
273
|
+
features: string[]
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
```js
|
|
277
|
+
generateChatMessage() - Generate a chat message.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
|
|
281
|
+
{
|
|
282
|
+
messageId: string,
|
|
283
|
+
sender: string,
|
|
284
|
+
message: string,
|
|
285
|
+
timestamp: string // ISO timestamp
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Contributing
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
Contributions are welcome! If you'd like to improve this project, follow these steps:
|
|
295
|
+
|
|
296
|
+
- Fork the repository
|
|
297
|
+
|
|
298
|
+
- Create a new branch
|
|
299
|
+
```js
|
|
300
|
+
(git checkout -b feature-branch)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
- Make your changes
|
|
304
|
+
|
|
305
|
+
- Commit your changes
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
(git commit -m 'Add new feature')
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
- Push to the branch (git push origin feature-branch)
|
|
312
|
+
|
|
313
|
+
- Open a Pull Request
|
|
314
|
+
|
|
315
|
+
Please make sure your code follows the existing style and includes relevant tests where applicable.
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
## License
|
|
319
|
+
|
|
320
|
+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|
|
321
|
+
You are free to use, modify, and distribute this software as permitted under the terms of the license.
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// __tests__/test-factory.test.js
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
generateUser,
|
|
5
|
+
generateAddress,
|
|
6
|
+
generateProduct,
|
|
7
|
+
generateOrder,
|
|
8
|
+
generateCompany,
|
|
9
|
+
generatePaymentCard,
|
|
10
|
+
generateVehicle,
|
|
11
|
+
generateBankAccount,
|
|
12
|
+
generateJobProfile,
|
|
13
|
+
generateEducationRecord,
|
|
14
|
+
generateSocialProfile,
|
|
15
|
+
generateMedicalRecord,
|
|
16
|
+
generateTravelBooking,
|
|
17
|
+
generateSupportTicket,
|
|
18
|
+
generateSubscriptionPlan,
|
|
19
|
+
generateChatMessage
|
|
20
|
+
} = require('../index');
|
|
21
|
+
|
|
22
|
+
describe('QA Faker Factory', () => {
|
|
23
|
+
|
|
24
|
+
test('generateUser produces expected properties', () => {
|
|
25
|
+
const user = generateUser({ countryCode: '+1' });
|
|
26
|
+
expect(user).toHaveProperty('firstName');
|
|
27
|
+
expect(user).toHaveProperty('lastName');
|
|
28
|
+
expect(user).toHaveProperty('email');
|
|
29
|
+
expect(user).toHaveProperty('phone');
|
|
30
|
+
expect(user.phone.startsWith('+1')).toBe(true);
|
|
31
|
+
expect(user).toHaveProperty('gender');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('generateAddress produces expected properties', () => {
|
|
35
|
+
const address = generateAddress({ country: 'USA' });
|
|
36
|
+
expect(address).toHaveProperty('street');
|
|
37
|
+
expect(address).toHaveProperty('city');
|
|
38
|
+
expect(address).toHaveProperty('state');
|
|
39
|
+
expect(address).toHaveProperty('postalCode');
|
|
40
|
+
expect(address.country).toBe('USA');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('generateProduct produces expected properties', () => {
|
|
44
|
+
const product = generateProduct();
|
|
45
|
+
expect(product).toHaveProperty('name');
|
|
46
|
+
expect(product).toHaveProperty('price');
|
|
47
|
+
expect(product.price).toMatch(/^₦\d+/);
|
|
48
|
+
expect(product).toHaveProperty('category');
|
|
49
|
+
expect(product).toHaveProperty('stock');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('generateOrder produces expected properties and consistent total', () => {
|
|
53
|
+
const order = generateOrder({ countryCode: '+44' });
|
|
54
|
+
expect(order).toHaveProperty('user');
|
|
55
|
+
expect(order.user.phone.startsWith('+44')).toBe(true);
|
|
56
|
+
expect(order).toHaveProperty('product');
|
|
57
|
+
expect(order).toHaveProperty('quantity');
|
|
58
|
+
expect(order.quantity).toBeGreaterThanOrEqual(1);
|
|
59
|
+
expect(order.quantity).toBeLessThanOrEqual(5);
|
|
60
|
+
expect(order).toHaveProperty('total');
|
|
61
|
+
|
|
62
|
+
// Check total calculation is correct
|
|
63
|
+
const price = parseInt(order.product.price.replace('₦', ''), 10);
|
|
64
|
+
expect(order.total).toBe(`₦${price * order.quantity}`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('generateCompany produces expected properties', () => {
|
|
68
|
+
const company = generateCompany();
|
|
69
|
+
expect(company).toHaveProperty('name');
|
|
70
|
+
expect(company).toHaveProperty('catchPhrase');
|
|
71
|
+
expect(company).toHaveProperty('industry');
|
|
72
|
+
expect(company).toHaveProperty('website');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('generatePaymentCard produces expected properties', () => {
|
|
76
|
+
const card = generatePaymentCard();
|
|
77
|
+
expect(card).toHaveProperty('type');
|
|
78
|
+
expect(card).toHaveProperty('number');
|
|
79
|
+
expect(card).toHaveProperty('cvv');
|
|
80
|
+
expect(card).toHaveProperty('expiry');
|
|
81
|
+
expect(new Date(card.expiry).getFullYear()).toBeGreaterThan(new Date().getFullYear());
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('generateVehicle produces expected properties', () => {
|
|
85
|
+
const vehicle = generateVehicle();
|
|
86
|
+
expect(vehicle).toHaveProperty('make');
|
|
87
|
+
expect(vehicle).toHaveProperty('model');
|
|
88
|
+
expect(vehicle).toHaveProperty('type');
|
|
89
|
+
expect(vehicle).toHaveProperty('vin');
|
|
90
|
+
expect(vehicle).toHaveProperty('registrationNumber');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('generateBankAccount produces expected properties', () => {
|
|
94
|
+
const account = generateBankAccount();
|
|
95
|
+
expect(account).toHaveProperty('bankName');
|
|
96
|
+
expect(account).toHaveProperty('accountNumber');
|
|
97
|
+
expect(account).toHaveProperty('iban');
|
|
98
|
+
expect(account).toHaveProperty('bic');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('generateJobProfile produces expected properties', () => {
|
|
102
|
+
const job = generateJobProfile();
|
|
103
|
+
expect(job).toHaveProperty('title');
|
|
104
|
+
expect(job).toHaveProperty('area');
|
|
105
|
+
expect(job).toHaveProperty('type');
|
|
106
|
+
expect(job).toHaveProperty('company');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('generateEducationRecord produces expected properties', () => {
|
|
110
|
+
|
|
111
|
+
const education = generateEducationRecord();
|
|
112
|
+
|
|
113
|
+
expect(education).toHaveProperty('institution');
|
|
114
|
+
expect(typeof education.institution).toBe('string');
|
|
115
|
+
|
|
116
|
+
expect(education).toHaveProperty('degree');
|
|
117
|
+
expect(['B.Sc.', 'M.Sc.', 'Ph.D.', 'Diploma']).toContain(education.degree);
|
|
118
|
+
|
|
119
|
+
expect(education).toHaveProperty('fieldOfStudy');
|
|
120
|
+
expect(typeof education.fieldOfStudy).toBe('string');
|
|
121
|
+
|
|
122
|
+
expect(education).toHaveProperty('startDate');
|
|
123
|
+
expect(education.startDate instanceof Date).toBe(true);
|
|
124
|
+
|
|
125
|
+
expect(education).toHaveProperty('endDate');
|
|
126
|
+
expect(education.endDate instanceof Date).toBe(true);
|
|
127
|
+
|
|
128
|
+
expect(education).toHaveProperty('grade');
|
|
129
|
+
expect(['First Class', 'Second Class Upper', 'Second Class Lower', 'Pass']).toContain(education.grade);
|
|
130
|
+
|
|
131
|
+
expect(education).toHaveProperty('description');
|
|
132
|
+
expect(typeof education.description).toBe('string');
|
|
133
|
+
expect(education.description.length).toBeGreaterThan(0);
|
|
134
|
+
|
|
135
|
+
expect(education.endDate.getTime()).toBeGreaterThan(education.startDate.getTime());
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('generateSocialProfile produces expected properties', () => {
|
|
139
|
+
const social = generateSocialProfile();
|
|
140
|
+
expect(social).toHaveProperty('username');
|
|
141
|
+
expect(social).toHaveProperty('email');
|
|
142
|
+
expect(social).toHaveProperty('avatar');
|
|
143
|
+
expect(social).toHaveProperty('url');
|
|
144
|
+
expect(social).toHaveProperty('followers');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('generateMedicalRecord produces expected properties', () => {
|
|
148
|
+
const medical = generateMedicalRecord();
|
|
149
|
+
expect(medical).toHaveProperty('patientId');
|
|
150
|
+
expect(medical).toHaveProperty('bloodType');
|
|
151
|
+
expect(['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-']).toContain(medical.bloodType);
|
|
152
|
+
expect(medical).toHaveProperty('allergies');
|
|
153
|
+
expect(Array.isArray(medical.allergies)).toBe(true);
|
|
154
|
+
expect(medical).toHaveProperty('diagnosis');
|
|
155
|
+
expect(medical).toHaveProperty('lastVisit');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('generateTravelBooking produces expected properties', () => {
|
|
159
|
+
const booking = generateTravelBooking();
|
|
160
|
+
expect(booking).toHaveProperty('destination');
|
|
161
|
+
expect(booking).toHaveProperty('departureDate');
|
|
162
|
+
expect(booking).toHaveProperty('returnDate');
|
|
163
|
+
expect(booking).toHaveProperty('airline');
|
|
164
|
+
expect(booking).toHaveProperty('bookingRef');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('generateSupportTicket produces expected properties', () => {
|
|
168
|
+
const ticket = generateSupportTicket();
|
|
169
|
+
expect(ticket).toHaveProperty('ticketId');
|
|
170
|
+
expect(ticket).toHaveProperty('subject');
|
|
171
|
+
expect(ticket).toHaveProperty('status');
|
|
172
|
+
expect(['open', 'pending', 'closed']).toContain(ticket.status);
|
|
173
|
+
expect(ticket).toHaveProperty('priority');
|
|
174
|
+
expect(['low', 'medium', 'high']).toContain(ticket.priority);
|
|
175
|
+
expect(ticket).toHaveProperty('createdAt');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('generateSubscriptionPlan produces expected properties', () => {
|
|
179
|
+
const plan = generateSubscriptionPlan();
|
|
180
|
+
expect(plan).toHaveProperty('planName');
|
|
181
|
+
expect(plan.planName).toMatch(/Plan$/);
|
|
182
|
+
expect(plan).toHaveProperty('pricePerMonth');
|
|
183
|
+
expect(plan.pricePerMonth).toMatch(/^\$\d+/);
|
|
184
|
+
expect(plan).toHaveProperty('features');
|
|
185
|
+
expect(Array.isArray(plan.features)).toBe(true);
|
|
186
|
+
expect(plan.features.length).toBeGreaterThan(0);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('generateChatMessage produces expected properties', () => {
|
|
190
|
+
const msg = generateChatMessage();
|
|
191
|
+
expect(msg).toHaveProperty('messageId');
|
|
192
|
+
expect(msg).toHaveProperty('sender');
|
|
193
|
+
expect(msg).toHaveProperty('message');
|
|
194
|
+
expect(msg).toHaveProperty('timestamp');
|
|
195
|
+
});
|
|
196
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// qa-faker-factory/index.js
|
|
2
|
+
const { faker } = require('@faker-js/faker');
|
|
3
|
+
|
|
4
|
+
function generateUser(options = {}) {
|
|
5
|
+
const countryCode = options.countryCode || '+1';
|
|
6
|
+
return {
|
|
7
|
+
firstName: faker.person.firstName(),
|
|
8
|
+
lastName: faker.person.lastName(),
|
|
9
|
+
email: faker.internet.email(),
|
|
10
|
+
phone: `${countryCode} ${faker.string.numeric(10)}`,
|
|
11
|
+
gender: faker.helpers.arrayElement(['Male', 'Female', 'Other'])
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function generateAddress(options = {}) {
|
|
16
|
+
const country = options.country || faker.location.country();
|
|
17
|
+
return {
|
|
18
|
+
street: faker.location.streetAddress(),
|
|
19
|
+
city: faker.location.city(),
|
|
20
|
+
state: faker.location.state(),
|
|
21
|
+
postalCode: faker.location.zipCode(),
|
|
22
|
+
country
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function generateProduct() {
|
|
27
|
+
return {
|
|
28
|
+
name: faker.commerce.productName(),
|
|
29
|
+
price: `₦${faker.commerce.price({ min: 1000, max: 20000, dec: 0 })}`,
|
|
30
|
+
category: faker.commerce.department(),
|
|
31
|
+
stock: faker.number.int({ min: 0, max: 500 })
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function generateOrder(options = {}) {
|
|
36
|
+
const user = generateUser(options);
|
|
37
|
+
const product = generateProduct();
|
|
38
|
+
const quantity = faker.number.int({ min: 1, max: 5 });
|
|
39
|
+
return {
|
|
40
|
+
user,
|
|
41
|
+
product,
|
|
42
|
+
quantity,
|
|
43
|
+
total: `₦${parseInt(product.price.replace('₦', '')) * quantity}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function generateCompany() {
|
|
48
|
+
return {
|
|
49
|
+
name: faker.company.name(),
|
|
50
|
+
catchPhrase: faker.company.catchPhrase(),
|
|
51
|
+
industry: faker.company.buzzNoun(),
|
|
52
|
+
website: faker.internet.url()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function generatePaymentCard() {
|
|
57
|
+
return {
|
|
58
|
+
type: faker.finance.creditCardIssuer(),
|
|
59
|
+
number: faker.finance.creditCardNumber(),
|
|
60
|
+
cvv: faker.finance.creditCardCVV(),
|
|
61
|
+
expiry: faker.date.future({ years: 3 }).toISOString().split('T')[0]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function generateVehicle() {
|
|
66
|
+
return {
|
|
67
|
+
make: faker.vehicle.manufacturer(),
|
|
68
|
+
model: faker.vehicle.model(),
|
|
69
|
+
type: faker.vehicle.type(),
|
|
70
|
+
vin: faker.vehicle.vin(),
|
|
71
|
+
registrationNumber: faker.string.alphanumeric(8).toUpperCase()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function generateBankAccount() {
|
|
76
|
+
return {
|
|
77
|
+
bankName: faker.finance.accountName(),
|
|
78
|
+
accountNumber: faker.finance.accountNumber(),
|
|
79
|
+
iban: faker.finance.iban(),
|
|
80
|
+
bic: faker.finance.bic()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function generateJobProfile() {
|
|
85
|
+
return {
|
|
86
|
+
title: faker.person.jobTitle(),
|
|
87
|
+
area: faker.person.jobArea(),
|
|
88
|
+
type: faker.person.jobType(),
|
|
89
|
+
company: faker.company.name()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function generateEducationRecord() {
|
|
94
|
+
return {
|
|
95
|
+
institution: faker.company.name(),
|
|
96
|
+
degree: faker.helpers.arrayElement(['B.Sc.', 'M.Sc.', 'Ph.D.', 'Diploma']),
|
|
97
|
+
fieldOfStudy: faker.person.jobArea(),
|
|
98
|
+
startDate: faker.date.past({ years: 10 }),
|
|
99
|
+
endDate: faker.date.recent(),
|
|
100
|
+
grade: faker.helpers.arrayElement(['First Class', 'Second Class Upper', 'Second Class Lower', 'Pass']),
|
|
101
|
+
description: faker.lorem.sentences(2)
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function generateSocialProfile() {
|
|
106
|
+
return {
|
|
107
|
+
username: faker.internet.userName(),
|
|
108
|
+
email: faker.internet.email(),
|
|
109
|
+
avatar: faker.image.avatar(),
|
|
110
|
+
url: faker.internet.url(),
|
|
111
|
+
followers: faker.number.int({ min: 0, max: 100000 })
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function generateMedicalRecord() {
|
|
116
|
+
return {
|
|
117
|
+
patientId: faker.string.uuid(),
|
|
118
|
+
bloodType: faker.helpers.arrayElement(['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-']),
|
|
119
|
+
allergies: faker.helpers.arrayElements(['Penicillin', 'Peanuts', 'Latex', 'Bee stings', 'Dust'], 2),
|
|
120
|
+
diagnosis: faker.lorem.words(3),
|
|
121
|
+
lastVisit: faker.date.past().toISOString().split('T')[0]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function generateTravelBooking() {
|
|
126
|
+
return {
|
|
127
|
+
destination: faker.location.city(),
|
|
128
|
+
departureDate: faker.date.future().toISOString().split('T')[0],
|
|
129
|
+
returnDate: faker.date.future({ years: 1 }).toISOString().split('T')[0],
|
|
130
|
+
airline: faker.company.name(),
|
|
131
|
+
bookingRef: faker.string.alphanumeric(6).toUpperCase()
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function generateSupportTicket() {
|
|
136
|
+
return {
|
|
137
|
+
ticketId: faker.string.uuid(),
|
|
138
|
+
subject: faker.lorem.sentence(),
|
|
139
|
+
status: faker.helpers.arrayElement(['open', 'pending', 'closed']),
|
|
140
|
+
priority: faker.helpers.arrayElement(['low', 'medium', 'high']),
|
|
141
|
+
createdAt: faker.date.past().toISOString()
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function generateSubscriptionPlan() {
|
|
146
|
+
return {
|
|
147
|
+
planName: faker.commerce.productAdjective() + ' Plan',
|
|
148
|
+
pricePerMonth: `$${faker.commerce.price({ min: 5, max: 100, dec: 2 })}`,
|
|
149
|
+
features: faker.helpers.arrayElements([
|
|
150
|
+
'Unlimited access', 'Priority support', 'Custom reports', 'Team management', 'API access'
|
|
151
|
+
], 3)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function generateChatMessage() {
|
|
156
|
+
return {
|
|
157
|
+
messageId: faker.string.uuid(),
|
|
158
|
+
sender: faker.internet.userName(),
|
|
159
|
+
message: faker.lorem.sentences(2),
|
|
160
|
+
timestamp: faker.date.recent().toISOString()
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports = {
|
|
165
|
+
generateUser,
|
|
166
|
+
generateAddress,
|
|
167
|
+
generateProduct,
|
|
168
|
+
generateOrder,
|
|
169
|
+
generateCompany,
|
|
170
|
+
generatePaymentCard,
|
|
171
|
+
generateVehicle,
|
|
172
|
+
generateBankAccount,
|
|
173
|
+
generateJobProfile,
|
|
174
|
+
generateEducationRecord,
|
|
175
|
+
generateSocialProfile,
|
|
176
|
+
generateMedicalRecord,
|
|
177
|
+
generateTravelBooking,
|
|
178
|
+
generateSupportTicket,
|
|
179
|
+
generateSubscriptionPlan,
|
|
180
|
+
generateChatMessage
|
|
181
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qa-faker-factory",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight test data factory for QA Engineers and Software Engineers based on @faker-js/faker",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"keywords": ["faker", "qa", "test-data", "mock", "factory", "automation"],
|
|
10
|
+
"author": "Patrick Azu <azupatrick0@gmail.com>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@faker-js/faker": "^8.4.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"jest": "^29.7.0"
|
|
17
|
+
}
|
|
18
|
+
}
|