This repository was archived by the owner on Mar 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-mock-users.js
99 lines (80 loc) · 1.9 KB
/
create-mock-users.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
/**
* ! NOTE - Requires the skills in /data/skills.json to exist
* ! first in the database
*
* * Creates 2 files
* * 1-create-users.csv => Upload this first. This will create the users
* * 2-users-with-skills.csv => Upload this next. This will create 10 skills per previously created user
*/
const fs = require('fs')
const faker = require('faker')
const { parseAsync } = require('json2csv')
const skills = require('./data/skills.json')
const baseUser = {
// handle
// firstName
// lastName
// email
countryName: 'India',
providerType: 'Foo Digital',
provider: 'Foo Technologies',
// userId
}
const skillUser = {
// handle
skillProviderName: 'EMSI',
// skillName: ''
}
const buFields = [
'handle',
'firstName',
'lastName',
'email',
'countryName',
'providerType',
'provider',
'userId'
]
const suFields = [
'handle',
'skillProviderName',
'skillName'
]
let userCount = 100 // Number of users
let BU = []
let SU = []
while (userCount > 0) {
userCount--
const handle = faker.internet.userName()
const b = {
handle,
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: faker.internet.exampleEmail(),
userId: faker.random.alphaNumeric(8)
}
BU.push(Object.assign(b, baseUser))
let skillCount = 10 // number of skills per user
while (skillCount > 0) {
skillCount--
const s = {
handle,
skillName: faker.random.arrayElement(skills)
}
SU.push(Object.assign(s, skillUser))
}
}
(async function start() {
try {
const opts1 = { fields: buFields }
const csv1 = await parseAsync(BU, opts1)
fs.writeFileSync('1-create-users.csv', csv1)
const opts2 = { fields: suFields }
const csv2 = await parseAsync(SU, opts2)
fs.writeFileSync('2-users-with-skills.csv', csv2)
} catch (error) {
console.log('Error generating base users')
console.error(error)
throw error
}
})()