typespeed 2.3.3 → 2.3.4
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/.github/workflows/test.yml +47 -0
- package/README.md +2 -1
- package/app/src/aop-test.class.ts +1 -1
- package/app/src/config-development.json +12 -9
- package/app/src/custom-log.class.ts +1 -1
- package/app/src/first-page.class.ts +1 -1
- package/app/src/jwt-authentication.class.ts +2 -2
- package/app/src/main.ts +1 -1
- package/app/src/second-page.class.ts +1 -1
- package/app/src/test-database.class.ts +10 -14
- package/app/src/test-log.class.ts +1 -1
- package/app/src/test-mq.class.ts +2 -47
- package/app/src/test-orm.class.ts +1 -1
- package/app/src/test-request.class.ts +1 -1
- package/app/src/user-model.class.ts +6 -2
- package/package.json +2 -2
- package/test/database.test.ts +19 -12
- package/test/first-page.test.ts +2 -1
- package/test/hooks.ts +4 -2
- package/test/mq.test.ts +3 -20
- package/test/orm.test.ts +10 -9
- package/test/request.test.ts +6 -5
- package/test/second-page.test.ts +6 -7
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
'on': ["push"]
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
name: 'Test TypeSpeed'
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
services:
|
|
9
|
+
redis:
|
|
10
|
+
image: redis
|
|
11
|
+
ports:
|
|
12
|
+
- 6379:6379
|
|
13
|
+
rabbitmq:
|
|
14
|
+
image: rabbitmq:3.8
|
|
15
|
+
env:
|
|
16
|
+
RABBITMQ_DEFAULT_USER: guest
|
|
17
|
+
RABBITMQ_DEFAULT_PASS: guest
|
|
18
|
+
ports:
|
|
19
|
+
- 5672
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/setup-node@v1
|
|
22
|
+
with:
|
|
23
|
+
node-version: 18
|
|
24
|
+
- uses: actions/checkout@v2
|
|
25
|
+
- name: Setup MySQL
|
|
26
|
+
run: |
|
|
27
|
+
sudo /etc/init.d/mysql start
|
|
28
|
+
mysql -e 'CREATE DATABASE test;USE test; \
|
|
29
|
+
CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(100) DEFAULT NULL,PRIMARY KEY (`id`)) \
|
|
30
|
+
ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;SHOW TABLES;' -uroot -proot
|
|
31
|
+
- name: 'Cache node_modules'
|
|
32
|
+
uses: actions/cache@v2
|
|
33
|
+
with:
|
|
34
|
+
path: ~/.npm
|
|
35
|
+
key: ${{ runner.os }}-node-v18-${{ hashFiles('**/package.json') }}
|
|
36
|
+
restore-keys: |
|
|
37
|
+
${{ runner.os }}-node-v18-
|
|
38
|
+
- name: Install Dependencies
|
|
39
|
+
run: npm install
|
|
40
|
+
- name: Run Tests with Coverage
|
|
41
|
+
run: npm run test-with-coverage
|
|
42
|
+
env:
|
|
43
|
+
LOCAL_HOST: localhost
|
|
44
|
+
- name: Upload coverage reports to Codecov
|
|
45
|
+
uses: codecov/codecov-action@v3
|
|
46
|
+
env:
|
|
47
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
package/README.md
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
[](https://github.com/SpeedPHP/typespeed/commits/main)
|
|
6
6
|
[](https://www.npmjs.com/package/typespeed)
|
|
7
7
|
[](https://github.com/SpeedPHP/typespeed/blob/main/LICENSE)
|
|
8
|
+
[](https://codecov.io/gh/SpeedPHP/typespeed)
|
|
8
9
|
|
|
9
10
|
### 特点
|
|
10
11
|
|
|
11
12
|
- 遵循 MIT 许可的开源项目。
|
|
12
|
-
- 提供
|
|
13
|
+
- 提供 30 个 TypeScript 装饰器,这些装饰器构成了完整的 Web 框架功能,包括对象管理、Web 路由、数据库操作等。
|
|
13
14
|
- 通过命令行脚手架,可以快速创建项目,零配置启动。
|
|
14
15
|
- 基于依赖注入、AOP、中间件和启动扫描等编程理念开发实现。
|
|
15
16
|
- 底层采用 ExpressJS 实现,提供稳定、快速的 Web 服务。
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"server": {
|
|
3
|
-
"port": "8081"
|
|
4
|
-
},
|
|
5
|
-
"database": {
|
|
6
|
-
"host": "localhost",
|
|
7
|
-
"port": "4455",
|
|
8
|
-
"name": "test"
|
|
9
|
-
},
|
|
10
2
|
"view": {
|
|
11
3
|
"engine": "mustache",
|
|
12
4
|
"path": "/app/src/views",
|
|
13
5
|
"suffix": "html"
|
|
14
6
|
},
|
|
7
|
+
"mysql": {
|
|
8
|
+
"host": "127.0.0.1",
|
|
9
|
+
"user": "root",
|
|
10
|
+
"password": "root",
|
|
11
|
+
"database": "test"
|
|
12
|
+
},
|
|
13
|
+
"redis": {
|
|
14
|
+
"host": "127.0.0.1",
|
|
15
|
+
"port": "6379",
|
|
16
|
+
"db": 0
|
|
17
|
+
},
|
|
15
18
|
"rabbitmq": {
|
|
16
19
|
"protocol": "amqp",
|
|
17
|
-
"hostname": "
|
|
20
|
+
"hostname": "127.0.0.1",
|
|
18
21
|
"port": 5672,
|
|
19
22
|
"username": "guest",
|
|
20
23
|
"password": "guest"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationFactory, bean, config } from "../../";
|
|
1
|
+
import { AuthenticationFactory, bean, config } from "../../src/typespeed";
|
|
2
2
|
import express from "express";
|
|
3
3
|
import { expressjwt, GetVerificationKey } from "express-jwt";
|
|
4
4
|
import * as jwt from 'jsonwebtoken';
|
|
@@ -23,8 +23,8 @@ export default class JwtAuthentication extends AuthenticationFactory {
|
|
|
23
23
|
if (err) {
|
|
24
24
|
//next(err);
|
|
25
25
|
}
|
|
26
|
-
next();
|
|
27
26
|
});
|
|
28
27
|
}
|
|
28
|
+
next();
|
|
29
29
|
}
|
|
30
30
|
}
|
package/app/src/main.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { insert, update, select, param, resultType, cache, CacheFactory, getMapping, component, log, autoware } from "../../";
|
|
1
|
+
import { insert, update, select, param, resultType, cache, CacheFactory, getMapping, component, log, autoware } from "../../src/typespeed";
|
|
2
2
|
import UserDto from "./entities/user-dto.class";
|
|
3
3
|
|
|
4
4
|
@component
|
|
@@ -11,24 +11,22 @@ export default class TestDatabase {
|
|
|
11
11
|
async insert(req, res) {
|
|
12
12
|
const id = req.query.id || 1;
|
|
13
13
|
const newId = await this.addRow("new name " + id, id);
|
|
14
|
-
|
|
15
|
-
res.send("Insert success");
|
|
14
|
+
res.send("Insert success: " + newId);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
@getMapping("/db/insert2")
|
|
19
18
|
async insertByObject(req, res) {
|
|
20
19
|
const newId = await this.addRowByObject({
|
|
21
|
-
"id":
|
|
20
|
+
"id": req.query.id, "name": "new name " + req.query.id
|
|
22
21
|
});
|
|
23
|
-
|
|
24
|
-
res.send("Insert success");
|
|
22
|
+
res.send("Insert success: " + newId);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
@getMapping("/db/update")
|
|
28
26
|
async update(req, res) {
|
|
29
|
-
const affectedRows = await this.editRow();
|
|
27
|
+
const affectedRows = await this.editRow(req.query.id);
|
|
30
28
|
log("Update rows: " + affectedRows);
|
|
31
|
-
res.send("update success");
|
|
29
|
+
res.send("update success: " + affectedRows);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
@getMapping("/db/select")
|
|
@@ -38,17 +36,15 @@ export default class TestDatabase {
|
|
|
38
36
|
res.send(rows);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
@getMapping("/db/
|
|
39
|
+
@getMapping("/db/select-row")
|
|
42
40
|
async selectById(req, res) {
|
|
43
|
-
const row = await this.findRow(req.query.id
|
|
44
|
-
log("select rows: " + row);
|
|
41
|
+
const row = await this.findRow(req.query.id);
|
|
45
42
|
res.send(row);
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
@getMapping("/db/select-user")
|
|
49
46
|
async selectUser(req, res) {
|
|
50
47
|
const users: UserDto[] = await this.findUsers();
|
|
51
|
-
log("select users: " + users);
|
|
52
48
|
res.send(users);
|
|
53
49
|
}
|
|
54
50
|
|
|
@@ -69,8 +65,8 @@ export default class TestDatabase {
|
|
|
69
65
|
@insert("Insert into `user` (id, name) values (#{id}, #{name})")
|
|
70
66
|
private async addRowByObject(myParams: object) { }
|
|
71
67
|
|
|
72
|
-
@update("Update `user` set `name` = 'test5' where id =
|
|
73
|
-
private async editRow() { }
|
|
68
|
+
@update("Update `user` set `name` = 'test5' where id = #{id}")
|
|
69
|
+
private async editRow(@param("id") id: number) { }
|
|
74
70
|
|
|
75
71
|
@select("Select * from `user`")
|
|
76
72
|
private async selectRow() { }
|
package/app/src/test-mq.class.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { component, getMapping, autoware, log, RabbitMQ, rabbitListener } from "../../";
|
|
1
|
+
import { component, getMapping, autoware, log, RabbitMQ, rabbitListener } from "../../src/typespeed";
|
|
2
2
|
import { connect } from "amqplib";
|
|
3
3
|
|
|
4
4
|
|
|
@@ -16,51 +16,6 @@ export default class TestMq {
|
|
|
16
16
|
@getMapping("/mq/sendByMQClass")
|
|
17
17
|
async sendByMQClass() {
|
|
18
18
|
this.rabbitMQ.send("myqueues", "hello world, by MQClass");
|
|
19
|
-
return "
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@getMapping("/mq/sendByQueue")
|
|
23
|
-
async sendMq() {
|
|
24
|
-
const queue = 'myqueues';
|
|
25
|
-
const text = "hello world, by queue";
|
|
26
|
-
const connection = await connect({
|
|
27
|
-
protocol: 'amqp',
|
|
28
|
-
hostname: 'localhost',
|
|
29
|
-
port: 5672,
|
|
30
|
-
username: 'guest',
|
|
31
|
-
password: 'guest'
|
|
32
|
-
});
|
|
33
|
-
const channel = await connection.createChannel();
|
|
34
|
-
await channel.assertQueue(queue);
|
|
35
|
-
channel.sendToQueue(queue, Buffer.from(text));
|
|
36
|
-
await channel.close();
|
|
37
|
-
return "sent by queue";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@getMapping("/mq/sendByExchange")
|
|
41
|
-
async sendMq2() {
|
|
42
|
-
const exchange = 'myexchanges';
|
|
43
|
-
const text = "hello world, by exchange";
|
|
44
|
-
const connection = await connect('amqp://localhost');
|
|
45
|
-
const channel = await connection.createChannel();
|
|
46
|
-
await channel.checkExchange(exchange);
|
|
47
|
-
channel.publish(exchange, '', Buffer.from(text));
|
|
48
|
-
await channel.close();
|
|
49
|
-
return "sent by exchange";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@getMapping("/mq/listen")
|
|
53
|
-
async testMq() {
|
|
54
|
-
const connection = await connect('amqp://localhost');
|
|
55
|
-
const channel = await connection.createChannel();
|
|
56
|
-
const queue = 'myqueues';
|
|
57
|
-
const queue2 = 'myqueues2';
|
|
58
|
-
await channel.checkQueue(queue);
|
|
59
|
-
await channel.checkQueue(queue2);
|
|
60
|
-
await channel.consume(queue, (message) => {
|
|
61
|
-
}, { noAck: true });
|
|
62
|
-
await channel.consume(queue2, (message) => {
|
|
63
|
-
}, { noAck: true });
|
|
64
|
-
return "ok";
|
|
19
|
+
return "Sent by MQClass";
|
|
65
20
|
}
|
|
66
21
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resource, component, log, autoware, schedule, getMapping, postMapping, Redis } from "../../";
|
|
1
|
+
import { resource, component, log, autoware, schedule, getMapping, postMapping, Redis } from "../../src/typespeed";
|
|
2
2
|
import UserModel from "./user-model.class";
|
|
3
3
|
|
|
4
4
|
@component
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { component, getMapping, postMapping, log, req, res, reqQuery, reqBody, reqForm, reqParam } from "../../";
|
|
1
|
+
import { component, getMapping, postMapping, log, req, res, reqQuery, reqBody, reqForm, reqParam } from "../../src/typespeed";
|
|
2
2
|
import MutilUsers from "./entities/mutil-users.class";
|
|
3
3
|
import UserDto from "./entities/user-dto.class";
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { log, Model } from "../../";
|
|
1
|
+
import { log, Model } from "../../src/typespeed";
|
|
2
2
|
import UserDto from "./entities/user-dto.class";
|
|
3
3
|
|
|
4
4
|
export default class UserModel extends Model {
|
|
@@ -20,7 +20,7 @@ export default class UserModel extends Model {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async newUsers() {
|
|
23
|
-
const newId =
|
|
23
|
+
const newId = this.random(1000, 2000);
|
|
24
24
|
await this.create([
|
|
25
25
|
new UserDto(newId, "UserDto " + newId),
|
|
26
26
|
new UserDto(newId+1, "UserDto " + (newId+1)),
|
|
@@ -43,4 +43,8 @@ export default class UserModel extends Model {
|
|
|
43
43
|
const effectRows = await this.update({ id: id }, { name: name });
|
|
44
44
|
return effectRows;
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
private random(min, max) {
|
|
48
|
+
return Math.round(Math.random() * (max - min)) + min;
|
|
49
|
+
}
|
|
46
50
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespeed",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "A new Framework for TypeScript.",
|
|
5
5
|
"author": "speedphp",
|
|
6
6
|
"license": "MIT License",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha --require ts-node/register test/**/*.ts --exit",
|
|
9
|
-
"test-with-coverage": "nyc --reporter=
|
|
9
|
+
"test-with-coverage": "nyc --reporter=lcov npm test",
|
|
10
10
|
"start": "ts-node --transpile-only app/src/main.ts",
|
|
11
11
|
"build": "tsc -p .",
|
|
12
12
|
"postbuild": "cp src/typespeed.d.ts dist/typespeed.d.ts && cp -r src/default/pages dist/default/pages && cp -r src/scaffold/templates dist/scaffold/templates",
|
package/test/database.test.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
|
|
1
2
|
const chaiObj = require('chai');
|
|
2
3
|
chaiObj.use(require("chai-http"));
|
|
3
4
|
const expect = chaiObj.expect;
|
|
4
5
|
describe("Test Database", () => {
|
|
6
|
+
const randomId = random(3000, 5000);
|
|
7
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
5
8
|
const testDatabase = [
|
|
6
9
|
{
|
|
7
|
-
"url": "/db/insert?id=" +
|
|
8
|
-
"expect": "Insert success",
|
|
10
|
+
"url": "/db/insert?id=" + randomId,
|
|
11
|
+
"expect": "Insert success: " + randomId,
|
|
9
12
|
},
|
|
10
13
|
{
|
|
11
|
-
"url": "/db/insert2",
|
|
12
|
-
"expect": "Insert success",
|
|
14
|
+
"url": "/db/insert2?id=" + (randomId + 1),
|
|
15
|
+
"expect": "Insert success: " + (randomId + 1),
|
|
13
16
|
},
|
|
14
17
|
{
|
|
15
|
-
"url": "/db/update",
|
|
16
|
-
"expect": "update success",
|
|
18
|
+
"url": "/db/update?id=" + randomId,
|
|
19
|
+
"expect": "update success: 1",
|
|
17
20
|
},
|
|
18
21
|
{
|
|
19
22
|
"url": "/db/set-cache?value=zzz",
|
|
@@ -26,22 +29,22 @@ describe("Test Database", () => {
|
|
|
26
29
|
]
|
|
27
30
|
testDatabase.forEach((testRequest) => {
|
|
28
31
|
it(testRequest.url, (done) => {
|
|
29
|
-
chaiObj.request(
|
|
32
|
+
chaiObj.request(testAddr).get(testRequest.url).end((err, res) => {
|
|
30
33
|
chaiObj.assert.equal(testRequest.expect, res.text);
|
|
31
34
|
return done();
|
|
32
35
|
});
|
|
33
36
|
});
|
|
34
37
|
});
|
|
35
|
-
it("/db/
|
|
36
|
-
chaiObj.request(
|
|
38
|
+
it("/db/select-row", (done) => {
|
|
39
|
+
chaiObj.request(testAddr).get("/db/select-row?id=" + randomId).end((err, res) => {
|
|
37
40
|
const dataList = JSON.parse(res.text);
|
|
38
41
|
expect(dataList).to.be.an('array');
|
|
39
|
-
expect(dataList[0]).to.have.property("id").which.is.a("number").equal(
|
|
42
|
+
expect(dataList[0]).to.have.property("id").which.is.a("number").equal(randomId);
|
|
40
43
|
done();
|
|
41
44
|
});
|
|
42
45
|
});
|
|
43
46
|
it("/db/select", (done) => {
|
|
44
|
-
chaiObj.request(
|
|
47
|
+
chaiObj.request(testAddr).get("/db/select").end((err, res) => {
|
|
45
48
|
const dataList = JSON.parse(res.text);
|
|
46
49
|
expect(dataList).to.be.an('array');
|
|
47
50
|
expect(dataList[0]).to.have.property('id');
|
|
@@ -49,7 +52,7 @@ describe("Test Database", () => {
|
|
|
49
52
|
});
|
|
50
53
|
});
|
|
51
54
|
it("/db/select-user", (done) => {
|
|
52
|
-
chaiObj.request(
|
|
55
|
+
chaiObj.request(testAddr).get("/db/select-user").end((err, res) => {
|
|
53
56
|
const dataList = JSON.parse(res.text);
|
|
54
57
|
expect(dataList).to.be.an('array');
|
|
55
58
|
expect(dataList[0]).to.have.property('id');
|
|
@@ -58,4 +61,8 @@ describe("Test Database", () => {
|
|
|
58
61
|
});
|
|
59
62
|
});
|
|
60
63
|
|
|
64
|
+
function random(min, max) {
|
|
65
|
+
return Math.round(Math.random() * (max - min)) + min;
|
|
66
|
+
}
|
|
67
|
+
|
|
61
68
|
export {};
|
package/test/first-page.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ const chaiObj = require('chai');
|
|
|
2
2
|
chaiObj.use(require("chai-http"));
|
|
3
3
|
|
|
4
4
|
describe("Test First page", () => {
|
|
5
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
5
6
|
const firstPageRequests = [
|
|
6
7
|
{
|
|
7
8
|
"url": "/first",
|
|
@@ -29,7 +30,7 @@ describe("Test First page", () => {
|
|
|
29
30
|
]
|
|
30
31
|
firstPageRequests.forEach((testRequest) => {
|
|
31
32
|
it(testRequest.url, (done) => {
|
|
32
|
-
chaiObj.request(
|
|
33
|
+
chaiObj.request(testAddr).get(testRequest.url).end((err, res) => {
|
|
33
34
|
chaiObj.assert.equal(testRequest.expect, res.text);
|
|
34
35
|
return done();
|
|
35
36
|
});
|
package/test/hooks.ts
CHANGED
package/test/mq.test.ts
CHANGED
|
@@ -5,27 +5,10 @@ chaiObj.use(require("chai-http"));
|
|
|
5
5
|
const expect = chaiObj.expect;
|
|
6
6
|
|
|
7
7
|
describe("Test RabbitMQ", () => {
|
|
8
|
-
|
|
9
|
-
chaiObj.request("http://localhost:8081").get("/mq/listen").end((err, res) => {
|
|
10
|
-
expect(res.text).to.be.equal("ok");
|
|
11
|
-
done();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
8
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
14
9
|
it("/mq/sendByMQClass", (done) => {
|
|
15
|
-
chaiObj.request(
|
|
16
|
-
expect(res.text).to.be.equal("
|
|
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");
|
|
10
|
+
chaiObj.request(testAddr).get("/mq/sendByMQClass").end((err, res) => {
|
|
11
|
+
expect(res.text).to.be.equal("Sent by MQClass");
|
|
29
12
|
done();
|
|
30
13
|
});
|
|
31
14
|
});
|
package/test/orm.test.ts
CHANGED
|
@@ -3,56 +3,57 @@ chaiObj.use(require("chai-http"));
|
|
|
3
3
|
const expect = chaiObj.expect;
|
|
4
4
|
|
|
5
5
|
describe("Test Request Paramters", () => {
|
|
6
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
6
7
|
it("/redis", (done) => {
|
|
7
|
-
chaiObj.request(
|
|
8
|
+
chaiObj.request(testAddr).get("/redis").end((err, res) => {
|
|
8
9
|
expect(res.text).to.be.equal("get from redis: " + "Hello World");
|
|
9
10
|
done();
|
|
10
11
|
});
|
|
11
12
|
});
|
|
12
13
|
it("/orm/first", (done) => {
|
|
13
|
-
chaiObj.request(
|
|
14
|
+
chaiObj.request(testAddr).get("/orm/first").end((err, res) => {
|
|
14
15
|
expect(res.text).to.be.equal("first test, to getUsers");
|
|
15
16
|
done();
|
|
16
17
|
});
|
|
17
18
|
});
|
|
18
19
|
it("/orm/one", (done) => {
|
|
19
|
-
chaiObj.request(
|
|
20
|
+
chaiObj.request(testAddr).get("/orm/one?id=1").end((err, res) => {
|
|
20
21
|
expect(res.text).to.be.equal("find one test, to getUser");
|
|
21
22
|
done();
|
|
22
23
|
});
|
|
23
24
|
});
|
|
24
25
|
it("/orm/delete", (done) => {
|
|
25
|
-
chaiObj.request(
|
|
26
|
+
chaiObj.request(testAddr).get("/orm/delete?id=0").end((err, res) => {
|
|
26
27
|
expect(res.text).to.be.equal("remove user, results: remove rows: 0");
|
|
27
28
|
done();
|
|
28
29
|
});
|
|
29
30
|
});
|
|
30
31
|
it("/orm/count", (done) => {
|
|
31
|
-
chaiObj.request(
|
|
32
|
+
chaiObj.request(testAddr).get("/orm/count").end((err, res) => {
|
|
32
33
|
expect(JSON.parse(res.text)).to.have.property("count").which.is.a("number").above(0);
|
|
33
34
|
done();
|
|
34
35
|
});
|
|
35
36
|
});
|
|
36
37
|
it("/orm/new", (done) => {
|
|
37
|
-
chaiObj.request(
|
|
38
|
+
chaiObj.request(testAddr).get("/orm/new").end((err, res) => {
|
|
38
39
|
expect(JSON.parse(res.text)).to.have.property("newId").which.is.a("number").above(0);
|
|
39
40
|
done();
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
it("/orm/page/calculate", (done) => {
|
|
43
|
-
chaiObj.request(
|
|
44
|
+
chaiObj.request(testAddr).get("/orm/page/calculate").end((err, res) => {
|
|
44
45
|
expect(JSON.parse(res.text)).to.have.property("totalPage").which.is.a("number").equal(38);
|
|
45
46
|
done();
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
it("/orm/pages", (done) => {
|
|
49
|
-
chaiObj.request(
|
|
50
|
+
chaiObj.request(testAddr).get("/orm/pages/1").end((err, res) => {
|
|
50
51
|
expect(JSON.parse(res.text)).is.a("array").lengthOf(3);
|
|
51
52
|
done();
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
it("/orm/edit", (done) => {
|
|
55
|
-
chaiObj.request(
|
|
56
|
+
chaiObj.request(testAddr).post("/orm/edit")
|
|
56
57
|
.type("form")
|
|
57
58
|
.send({ id: 1, name: "new name" })
|
|
58
59
|
.end((err, res) => {
|
package/test/request.test.ts
CHANGED
|
@@ -5,14 +5,15 @@ chaiObj.use(require("chai-http"));
|
|
|
5
5
|
const expect = chaiObj.expect;
|
|
6
6
|
|
|
7
7
|
describe("Test Request Paramters", () => {
|
|
8
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
8
9
|
it("/request/res", (done) => {
|
|
9
|
-
chaiObj.request(
|
|
10
|
+
chaiObj.request(testAddr).get("/request/res").end((err, res) => {
|
|
10
11
|
expect(res.text).to.be.equal("test res");
|
|
11
12
|
done();
|
|
12
13
|
});
|
|
13
14
|
});
|
|
14
15
|
it("/request/query", (done) => {
|
|
15
|
-
chaiObj.request(
|
|
16
|
+
chaiObj.request(testAddr).get("/request/query?id=100").end((err, res) => {
|
|
16
17
|
expect(res.text).to.be.equal(JSON.stringify(
|
|
17
18
|
new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]
|
|
18
19
|
)));
|
|
@@ -21,7 +22,7 @@ describe("Test Request Paramters", () => {
|
|
|
21
22
|
});
|
|
22
23
|
it("/request/body", (done) => {
|
|
23
24
|
const sendUser = new UserDto(100, "name100");
|
|
24
|
-
chaiObj.request(
|
|
25
|
+
chaiObj.request(testAddr).post("/request/body")
|
|
25
26
|
.send(sendUser)
|
|
26
27
|
.end((err, res) => {
|
|
27
28
|
expect(res.text).to.be.equal(JSON.stringify(new MutilUsers("group", [sendUser])));
|
|
@@ -30,7 +31,7 @@ describe("Test Request Paramters", () => {
|
|
|
30
31
|
});
|
|
31
32
|
it("/request/form", (done) => {
|
|
32
33
|
const sendName = "name200";
|
|
33
|
-
chaiObj.request(
|
|
34
|
+
chaiObj.request(testAddr).post("/request/form")
|
|
34
35
|
.type("form")
|
|
35
36
|
.send({ name: sendName })
|
|
36
37
|
.end((err, res) => {
|
|
@@ -40,7 +41,7 @@ describe("Test Request Paramters", () => {
|
|
|
40
41
|
});
|
|
41
42
|
it("/request/param", (done) => {
|
|
42
43
|
const sendId = 200;
|
|
43
|
-
chaiObj.request(
|
|
44
|
+
chaiObj.request(testAddr).get("/request/param/" + sendId).end((err, res) => {
|
|
44
45
|
expect(res.text).to.be.equal("test param: " + sendId);
|
|
45
46
|
done();
|
|
46
47
|
});
|
package/test/second-page.test.ts
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
import * as jwttoken from "jsonwebtoken";
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
const chaiObj = require('chai');
|
|
4
|
-
|
|
5
4
|
chaiObj.use(require("chai-http"));
|
|
6
5
|
|
|
7
|
-
|
|
8
6
|
describe("Test Sencond Page", () => {
|
|
7
|
+
const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
|
|
9
8
|
it("/second/setCookie", (done) => {
|
|
10
|
-
chaiObj.request(
|
|
9
|
+
chaiObj.request(testAddr).get("/second/setCookie").end((err, res) => {
|
|
11
10
|
chaiObj.assert.equal(res.headers["set-cookie"].includes("name=zzz; Path=/"), true);
|
|
12
11
|
done();
|
|
13
12
|
});
|
|
14
13
|
});
|
|
15
14
|
it("/second/getCookie", (done) => {
|
|
16
15
|
const cookieSet = "mycookie"
|
|
17
|
-
chaiObj.request(
|
|
16
|
+
chaiObj.request(testAddr).get("/second/getCookie")
|
|
18
17
|
.set("Cookie", "name=" + cookieSet).end((err, res) => {
|
|
19
18
|
chaiObj.assert.equal(res.text, "getCookie: " + cookieSet);
|
|
20
19
|
done();
|
|
21
20
|
});
|
|
22
21
|
});
|
|
23
22
|
it("/second/testSession", (done) => {
|
|
24
|
-
chaiObj.request(
|
|
23
|
+
chaiObj.request(testAddr).get("/second/testSession").end((err, res) => {
|
|
25
24
|
chaiObj.assert.equal(res.text, "testForSession: 1");
|
|
26
25
|
done();
|
|
27
26
|
});
|
|
28
27
|
});
|
|
29
28
|
it("/upload", (done) => {
|
|
30
29
|
const uploadfile = "./app/static/k.jpg";
|
|
31
|
-
chaiObj.request(
|
|
30
|
+
chaiObj.request(testAddr).post("/upload")
|
|
32
31
|
.set('Content-Type', 'multipart/form-data')
|
|
33
32
|
.attach("file", uploadfile)
|
|
34
33
|
.end((err, res) => {
|
|
@@ -39,7 +38,7 @@ describe("Test Sencond Page", () => {
|
|
|
39
38
|
it("/form", (done) => {
|
|
40
39
|
const token = jwttoken.sign({ foo: 'bar' }, 'shhhhhhared-secret');
|
|
41
40
|
const fileContents = fs.readFileSync("./app/src/views/upload.html", "utf8");
|
|
42
|
-
chaiObj.request(
|
|
41
|
+
chaiObj.request(testAddr).post("/form")
|
|
43
42
|
.set({ "Authorization": `Bearer ${token}` })
|
|
44
43
|
.end((err, res) => {
|
|
45
44
|
chaiObj.assert.equal(res.text, fileContents);
|