Skip to content

Commit 93f1b74

Browse files
authored
feat: use egg-orm latest version (#124)
1 parent 081dcf5 commit 93f1b74

File tree

18 files changed

+53
-127
lines changed

18 files changed

+53
-127
lines changed

todomvc/.autod.conf.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

todomvc/.eslintrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"extends": "eslint-config-egg"
2+
"root": true,
3+
"extends": "eslint-config-egg",
4+
"parserOptions": {
5+
"ecmaVersion": 2022
6+
}
37
}

todomvc/.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

todomvc/app.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const initDatabase = require('./config/database/init');
42

53
class AppBootHook {

todomvc/app/controller/home.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { Controller } = require('egg');
42

53
class HomeController extends Controller {

todomvc/app/controller/todo.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { Controller } = require('egg');
42

53
class TodoController extends Controller {

todomvc/app/middleware/response_time.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = options => {
42
return async function responseTime(ctx, next) {
53
const start = Date.now();

todomvc/app/model/todo.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
'use strict';
1+
module.exports = app => {
2+
const { Bone, DataTypes: { DATE, STRING, BOOLEAN } } = app.model;
23

3-
module.exports = (app, Model) => {
4-
const { INTEGER, DATE, STRING, BOOLEAN } = Model.DataTypes;
5-
6-
class Todo extends Model {}
7-
8-
Todo.init({
9-
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
10-
title: STRING(1000),
11-
createdAt: DATE,
12-
updatedAt: DATE,
13-
deletedAt: DATE,
14-
completed: BOOLEAN,
15-
});
4+
class Todo extends Bone {
5+
static table = 'todos';
6+
static attributes = {
7+
title: STRING(1000),
8+
createdAt: DATE,
9+
updatedAt: DATE,
10+
deletedAt: DATE,
11+
completed: BOOLEAN,
12+
};
13+
}
1614

1715
return Todo;
1816
};

todomvc/app/router.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
/**
42
* @param {Egg.Application} app - egg application
53
*/

todomvc/app/service/todo.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
const { Service } = require('egg');
42

53
/**

todomvc/app/view/home.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</div>
4040
{% endraw %}
4141
</body>
42-
<script src="//cdn.jsdelivr.net/npm/vue"></script>
42+
<script src="//cdn.jsdelivr.net/npm/vue@2"></script>
4343
<script src="//cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
4444
<script src="//cdn.jsdelivr.net/npm/js-cookie/src/js.cookie.min.js"></script>
4545
<script src="/public/main.js"></script>

todomvc/appveyor.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

todomvc/config/config.default.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint valid-jsdoc: "off" */
22

3-
'use strict';
4-
53
const path = require('path');
64

75
/**

todomvc/config/config.unittest.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint valid-jsdoc: "off" */
22

3-
'use strict';
4-
53
const path = require('path');
64

75
module.exports = () => {

todomvc/config/database/init.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
// init database here
42
module.exports = async app => {
53
// sync database defines
@@ -8,9 +6,11 @@ module.exports = async app => {
86
if (app.config.env === 'unittest') {
97
await app.model.Todo.remove({}, true);
108
await app.model.Todo.bulkCreate([
11-
{ id: 1, title: 'Read history of Node.js', completed: true },
12-
{ id: 2, title: 'Learn Koa', completed: true },
13-
{ id: 3, title: 'Star Egg', completed: false },
9+
{ title: 'Read history of Node.js', completed: true },
10+
{ title: 'Learn Koa', completed: true },
11+
{ title: 'Star Egg', completed: false },
1412
]);
13+
const rows = await app.model.Todo.findAll();
14+
console.log(rows);
1515
}
1616
};

todomvc/config/plugin.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
/** @type Egg.EggPlugin */
42
module.exports = {
53
nunjucks: {

todomvc/package.json

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@
77
"declarations": true
88
},
99
"dependencies": {
10-
"egg": "^2.15.1",
11-
"egg-orm": "^1.0.0",
12-
"egg-scripts": "^2.11.0",
10+
"egg": "^3.11.0",
11+
"egg-orm": "^2.3.0",
12+
"egg-scripts": "^2.17.0",
1313
"egg-validate": "^2.0.2",
14-
"egg-view-nunjucks": "^2.2.0",
15-
"sqlite3": "^4.1.1"
14+
"egg-view-nunjucks": "^2.3.0",
15+
"sqlite3": "^5.1.4"
1616
},
1717
"devDependencies": {
18-
"autod": "^3.0.1",
19-
"autod-egg": "^1.1.0",
20-
"egg-bin": "^4.11.0",
21-
"egg-ci": "^1.11.0",
22-
"egg-mock": "^3.21.0",
23-
"eslint": "^5.13.0",
24-
"eslint-config-egg": "^7.1.0"
18+
"egg-bin": "^5.9.0",
19+
"egg-mock": "^5.5.0",
20+
"eslint": "^8.31.0",
21+
"eslint-config-egg": "^12.1.0"
2522
},
2623
"engines": {
27-
"node": ">=10.0.0"
24+
"node": ">=16.0.0"
2825
},
2926
"scripts": {
3027
"start": "egg-scripts start --daemon --title=egg-server-todomvc",
@@ -35,16 +32,12 @@
3532
"test-local": "DEBUG=leoric egg-bin test",
3633
"cov": "DEBUG=leoric egg-bin cov",
3734
"lint": "eslint .",
38-
"ci": "npm run lint && npm run cov",
39-
"autod": "autod"
35+
"ci": "npm run lint && npm run cov"
4036
},
4137
"repository": {
4238
"type": "git",
4339
"url": ""
4440
},
45-
"ci": {
46-
"version": "10, 12"
47-
},
4841
"author": "TZ <[email protected]>",
4942
"license": "MIT"
5043
}

todomvc/test/app/controller/home.test.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
'use strict';
2-
3-
const { app, assert } = require('egg-mock/bootstrap');
1+
const { app, assert, mock } = require('egg-mock/bootstrap');
42

53
describe('test/app/controller/home.test.js', () => {
64
beforeEach(() => {
75
app.mockCsrf();
86
});
7+
afterEach(mock.restore);
98

109
it('should GET /', () => {
1110
return app.httpRequest()
@@ -69,9 +68,13 @@ describe('test/app/controller/home.test.js', () => {
6968
});
7069

7170
it('should update todo', async () => {
71+
const res = await app.httpRequest()
72+
.get('/api/todo');
73+
const row = res.body[0];
74+
7275
await app.httpRequest()
73-
.put('/api/todo/1')
74-
.send({ id: '1', title: 'Modify Node.js' })
76+
.put(`/api/todo/${row.id}`)
77+
.send({ id: row.id, title: 'Modify Node.js' })
7578
.expect('X-Response-Time', /\d+ms/)
7679
.expect(204);
7780

@@ -86,7 +89,7 @@ describe('test/app/controller/home.test.js', () => {
8689

8790
it('should update todo fail', () => {
8891
return app.httpRequest()
89-
.put('/api/todo/999')
92+
.put('/api/todo/999999999999')
9093
.set('Accept', 'application/json')
9194
.send({ id: '1', title: undefined })
9295
.expect(422)
@@ -103,18 +106,22 @@ describe('test/app/controller/home.test.js', () => {
103106

104107
it('should update todo fail with not found', () => {
105108
return app.httpRequest()
106-
.put('/api/todo/999')
109+
.put('/api/todo/999999999999')
107110
.set('Accept', 'application/json')
108-
.send({ id: '999', title: 'Modify Node.js' })
111+
.send({ id: '999999999999', title: 'Modify Node.js' })
109112
.expect(500)
110113
.then(res => {
111-
assert(res.body.message === 'task#999 not found');
114+
assert(res.body.message === 'task#999999999999 not found');
112115
});
113116
});
114117

115118
it('should delete todo', async () => {
119+
const res = await app.httpRequest()
120+
.get('/api/todo');
121+
const row = res.body[0];
122+
116123
await app.httpRequest()
117-
.delete('/api/todo/1')
124+
.delete(`/api/todo/${row.id}`)
118125
.expect(204);
119126

120127
// validate
@@ -129,11 +136,11 @@ describe('test/app/controller/home.test.js', () => {
129136

130137
it('should delete todo fail', () => {
131138
return app.httpRequest()
132-
.delete('/api/todo/999')
139+
.delete('/api/todo/999999999999')
133140
.set('Accept', 'application/json')
134141
.expect(500)
135142
.then(res => {
136-
assert(res.body.message === 'task#999 not found');
143+
assert(res.body.message === 'task#999999999999 not found');
137144
});
138145
});
139146
});

0 commit comments

Comments
 (0)