-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
109 lines (102 loc) · 3.02 KB
/
test.ts
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
import { TestUtilService } from './app/core/test-util/testing.service';
import { Container } from '@gapi/core';
import { UserSettings, User } from './models/User';
import { Credential } from './models/Credential';
import { AuthService } from './app/core/services/auth/auth.service';
interface FakeUser {
username: string;
settings: UserSettings;
userType: 'ADMIN' | 'USER';
email: string;
password: string;
wallets?: Array<string>;
}
export const TEST_CONFIG = {
defaultPassword: '123456'
};
export const FAKE_USERS: FakeUser[] = [{
username: 'Kristiyan Tachev',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'ADMIN'
}, {
username: 'Admin Account',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'ADMIN'
}, {
username: 'User Account',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'USER'
}, {
username: 'Zdravko Tatarski',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'USER'
}, {
username: 'Ivan Spiridonov Admin',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'ADMIN'
}, {
username: 'Ivan Spiridonov User',
settings: {
sidebar: true,
language: 'FR'
},
email: '[email protected]',
password: TEST_CONFIG.defaultPassword,
userType: 'USER'
}];
const testUtil = Container.get(TestUtilService);
if (process.env.BEFORE_HOOK) {
testUtil.setSequelizeConfig({ force: true });
// Flush sequelize connection and force database to recreate table schema;
testUtil.initSequelize();
// Wait a little bit so Sequelize will finish building schema for example 1 sec then init fake users;
setTimeout(() => {
User.bulkCreate(FAKE_USERS, { individualHooks: true })
.then(async (users) => {
return await Promise.all(users.map(async user => {
const fakeUser = FAKE_USERS.filter(fu => fu.username === user.username)[0];
await Credential.create({
userId: user.id,
email: fakeUser.email,
password: Container.get(AuthService).encryptPassword(fakeUser.password)
});
return user;
}));
})
.then((data) => {
console.log(`Users successfully created! Count: ${data.length}`);
process.exit(0);
})
.catch((e) => {
console.error(e);
process.exit(1);
});
}, 1000);
} else {
process.exit(0);
}