Skip to content

Commit 922b926

Browse files
author
pedro
authored
Merge pull request #25 from TaleLin/dev
fix:修改用户脚本,修复fake数据问题
2 parents 46adc7c + f231e90 commit 922b926

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/helper/fake.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ require('./initial');
22
const { db } = require('lin-mizar/lin/db');
33
// eslint-disable-next-line no-unused-vars
44
const { User, Group, Auth } = require('lin-mizar/lin');
5+
const { initModels } = require('./init_models');
56

7+
/**
8+
* 如果创建失败,请确保你的数据库中没有同名的分组和同名的用户
9+
*/
610
const run = async () => {
11+
await initModels();
12+
713
const group = new Group();
814

915
group.name = '普通分组';

tests/helper/init_models.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { db } = require('lin-mizar/lin/db');
2+
// eslint-disable-next-line no-unused-vars
3+
const { User, Group, Auth } = require('lin-mizar/lin');
4+
const {
5+
UserInterface,
6+
GroupInterface,
7+
AuthInterface
8+
} = require('lin-mizar/lin/interface');
9+
const lodash = require('lodash');
10+
11+
const initModels = async () => {
12+
User.init(
13+
Object.assign({}, UserInterface.attributes),
14+
lodash.merge(
15+
{
16+
sequelize: db,
17+
tableName: 'lin_user',
18+
modelName: 'user'
19+
},
20+
UserInterface.options
21+
)
22+
);
23+
24+
Group.init(
25+
Object.assign({}, GroupInterface.attributes),
26+
lodash.merge(
27+
{
28+
sequelize: db,
29+
tableName: 'lin_group',
30+
modelName: 'group'
31+
},
32+
GroupInterface.options
33+
)
34+
);
35+
36+
Auth.init(
37+
Object.assign({}, AuthInterface.attributes),
38+
lodash.merge(
39+
{
40+
sequelize: db,
41+
tableName: 'lin_auth',
42+
modelName: 'auth'
43+
},
44+
AuthInterface.options
45+
)
46+
);
47+
};
48+
49+
module.exports = { initModels };

0 commit comments

Comments
 (0)