-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathseed.js
49 lines (42 loc) · 988 Bytes
/
seed.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
const faker = require('faker');
const { User, db } = require('./server/db');
const numUsers = 20;
const doTimes = (n, fn) => {
const results = [];
while (n--) {
results.push(fn());
}
return results;
};
const randomFakeUser = () => {
return User.build({
username: faker.internet.userName(),
password: faker.internet.password(),
last_logout: Date.now(),
});
};
const createFakeUser = () => {
const testUser = User.build({
username: 'example',
password: '12345',
});
const arrOfUsersToBeSaved = [
testUser,
...doTimes(numUsers, () => randomFakeUser()),
].map(user => user.save());
return Promise.all(arrOfUsersToBeSaved);
};
const seed = () => createFakeUser();
db.sync({ force: true })
.then(() => {
return seed();
})
.then(() => {
console.log('----- Seeding successful! -----');
}, (err) => {
console.error('Error while seeding');
console.error(err.stack);
})
.then(() => {
process.exit();
});