typespeed 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/nodemon.json +1 -1
- package/app/package.json +1 -1
- package/app/src/config-development.json +7 -0
- package/app/src/jwt-authentication.class.ts +3 -2
- package/app/src/main.ts +1 -1
- package/app/src/test-database.class.ts +1 -1
- package/app/src/test-log.class.ts +5 -3
- package/app/src/test-mq.class.ts +2 -6
- package/app/src/test-orm.class.ts +8 -8
- package/app/src/test-request.class.ts +4 -4
- package/app/src/user-model.class.ts +12 -11
- package/dist/database.decorator.js +1 -1
- package/dist/default/express-server.class.js +2 -4
- package/dist/factory/log-factory.class.js +0 -3
- package/package.json +1 -1
- package/src/database.decorator.ts +1 -1
- package/src/default/express-server.class.ts +2 -4
- package/src/factory/log-factory.class.ts +0 -3
- package/src/factory/server-factory.class.ts +1 -1
- package/test/database.test.ts +61 -0
- package/test/first-page.test.ts +30 -34
- package/test/hooks.ts +10 -0
- package/test/mq.test.ts +34 -0
- package/test/orm.test.ts +65 -0
- package/test/request.test.ts +50 -0
- package/test/second-page.test.ts +51 -0
package/app/nodemon.json
CHANGED
package/app/package.json
CHANGED
|
@@ -11,7 +11,7 @@ const jwtConfig: {
|
|
|
11
11
|
|
|
12
12
|
export default class JwtAuthentication extends AuthenticationFactory {
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
@bean
|
|
15
15
|
public getJwtAuthentication(): AuthenticationFactory {
|
|
16
16
|
return new JwtAuthentication();
|
|
17
17
|
}
|
|
@@ -21,8 +21,9 @@ export default class JwtAuthentication extends AuthenticationFactory {
|
|
|
21
21
|
const jwtMiddleware = expressjwt(jwtConfig);
|
|
22
22
|
jwtMiddleware(req, res, (err) => {
|
|
23
23
|
if (err) {
|
|
24
|
-
next(err);
|
|
24
|
+
//next(err);
|
|
25
25
|
}
|
|
26
|
+
next();
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
}
|
package/app/src/main.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default class TestDatabase {
|
|
|
18
18
|
@getMapping("/db/insert2")
|
|
19
19
|
async insertByObject(req, res) {
|
|
20
20
|
const newId = await this.addRowByObject({
|
|
21
|
-
"id":
|
|
21
|
+
"id": Math.ceil(Math.random() * 1000), "name": "new name 25"
|
|
22
22
|
});
|
|
23
23
|
log("Insert newId: " + newId);
|
|
24
24
|
res.send("Insert success");
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { component } from "../../";
|
|
1
|
+
import { component, getMapping, error } from "../../";
|
|
2
2
|
|
|
3
3
|
@component
|
|
4
4
|
export default class TestLog {
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
@getMapping("/test/error")
|
|
7
|
+
testError() {
|
|
8
|
+
//error("This is a error log");
|
|
9
|
+
return "This is a error log";
|
|
8
10
|
}
|
|
9
11
|
}
|
package/app/src/test-mq.class.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default class TestMq {
|
|
|
8
8
|
@autoware
|
|
9
9
|
private rabbitMQ: RabbitMQ;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
@rabbitListener("myqueues")
|
|
12
12
|
public async listen(message) {
|
|
13
13
|
log(" Received by Decorator '%s'", message.content.toString());
|
|
14
14
|
}
|
|
@@ -31,9 +31,8 @@ export default class TestMq {
|
|
|
31
31
|
password: 'guest'
|
|
32
32
|
});
|
|
33
33
|
const channel = await connection.createChannel();
|
|
34
|
-
await channel.
|
|
34
|
+
await channel.assertQueue(queue);
|
|
35
35
|
channel.sendToQueue(queue, Buffer.from(text));
|
|
36
|
-
console.log(" [x] Sent by queue '%s'", text);
|
|
37
36
|
await channel.close();
|
|
38
37
|
return "sent by queue";
|
|
39
38
|
}
|
|
@@ -46,7 +45,6 @@ export default class TestMq {
|
|
|
46
45
|
const channel = await connection.createChannel();
|
|
47
46
|
await channel.checkExchange(exchange);
|
|
48
47
|
channel.publish(exchange, '', Buffer.from(text));
|
|
49
|
-
console.log(" [x] Publish by exchange '%s'", text);
|
|
50
48
|
await channel.close();
|
|
51
49
|
return "sent by exchange";
|
|
52
50
|
}
|
|
@@ -60,10 +58,8 @@ export default class TestMq {
|
|
|
60
58
|
await channel.checkQueue(queue);
|
|
61
59
|
await channel.checkQueue(queue2);
|
|
62
60
|
await channel.consume(queue, (message) => {
|
|
63
|
-
console.log(" [x] Received '%s'", message.content.toString());
|
|
64
61
|
}, { noAck: true });
|
|
65
62
|
await channel.consume(queue2, (message) => {
|
|
66
|
-
console.log(" [x] Received queue2 '%s'", message.content.toString());
|
|
67
63
|
}, { noAck: true });
|
|
68
64
|
return "ok";
|
|
69
65
|
}
|
|
@@ -38,33 +38,33 @@ export default class TestOrm {
|
|
|
38
38
|
|
|
39
39
|
@getMapping("/orm/count")
|
|
40
40
|
async countTest(req, res) {
|
|
41
|
-
const
|
|
42
|
-
res.send(
|
|
41
|
+
const total = await this.userModel.count();
|
|
42
|
+
res.send({"count": total});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
@getMapping("/orm/new")
|
|
46
46
|
async newUserTest(req, res) {
|
|
47
|
-
const
|
|
48
|
-
res.send("
|
|
47
|
+
const newId = await this.userModel.newUsers();
|
|
48
|
+
res.send({"newId": newId});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
@getMapping("/orm/page/calculate")
|
|
52
52
|
async calculatePage(req, res) {
|
|
53
53
|
const pages = this.userModel.pager(15, 376);
|
|
54
|
-
res.
|
|
54
|
+
res.json(pages);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
@getMapping("/orm/pages/:id")
|
|
58
58
|
async findPage(req, res) {
|
|
59
59
|
const results = await this.userModel.findAll("1", { id: -1 }, "*", { page: req.params.id, pageSize: 3 });
|
|
60
60
|
log(this.userModel.page);
|
|
61
|
-
res.
|
|
61
|
+
res.json(results);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
@postMapping("/orm/edit")
|
|
65
65
|
async updateTest(req, res) {
|
|
66
|
-
const
|
|
67
|
-
res.send(
|
|
66
|
+
const effectRows = await this.userModel.editUser(req.body.id, req.body.name);
|
|
67
|
+
res.send({"effectRows": effectRows});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
//@schedule("* * * * * *")
|
|
@@ -18,20 +18,20 @@ export default class TestRequest {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
@postMapping("/request/body")
|
|
21
|
-
testBody(@res res, @reqBody body:
|
|
21
|
+
testBody(@res res, @reqBody body: UserDto):MutilUsers {
|
|
22
22
|
log("body: " + JSON.stringify(body));
|
|
23
|
-
return new MutilUsers("group", [
|
|
23
|
+
return new MutilUsers("group", [body]);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
@postMapping("/request/form")
|
|
27
27
|
testForm(@res res, @reqForm("name") name: string) {
|
|
28
28
|
log("form: " + JSON.stringify(name));
|
|
29
|
-
res.send("
|
|
29
|
+
res.send("Got name: " + name);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
@getMapping("/request/param/:id")
|
|
33
33
|
testParam(@res res, @reqParam id: number) {
|
|
34
34
|
log("id: " + id);
|
|
35
|
-
res.send("test param");
|
|
35
|
+
res.send("test param: " + id);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -8,24 +8,25 @@ export default class UserModel extends Model {
|
|
|
8
8
|
const users = await this.findAll({
|
|
9
9
|
id: { $lt: 10, $lte: 20 }, "name": { $like: "%a%" },
|
|
10
10
|
$or: [{ id: 1 }, { id: 2 }]
|
|
11
|
-
});
|
|
11
|
+
}, "id asc", "*", { page: 1, pageSize: 10 });
|
|
12
12
|
log("users", users);
|
|
13
13
|
return "getUsers";
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async getUser(id: number) {
|
|
17
|
-
const user = await this.find({ id: id }, "");
|
|
17
|
+
const user = await this.find({ id: id }, "id asc", "*");
|
|
18
18
|
log("user", user);
|
|
19
19
|
return "getUser";
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async newUsers() {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
new UserDto(
|
|
26
|
-
|
|
23
|
+
const newId = Math.ceil(Math.random() * 1000);
|
|
24
|
+
await this.create([
|
|
25
|
+
new UserDto(newId, "UserDto " + newId),
|
|
26
|
+
new UserDto(newId+1, "UserDto " + (newId+1)),
|
|
27
|
+
{ id: newId+2, name: "UserDto " + (newId+2) },
|
|
27
28
|
]);
|
|
28
|
-
return
|
|
29
|
+
return newId;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async remove(id: number) {
|
|
@@ -33,13 +34,13 @@ export default class UserModel extends Model {
|
|
|
33
34
|
return "remove rows: " + result;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
async count() {
|
|
37
|
+
async count():Promise<number> {
|
|
37
38
|
const result = await this.findCount("1");
|
|
38
|
-
return
|
|
39
|
+
return result;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
async editUser(id: number, name: string) {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
43
|
+
const effectRows = await this.update({ id: id }, { name: name });
|
|
44
|
+
return effectRows;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -74,7 +74,7 @@ function select(sql) {
|
|
|
74
74
|
exports.select = select;
|
|
75
75
|
function resultType(dataClass) {
|
|
76
76
|
return function (target, propertyKey) {
|
|
77
|
-
resultTypeMap.set([target.constructor.name, propertyKey].toString(),
|
|
77
|
+
resultTypeMap.set([target.constructor.name, propertyKey].toString(), dataClass);
|
|
78
78
|
//never return
|
|
79
79
|
};
|
|
80
80
|
}
|
|
@@ -32,15 +32,13 @@ class ExpressServer extends server_factory_class_1.default {
|
|
|
32
32
|
setMiddleware(middleware) {
|
|
33
33
|
this.middlewareList.push(middleware);
|
|
34
34
|
}
|
|
35
|
-
start(port) {
|
|
35
|
+
start(port, callback) {
|
|
36
36
|
this.app.use(this.authentication.afterCompletion);
|
|
37
37
|
this.middlewareList.forEach(middleware => {
|
|
38
38
|
this.app.use(middleware);
|
|
39
39
|
});
|
|
40
40
|
this.setDefaultMiddleware();
|
|
41
|
-
return this.app.listen(port,
|
|
42
|
-
(0, core_decorator_1.log)("server start at port: " + port);
|
|
43
|
-
});
|
|
41
|
+
return this.app.listen(port, callback);
|
|
44
42
|
}
|
|
45
43
|
setDefaultMiddleware() {
|
|
46
44
|
this.app.use(express.urlencoded({ extended: true }));
|
package/package.json
CHANGED
|
@@ -72,7 +72,7 @@ function select(sql: string) {
|
|
|
72
72
|
|
|
73
73
|
function resultType(dataClass) {
|
|
74
74
|
return function (target, propertyKey: string) {
|
|
75
|
-
resultTypeMap.set([target.constructor.name, propertyKey].toString(),
|
|
75
|
+
resultTypeMap.set([target.constructor.name, propertyKey].toString(), dataClass);
|
|
76
76
|
//never return
|
|
77
77
|
};
|
|
78
78
|
}
|
|
@@ -53,7 +53,7 @@ export default class ExpressServer extends ServerFactory {
|
|
|
53
53
|
this.middlewareList.push(middleware);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
public start(port: number): any {
|
|
56
|
+
public start(port: number, callback?: Function): any {
|
|
57
57
|
this.app.use(this.authentication.afterCompletion);
|
|
58
58
|
this.middlewareList.forEach(middleware => {
|
|
59
59
|
this.app.use(middleware);
|
|
@@ -61,9 +61,7 @@ export default class ExpressServer extends ServerFactory {
|
|
|
61
61
|
|
|
62
62
|
this.setDefaultMiddleware();
|
|
63
63
|
|
|
64
|
-
return this.app.listen(port,
|
|
65
|
-
log("server start at port: " + port);
|
|
66
|
-
});
|
|
64
|
+
return this.app.listen(port, callback);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
private setDefaultMiddleware() {
|
|
@@ -5,7 +5,4 @@ export default abstract class LogFactory {
|
|
|
5
5
|
public error(message?: any, ...optionalParams: any[]) : void {
|
|
6
6
|
console.error(message, ...optionalParams);
|
|
7
7
|
}
|
|
8
|
-
public debug(message?: any, ...optionalParams: any[]) : void {
|
|
9
|
-
console.debug(message, ...optionalParams);
|
|
10
|
-
}
|
|
11
8
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const chaiObj = require('chai');
|
|
2
|
+
chaiObj.use(require("chai-http"));
|
|
3
|
+
const expect = chaiObj.expect;
|
|
4
|
+
describe("Test Database", () => {
|
|
5
|
+
const testDatabase = [
|
|
6
|
+
{
|
|
7
|
+
"url": "/db/insert?id=" + Math.ceil(Math.random() * 1000),
|
|
8
|
+
"expect": "Insert success",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"url": "/db/insert2",
|
|
12
|
+
"expect": "Insert success",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"url": "/db/update",
|
|
16
|
+
"expect": "update success",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"url": "/db/set-cache?value=zzz",
|
|
20
|
+
"expect": "set cache success",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"url": "/db/get-cache",
|
|
24
|
+
"expect": "zzz",
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
testDatabase.forEach((testRequest) => {
|
|
28
|
+
it(testRequest.url, (done) => {
|
|
29
|
+
chaiObj.request("http://localhost:8081").get(testRequest.url).end((err, res) => {
|
|
30
|
+
chaiObj.assert.equal(testRequest.expect, res.text);
|
|
31
|
+
return done();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it("/db/select1", (done) => {
|
|
36
|
+
chaiObj.request("http://localhost:8081").get("/db/select1").end((err, res) => {
|
|
37
|
+
const dataList = JSON.parse(res.text);
|
|
38
|
+
expect(dataList).to.be.an('array');
|
|
39
|
+
expect(dataList[0]).to.have.property("id").which.is.a("number").equal(1);
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it("/db/select", (done) => {
|
|
44
|
+
chaiObj.request("http://localhost:8081").get("/db/select").end((err, res) => {
|
|
45
|
+
const dataList = JSON.parse(res.text);
|
|
46
|
+
expect(dataList).to.be.an('array');
|
|
47
|
+
expect(dataList[0]).to.have.property('id');
|
|
48
|
+
done();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it("/db/select-user", (done) => {
|
|
52
|
+
chaiObj.request("http://localhost:8081").get("/db/select-user").end((err, res) => {
|
|
53
|
+
const dataList = JSON.parse(res.text);
|
|
54
|
+
expect(dataList).to.be.an('array');
|
|
55
|
+
expect(dataList[0]).to.have.property('id');
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export {};
|
package/test/first-page.test.ts
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
const chaiObj = require('chai');
|
|
2
|
-
|
|
3
2
|
chaiObj.use(require("chai-http"));
|
|
4
3
|
|
|
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
|
-
});
|
|
4
|
+
describe("Test First page", () => {
|
|
5
|
+
const firstPageRequests = [
|
|
6
|
+
{
|
|
7
|
+
"url": "/first",
|
|
8
|
+
"expect": "FirstPage index running",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"url": "/first/sendJson",
|
|
12
|
+
"expect": JSON.stringify({
|
|
13
|
+
"from": "sendJson",
|
|
14
|
+
"to": "Browser"
|
|
15
|
+
}),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"url": "/first/sendResult",
|
|
19
|
+
"expect": "sendResult",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"url": "/first/renderTest",
|
|
23
|
+
"expect": "Hello zzz!",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"url": "/test/error",
|
|
27
|
+
"expect": "This is a error log",
|
|
28
|
+
}
|
|
29
|
+
]
|
|
32
30
|
firstPageRequests.forEach((testRequest) => {
|
|
33
31
|
it(testRequest.url, (done) => {
|
|
34
32
|
chaiObj.request("http://localhost:8081").get(testRequest.url).end((err, res) => {
|
|
@@ -37,9 +35,7 @@ describe("First page", () => {
|
|
|
37
35
|
});
|
|
38
36
|
});
|
|
39
37
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
});
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export {};
|
package/test/hooks.ts
ADDED
package/test/mq.test.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const chaiObj = require('chai');
|
|
2
|
+
|
|
3
|
+
chaiObj.use(require("chai-http"));
|
|
4
|
+
|
|
5
|
+
const expect = chaiObj.expect;
|
|
6
|
+
|
|
7
|
+
describe("Test RabbitMQ", () => {
|
|
8
|
+
it("/mq/listen", (done) => {
|
|
9
|
+
chaiObj.request("http://localhost:8081").get("/mq/listen").end((err, res) => {
|
|
10
|
+
expect(res.text).to.be.equal("ok");
|
|
11
|
+
done();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("/mq/sendByMQClass", (done) => {
|
|
15
|
+
chaiObj.request("http://localhost:8081").get("/mq/sendByMQClass").end((err, res) => {
|
|
16
|
+
expect(res.text).to.be.equal("sent by MQClass");
|
|
17
|
+
done();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it("/mq/sendByQueue", (done) => {
|
|
21
|
+
chaiObj.request("http://localhost:8081").get("/mq/sendByQueue").end((err, res) => {
|
|
22
|
+
expect(res.text).to.be.equal("sent by queue");
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("/mq/sendByExchange", (done) => {
|
|
27
|
+
chaiObj.request("http://localhost:8081").get("/mq/sendByExchange").end((err, res) => {
|
|
28
|
+
expect(res.text).to.be.equal("sent by exchange");
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export { };
|
package/test/orm.test.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const chaiObj = require('chai');
|
|
2
|
+
chaiObj.use(require("chai-http"));
|
|
3
|
+
const expect = chaiObj.expect;
|
|
4
|
+
|
|
5
|
+
describe("Test Request Paramters", () => {
|
|
6
|
+
it("/redis", (done) => {
|
|
7
|
+
chaiObj.request("http://localhost:8081").get("/redis").end((err, res) => {
|
|
8
|
+
expect(res.text).to.be.equal("get from redis: " + "Hello World");
|
|
9
|
+
done();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
it("/orm/first", (done) => {
|
|
13
|
+
chaiObj.request("http://localhost:8081").get("/orm/first").end((err, res) => {
|
|
14
|
+
expect(res.text).to.be.equal("first test, to getUsers");
|
|
15
|
+
done();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it("/orm/one", (done) => {
|
|
19
|
+
chaiObj.request("http://localhost:8081").get("/orm/one?id=1").end((err, res) => {
|
|
20
|
+
expect(res.text).to.be.equal("find one test, to getUser");
|
|
21
|
+
done();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it("/orm/delete", (done) => {
|
|
25
|
+
chaiObj.request("http://localhost:8081").get("/orm/delete?id=0").end((err, res) => {
|
|
26
|
+
expect(res.text).to.be.equal("remove user, results: remove rows: 0");
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it("/orm/count", (done) => {
|
|
31
|
+
chaiObj.request("http://localhost:8081").get("/orm/count").end((err, res) => {
|
|
32
|
+
expect(JSON.parse(res.text)).to.have.property("count").which.is.a("number").above(0);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it("/orm/new", (done) => {
|
|
37
|
+
chaiObj.request("http://localhost:8081").get("/orm/new").end((err, res) => {
|
|
38
|
+
expect(JSON.parse(res.text)).to.have.property("newId").which.is.a("number").above(0);
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it("/orm/page/calculate", (done) => {
|
|
43
|
+
chaiObj.request("http://localhost:8081").get("/orm/page/calculate").end((err, res) => {
|
|
44
|
+
expect(JSON.parse(res.text)).to.have.property("totalPage").which.is.a("number").equal(38);
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it("/orm/pages", (done) => {
|
|
49
|
+
chaiObj.request("http://localhost:8081").get("/orm/pages/1").end((err, res) => {
|
|
50
|
+
expect(JSON.parse(res.text)).is.a("array").lengthOf(3);
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it("/orm/edit", (done) => {
|
|
55
|
+
chaiObj.request("http://localhost:8081").post("/orm/edit")
|
|
56
|
+
.type("form")
|
|
57
|
+
.send({ id: 1, name: "new name" })
|
|
58
|
+
.end((err, res) => {
|
|
59
|
+
expect(JSON.parse(res.text)).to.have.property("effectRows").which.to.be.oneOf([0, 1]);
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export { };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import MutilUsers from "../app/src/entities/mutil-users.class";
|
|
2
|
+
import UserDto from "../app/src/entities/user-dto.class";
|
|
3
|
+
const chaiObj = require('chai');
|
|
4
|
+
chaiObj.use(require("chai-http"));
|
|
5
|
+
const expect = chaiObj.expect;
|
|
6
|
+
|
|
7
|
+
describe("Test Request Paramters", () => {
|
|
8
|
+
it("/request/res", (done) => {
|
|
9
|
+
chaiObj.request("http://localhost:8081").get("/request/res").end((err, res) => {
|
|
10
|
+
expect(res.text).to.be.equal("test res");
|
|
11
|
+
done();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
it("/request/query", (done) => {
|
|
15
|
+
chaiObj.request("http://localhost:8081").get("/request/query?id=100").end((err, res) => {
|
|
16
|
+
expect(res.text).to.be.equal(JSON.stringify(
|
|
17
|
+
new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]
|
|
18
|
+
)));
|
|
19
|
+
done();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("/request/body", (done) => {
|
|
23
|
+
const sendUser = new UserDto(100, "name100");
|
|
24
|
+
chaiObj.request("http://localhost:8081").post("/request/body")
|
|
25
|
+
.send(sendUser)
|
|
26
|
+
.end((err, res) => {
|
|
27
|
+
expect(res.text).to.be.equal(JSON.stringify(new MutilUsers("group", [sendUser])));
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it("/request/form", (done) => {
|
|
32
|
+
const sendName = "name200";
|
|
33
|
+
chaiObj.request("http://localhost:8081").post("/request/form")
|
|
34
|
+
.type("form")
|
|
35
|
+
.send({ name: sendName })
|
|
36
|
+
.end((err, res) => {
|
|
37
|
+
expect(res.text).to.be.equal("Got name: " + sendName);
|
|
38
|
+
done();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it("/request/param", (done) => {
|
|
42
|
+
const sendId = 200;
|
|
43
|
+
chaiObj.request("http://localhost:8081").get("/request/param/" + sendId).end((err, res) => {
|
|
44
|
+
expect(res.text).to.be.equal("test param: " + sendId);
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as jwttoken from "jsonwebtoken";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
const chaiObj = require('chai');
|
|
4
|
+
|
|
5
|
+
chaiObj.use(require("chai-http"));
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe("Test Sencond Page", () => {
|
|
9
|
+
it("/second/setCookie", (done) => {
|
|
10
|
+
chaiObj.request("http://localhost:8081").get("/second/setCookie").end((err, res) => {
|
|
11
|
+
chaiObj.assert.equal(res.headers["set-cookie"].includes("name=zzz; Path=/"), true);
|
|
12
|
+
done();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
it("/second/getCookie", (done) => {
|
|
16
|
+
const cookieSet = "mycookie"
|
|
17
|
+
chaiObj.request("http://localhost:8081").get("/second/getCookie")
|
|
18
|
+
.set("Cookie", "name=" + cookieSet).end((err, res) => {
|
|
19
|
+
chaiObj.assert.equal(res.text, "getCookie: " + cookieSet);
|
|
20
|
+
done();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("/second/testSession", (done) => {
|
|
24
|
+
chaiObj.request("http://localhost:8081").get("/second/testSession").end((err, res) => {
|
|
25
|
+
chaiObj.assert.equal(res.text, "testForSession: 1");
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it("/upload", (done) => {
|
|
30
|
+
const uploadfile = "./app/static/k.jpg";
|
|
31
|
+
chaiObj.request("http://localhost:8081").post("/upload")
|
|
32
|
+
.set('Content-Type', 'multipart/form-data')
|
|
33
|
+
.attach("file", uploadfile)
|
|
34
|
+
.end((err, res) => {
|
|
35
|
+
chaiObj.assert.equal(res.text, "upload success");
|
|
36
|
+
done();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
it("/form", (done) => {
|
|
40
|
+
const token = jwttoken.sign({ foo: 'bar' }, 'shhhhhhared-secret');
|
|
41
|
+
const fileContents = fs.readFileSync("./app/src/views/upload.html", "utf8");
|
|
42
|
+
chaiObj.request("http://localhost:8081").post("/form")
|
|
43
|
+
.set({ "Authorization": `Bearer ${token}` })
|
|
44
|
+
.end((err, res) => {
|
|
45
|
+
chaiObj.assert.equal(res.text, fileContents);
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export { };
|