vona-module-test-vona 5.0.39 → 5.0.42

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.
Files changed (123) hide show
  1. package/dist/.metadata/index.d.ts +62 -29
  2. package/dist/controller/dtoTest.d.ts +1 -1
  3. package/dist/index.js +401 -158
  4. package/dist/service/category.d.ts +5 -0
  5. package/dist/service/order.d.ts +4 -0
  6. package/dist/service/post.d.ts +4 -2
  7. package/dist/service/user.d.ts +4 -0
  8. package/package.json +4 -2
  9. package/src/.metadata/index.ts +1771 -0
  10. package/src/.metadata/this.ts +2 -0
  11. package/src/bean/aop.regExp.ts +30 -0
  12. package/src/bean/aop.simple.ts +58 -0
  13. package/src/bean/aopMethod.test.ts +42 -0
  14. package/src/bean/bean.testCtx.ts +55 -0
  15. package/src/bean/broadcast.test.ts +22 -0
  16. package/src/bean/cacheMem.test.ts +7 -0
  17. package/src/bean/cacheRedis.post.ts +10 -0
  18. package/src/bean/cacheRedis.test.ts +7 -0
  19. package/src/bean/event.helloEcho.ts +8 -0
  20. package/src/bean/eventListener.helloEcho.ts +21 -0
  21. package/src/bean/meta.version.ts +81 -0
  22. package/src/bean/queue.test.ts +18 -0
  23. package/src/bean/schedule.test.ts +12 -0
  24. package/src/bean/schedule.test3.ts +12 -0
  25. package/src/bean/summerCache.test.ts +29 -0
  26. package/src/config/config.ts +5 -0
  27. package/src/config/locale/en-us.ts +19 -0
  28. package/src/config/locale/zh-cn.ts +17 -0
  29. package/src/controller/bean.ts +95 -0
  30. package/src/controller/cacheMem.ts +63 -0
  31. package/src/controller/cacheRedis.ts +55 -0
  32. package/src/controller/dtoTest.ts +63 -0
  33. package/src/controller/guardPassport.ts +25 -0
  34. package/src/controller/onion.ts +92 -0
  35. package/src/controller/passport.ts +48 -0
  36. package/src/controller/performAction.ts +18 -0
  37. package/src/controller/queue.ts +25 -0
  38. package/src/controller/summer.ts +125 -0
  39. package/src/controller/tail.ts +32 -0
  40. package/src/controller/transaction.ts +29 -0
  41. package/src/controller/upload.ts +57 -0
  42. package/src/dto/categoryTree.ts +8 -0
  43. package/src/dto/orderCreate.ts +10 -0
  44. package/src/dto/orderResult.ts +9 -0
  45. package/src/dto/orderUpdate.ts +9 -0
  46. package/src/dto/postCreate.ts +9 -0
  47. package/src/dto/profile.ts +14 -0
  48. package/src/dto/roleLazy.ts +15 -0
  49. package/src/dto/user.ts +19 -0
  50. package/src/dto/userCreate.ts +8 -0
  51. package/src/dto/userLazy.ts +18 -0
  52. package/src/dto/userUpdate.ts +8 -0
  53. package/src/entity/category.ts +14 -0
  54. package/src/entity/order.ts +18 -0
  55. package/src/entity/post.ts +17 -0
  56. package/src/entity/postContent.ts +14 -0
  57. package/src/entity/product.ts +24 -0
  58. package/src/entity/role.ts +11 -0
  59. package/src/entity/roleUser.ts +14 -0
  60. package/src/entity/test.ts +18 -0
  61. package/src/entity/user.ts +17 -0
  62. package/src/index.ts +1 -0
  63. package/src/model/category.ts +20 -0
  64. package/src/model/categoryChain.ts +16 -0
  65. package/src/model/order.ts +26 -0
  66. package/src/model/orderStats.ts +27 -0
  67. package/src/model/post.ts +16 -0
  68. package/src/model/postContent.ts +17 -0
  69. package/src/model/product.ts +8 -0
  70. package/src/model/role.ts +15 -0
  71. package/src/model/roleUser.ts +8 -0
  72. package/src/model/test.ts +8 -0
  73. package/src/model/testDynamicTable.ts +21 -0
  74. package/src/model/user.ts +21 -0
  75. package/src/model/userStats.ts +15 -0
  76. package/src/model/userStatsGroup.ts +15 -0
  77. package/src/service/aopMethod.ts +38 -0
  78. package/src/service/caching.ts +75 -0
  79. package/src/service/category.ts +72 -0
  80. package/src/service/order.ts +65 -0
  81. package/src/service/post.ts +219 -0
  82. package/src/service/test.ts +9 -0
  83. package/src/service/testApp.ts +13 -0
  84. package/src/service/testClass.ts +15 -0
  85. package/src/service/testData.ts +67 -0
  86. package/src/service/transaction.ts +20 -0
  87. package/src/service/user.ts +68 -0
  88. package/test/aopMethod.test.ts +21 -0
  89. package/test/authSimple.test.ts +45 -0
  90. package/test/bean.test.ts +16 -0
  91. package/test/broadcast.test.ts +17 -0
  92. package/test/cache/cacheMem.test.ts +10 -0
  93. package/test/cache/cacheRedis.test.ts +10 -0
  94. package/test/cache/caching.test.ts +58 -0
  95. package/test/cache/summer.test.ts +10 -0
  96. package/test/database/database.test.ts +127 -0
  97. package/test/database/dtoAggregate.test.ts +44 -0
  98. package/test/database/dtoGet.test.ts +61 -0
  99. package/test/database/dtoGroup.test.ts +44 -0
  100. package/test/database/dtoLazy.test.ts +45 -0
  101. package/test/database/dtoMutate.test.ts +56 -0
  102. package/test/database/modelAggregate.test.ts +197 -0
  103. package/test/database/modelCache.test.ts +37 -0
  104. package/test/database/modelGeneral.test.ts +18 -0
  105. package/test/database/modelGroup.test.ts +211 -0
  106. package/test/database/modelRelations.test.ts +203 -0
  107. package/test/database/modelRelationsJoins.test.ts +39 -0
  108. package/test/database/modelRelationsMutate.test.ts +354 -0
  109. package/test/database/modelWhere.test.ts +138 -0
  110. package/test/database/orm.test.ts +22 -0
  111. package/test/database/transaction.test.ts +142 -0
  112. package/test/event.test.ts +14 -0
  113. package/test/guardPassport.test.ts +44 -0
  114. package/test/jwt.test.ts +27 -0
  115. package/test/locale.test.ts +51 -0
  116. package/test/passport.test.ts +57 -0
  117. package/test/queue.test.ts +11 -0
  118. package/test/tail.test.ts +21 -0
  119. package/test/upload.test.ts +58 -0
  120. package/test/utils/cabloyUtils.test.ts +22 -0
  121. package/test/utils/celjs.test.ts +26 -0
  122. package/test/utils/mappedTypes.test.ts +65 -0
  123. package/test/utils/performAction.test.ts +28 -0
@@ -0,0 +1,72 @@
1
+ import assert from 'node:assert';
2
+ import { BeanBase } from 'vona';
3
+ import { Service } from 'vona-module-a-bean';
4
+
5
+ @Service()
6
+ export class ServiceCategory extends BeanBase {
7
+ async categoryTreeReverse() {
8
+ // create
9
+ const treeCreate = await this.scope.model.category.insert({
10
+ name: 'Category-1',
11
+ children: [
12
+ {
13
+ name: 'Category-1-1',
14
+ children: [
15
+ { name: 'Category-1-1-1' },
16
+ ],
17
+ },
18
+ {
19
+ name: 'Category-1-2',
20
+ },
21
+ ],
22
+ });
23
+ // 'Category-1-1-1'
24
+ const subCategoryId = treeCreate.children?.[0].children?.[0].id;
25
+ // get: reverse
26
+ const subCategory = await this.scope.model.categoryChain.get({
27
+ id: subCategoryId,
28
+ });
29
+ assert.equal(subCategory?.parent?.parent?.id, treeCreate.id);
30
+ }
31
+
32
+ async categoryTree() {
33
+ // create
34
+ const treeCreate = await this.scope.model.category.insert({
35
+ name: 'Category-1',
36
+ children: [
37
+ {
38
+ name: 'Category-1-1',
39
+ children: [
40
+ { name: 'Category-1-1-1' },
41
+ ],
42
+ },
43
+ {
44
+ name: 'Category-1-2',
45
+ },
46
+ ],
47
+ });
48
+ // get
49
+ const tree = await this.scope.model.category.get({
50
+ id: treeCreate.id,
51
+ });
52
+ assert.equal(tree?.children.length, 2);
53
+ assert.equal(tree?.children[0].children.length, 1);
54
+ // update
55
+ await this.scope.model.category.update({
56
+ id: treeCreate.id,
57
+ name: 'Category-1-Update',
58
+ children: [
59
+ // create
60
+ { name: 'Category-1-3' },
61
+ // update
62
+ { id: treeCreate.children?.[0].id, name: 'Category-1-1-Update' },
63
+ // delete
64
+ { id: treeCreate.children?.[1].id, deleted: true },
65
+ ],
66
+ });
67
+ // delete
68
+ await this.scope.model.category.delete({
69
+ id: treeCreate.id,
70
+ });
71
+ }
72
+ }
@@ -0,0 +1,65 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+
4
+ @Service()
5
+ export class ServiceOrder extends BeanBase {
6
+ async relationHasMany() {
7
+ // insert
8
+ const orderCreate = await this.scope.model.order.insert(
9
+ {
10
+ orderNo: 'Order001',
11
+ products: [
12
+ { name: 'Apple' },
13
+ { name: 'Pear' },
14
+ ],
15
+ },
16
+ {
17
+ include: {
18
+ products: true,
19
+ },
20
+ },
21
+ );
22
+ // get
23
+ await this.scope.model.order.get(
24
+ {
25
+ id: orderCreate.id,
26
+ },
27
+ {
28
+ include: {
29
+ products: true,
30
+ },
31
+ },
32
+ );
33
+ // update
34
+ await this.scope.model.order.update(
35
+ {
36
+ id: orderCreate.id,
37
+ orderNo: 'Order001-Update',
38
+ products: [
39
+ // create product: Peach
40
+ { name: 'Peach' },
41
+ // update product: Apple
42
+ { id: orderCreate.products?.[0].id, name: 'Apple-Update' },
43
+ // delete product: Pear
44
+ { id: orderCreate.products?.[1].id, deleted: true },
45
+ ],
46
+ },
47
+ {
48
+ include: {
49
+ products: true,
50
+ },
51
+ },
52
+ );
53
+ // delete
54
+ await this.scope.model.order.delete(
55
+ {
56
+ id: orderCreate.id,
57
+ },
58
+ {
59
+ include: {
60
+ products: true,
61
+ },
62
+ },
63
+ );
64
+ }
65
+ }
@@ -0,0 +1,219 @@
1
+ import type { TableIdentity } from 'table-identity';
2
+ import { BeanBase } from 'vona';
3
+ import { Service } from 'vona-module-a-bean';
4
+ import { Database } from 'vona-module-a-orm';
5
+
6
+ @Service()
7
+ export class ServicePost extends BeanBase {
8
+ async relationBelongsTo() {
9
+ const postContent = await this.scope.model.postContent.select({
10
+ include: {
11
+ post: true,
12
+ },
13
+ });
14
+ console.log(postContent[0]?.post?.title);
15
+ }
16
+
17
+ async relationHasOne() {
18
+ // insert
19
+ const postCreate = await this.scope.model.post.insert(
20
+ {
21
+ title: 'Post001',
22
+ postContent: {
23
+ content: 'This is a post',
24
+ },
25
+ },
26
+ {
27
+ include: {
28
+ postContent: true,
29
+ },
30
+ },
31
+ );
32
+ // get
33
+ const post = await this.scope.model.post.get(
34
+ {
35
+ id: postCreate.id,
36
+ },
37
+ {
38
+ include: {
39
+ postContent: true,
40
+ },
41
+ },
42
+ );
43
+ // update
44
+ await this.scope.model.post.update(
45
+ {
46
+ id: postCreate.id,
47
+ title: 'Post001-Update',
48
+ postContent: {
49
+ content: 'This is a post-changed',
50
+ },
51
+ },
52
+ {
53
+ include: {
54
+ postContent: true,
55
+ },
56
+ },
57
+ );
58
+ // delete
59
+ await this.scope.model.post.delete(
60
+ {
61
+ id: postCreate.id,
62
+ },
63
+ {
64
+ include: {
65
+ postContent: true,
66
+ },
67
+ },
68
+ );
69
+ console.log(post?.postContent?.id);
70
+ }
71
+
72
+ @Database.transaction()
73
+ async transaction() {
74
+ // insert
75
+ const post = await this.scope.model.post.insert({
76
+ title: 'Post001',
77
+ });
78
+ // cache
79
+ await this.scope.cacheRedis.post.set(post, post.id);
80
+ }
81
+
82
+ async transactionManually() {
83
+ const db = this.bean.database.getDb({ clientName: 'default' });
84
+ await db.transaction.begin(async () => {
85
+ const modelPost = this.scope.model.post.newInstance(db);
86
+ const post = await modelPost.insert({ title: 'Post001' });
87
+ await this.scope.cacheRedis.post.set(post, post.id, { db });
88
+ });
89
+ }
90
+
91
+ async create() {
92
+ const post = await this.scope.model.post.insert({
93
+ title: 'Post001',
94
+ });
95
+ // console.log(post.id);
96
+ return post;
97
+ }
98
+
99
+ async createBulk() {
100
+ const posts = await this.scope.model.post.insertBulk([
101
+ { title: 'Post001' },
102
+ { title: 'Post002' },
103
+ ]);
104
+ // console.log(posts[0].id, posts[1].id);
105
+ return posts;
106
+ }
107
+
108
+ async update() {
109
+ const post = await this.scope.model.post.update({
110
+ id: 1,
111
+ title: 'Post001-Update',
112
+ });
113
+ return post;
114
+ }
115
+
116
+ async update2() {
117
+ const post = await this.scope.model.post.update(
118
+ {
119
+ title: 'Post001-Update',
120
+ },
121
+ {
122
+ where: {
123
+ title: { _startsWith_: 'Post001' },
124
+ },
125
+ },
126
+ );
127
+ return post;
128
+ }
129
+
130
+ async updateBulk() {
131
+ const posts = await this.scope.model.post.updateBulk([
132
+ { id: 1, title: 'Post001-Update' },
133
+ { id: 2, title: 'Post002-Update' },
134
+ ]);
135
+ return posts;
136
+ }
137
+
138
+ async delete() {
139
+ await this.scope.model.post.delete({
140
+ id: 1,
141
+ });
142
+ }
143
+
144
+ async delete2() {
145
+ await this.scope.model.post.delete({
146
+ title: {
147
+ _startsWith_: 'Post',
148
+ },
149
+ });
150
+ }
151
+
152
+ async deleteBulk() {
153
+ await this.scope.model.post.deleteBulk([1, 2]);
154
+ }
155
+
156
+ async mutate() {
157
+ // insert
158
+ const post = await this.scope.model.post.mutate({
159
+ title: 'Post001',
160
+ });
161
+ // update
162
+ await this.scope.model.post.mutate({
163
+ id: post.id,
164
+ title: 'Post001-Update',
165
+ });
166
+ // delete
167
+ await this.scope.model.post.mutate({
168
+ id: post.id,
169
+ deleted: true,
170
+ });
171
+ }
172
+
173
+ async mutateBulk() {
174
+ await this.scope.model.post.mutateBulk([
175
+ // insert
176
+ { title: 'Post003' },
177
+ // update
178
+ { id: 1, title: 'Post001-Update' },
179
+ // delete
180
+ { id: 2, deleted: true },
181
+ ]);
182
+ }
183
+
184
+ async select() {
185
+ return await this.scope.model.post.select({
186
+ where: {
187
+ stars: '_skip_',
188
+ },
189
+ });
190
+ }
191
+
192
+ async select2() {
193
+ return await this.scope.model.post.select({
194
+ columns: ['id', 'title', 'userId'],
195
+ where: {
196
+ 'id': { _gt_: 1 },
197
+ 'testVonaUser.id': 1,
198
+ },
199
+ joins: [['innerJoin', 'testVonaUser', ['userId', 'testVonaUser.id']]],
200
+ offset: 0,
201
+ limit: 20,
202
+ orders: [['createdAt', 'desc']],
203
+ }, {
204
+ disableDeleted: false,
205
+ }, 'test-vona:user');
206
+ }
207
+
208
+ async get(id: TableIdentity) {
209
+ return await this.scope.model.post.get({ id });
210
+ }
211
+
212
+ async mget(ids: TableIdentity[]) {
213
+ return await this.scope.model.post.mget(ids);
214
+ }
215
+
216
+ async count() {
217
+ return await this.scope.model.post.count();
218
+ }
219
+ }
@@ -0,0 +1,9 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+
4
+ @Service()
5
+ export class ServiceTest extends BeanBase {
6
+ get name() {
7
+ return 'serviceTest';
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+
4
+ @Service()
5
+ export class ServiceTestApp extends BeanBase {
6
+ actionSync({ a, b }: any) {
7
+ return a + b;
8
+ }
9
+
10
+ async actionAsync({ a, b }: any) {
11
+ return Promise.resolve(a + b);
12
+ }
13
+ }
@@ -0,0 +1,15 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+
4
+ class ClassBeanBase extends BeanBase {
5
+ actionSync({ a, b }: any) {
6
+ return a + b;
7
+ }
8
+ }
9
+
10
+ @Service()
11
+ export class ServiceTestClass extends ClassBeanBase {
12
+ async actionAsync({ a, b }: any) {
13
+ return Promise.resolve(a + b);
14
+ }
15
+ }
@@ -0,0 +1,67 @@
1
+ import type { EntityRole } from 'vona-module-home-user';
2
+ import type { EntityPost } from '../entity/post.ts';
3
+ import type { EntityPostContent } from '../entity/postContent.ts';
4
+ import type { EntityUser } from '../entity/user.ts';
5
+ import { BeanBase } from 'vona';
6
+ import { Service } from 'vona-module-a-bean';
7
+
8
+ export interface ITestData {
9
+ userTom: EntityUser;
10
+ userJimmy: EntityUser;
11
+ roleFamily: EntityRole;
12
+ roleFriend: EntityRole;
13
+ postApple: EntityPost;
14
+ postPear: EntityPost;
15
+ postContentApple: EntityPostContent;
16
+ }
17
+
18
+ @Service()
19
+ export class ServiceTestData extends BeanBase {
20
+ async create(prefix: string): Promise<ITestData> {
21
+ const scopeTest = this.scope;
22
+ const userTom = await scopeTest.model.user.insert({ name: `${prefix}:tom` });
23
+ const userJimmy = await scopeTest.model.user.insert({ name: `${prefix}:jimmy` });
24
+ const roleFamily = await scopeTest.model.role.insert({ name: `${prefix}:family` });
25
+ const roleFriend = await scopeTest.model.role.insert({ name: `${prefix}:friend` });
26
+ await scopeTest.model.roleUser.insertBulk([
27
+ { userId: userTom.id, roleId: roleFamily.id },
28
+ { userId: userTom.id, roleId: roleFriend.id },
29
+ { userId: userJimmy.id, roleId: roleFamily.id },
30
+ ]);
31
+ const postApple = await scopeTest.model.post.insert({ title: `${prefix}:postApple`, userId: userTom.id });
32
+ const postPear = await scopeTest.model.post.insert({ title: `${prefix}:postPear`, userId: userTom.id });
33
+ const postContentApple = await scopeTest.model.postContent.insert({ content: `${prefix}:postContentApple`, postId: postApple.id });
34
+ // ok
35
+ return {
36
+ userTom,
37
+ userJimmy,
38
+ roleFamily,
39
+ roleFriend,
40
+ postApple,
41
+ postPear,
42
+ postContentApple,
43
+ };
44
+ }
45
+
46
+ async drop(data: ITestData) {
47
+ const {
48
+ userTom,
49
+ userJimmy,
50
+ roleFamily,
51
+ roleFriend,
52
+ postApple,
53
+ postPear,
54
+ postContentApple,
55
+ } = data;
56
+ const scopeTest = this.scope;
57
+ await scopeTest.model.postContent.delete({ id: postContentApple.id });
58
+ await scopeTest.model.post.delete({ id: postApple.id });
59
+ await scopeTest.model.post.delete({ id: postPear.id });
60
+ await scopeTest.model.roleUser.delete({ userId: userTom.id });
61
+ await scopeTest.model.roleUser.delete({ userId: userJimmy.id });
62
+ await scopeTest.model.role.delete({ id: roleFamily.id });
63
+ await scopeTest.model.role.delete({ id: roleFriend.id });
64
+ await scopeTest.model.user.delete({ id: userTom.id });
65
+ await scopeTest.model.user.delete({ id: userJimmy.id });
66
+ }
67
+ }
@@ -0,0 +1,20 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+ import { Database } from 'vona-module-a-orm';
4
+
5
+ const tableNameFail = '__tempTransactionFail';
6
+ const tableNameSuccess = '__tempTransactionSuccess';
7
+
8
+ @Service()
9
+ export class ServiceTransaction extends BeanBase {
10
+ @Database.transaction()
11
+ async fail(item: object) {
12
+ await this.bean.model.update(`${tableNameFail}` as any, item);
13
+ await this.bean.model.update(`${tableNameFail}error` as any, item);
14
+ }
15
+
16
+ @Database.transaction()
17
+ async success(item: object) {
18
+ await this.bean.model.update(tableNameSuccess as any, item);
19
+ }
20
+ }
@@ -0,0 +1,68 @@
1
+ import { BeanBase } from 'vona';
2
+ import { Service } from 'vona-module-a-bean';
3
+
4
+ @Service()
5
+ export class ServiceUser extends BeanBase {
6
+ async relationBelongsToMany() {
7
+ // insert: roles
8
+ const roles = await this.scope.model.role.insertBulk([
9
+ { name: 'role-family' },
10
+ { name: 'role-friend' },
11
+ ]);
12
+ const roleIdFamily = roles[0].id;
13
+ const roleIdFriend = roles[1].id;
14
+ // insert: user
15
+ const userCreate = await this.scope.model.user.insert(
16
+ {
17
+ name: 'Tom',
18
+ roles: [{
19
+ id: roleIdFamily,
20
+ }],
21
+ },
22
+ {
23
+ include: {
24
+ roles: true,
25
+ },
26
+ },
27
+ );
28
+ // get: user
29
+ await this.scope.model.user.get(
30
+ {
31
+ id: userCreate.id,
32
+ },
33
+ {
34
+ include: {
35
+ roles: true,
36
+ },
37
+ },
38
+ );
39
+ // update: user
40
+ await this.scope.model.user.update(
41
+ {
42
+ id: userCreate.id,
43
+ roles: [
44
+ // delete
45
+ { id: roleIdFamily, deleted: true },
46
+ // insert
47
+ { id: roleIdFriend },
48
+ ],
49
+ },
50
+ {
51
+ include: {
52
+ roles: true,
53
+ },
54
+ },
55
+ );
56
+ // delete: user
57
+ await this.scope.model.user.delete(
58
+ {
59
+ id: userCreate.id,
60
+ },
61
+ {
62
+ include: {
63
+ roles: true,
64
+ },
65
+ },
66
+ );
67
+ }
68
+ }
@@ -0,0 +1,21 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { app } from 'vona-mock';
4
+
5
+ describe('aopMethod.test.ts', () => {
6
+ it('action:aopMethod', async () => {
7
+ await app.bean.executor.mockCtx(async () => {
8
+ // scope
9
+ const scopeTest = app.bean.scope('test-vona');
10
+ let result = scopeTest.service.aopMethod.testSyncBase();
11
+ assert.equal(result, '-+hello+-');
12
+ result = scopeTest.service.aopMethod.testSync();
13
+ assert.equal(result, '-+hello+-');
14
+ result = await scopeTest.service.aopMethod.testAsync();
15
+ assert.equal(result, '-+hello+-');
16
+ scopeTest.service.aopMethod.name = '-+vona+-';
17
+ result = scopeTest.service.aopMethod.name;
18
+ assert.equal(result, '-+vona+-');
19
+ });
20
+ });
21
+ });
@@ -0,0 +1,45 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { catchError } from '@cabloy/utils';
4
+ import { app } from 'vona-mock';
5
+
6
+ describe('authSimple.test.ts', () => {
7
+ it('action:passwordHash', async () => {
8
+ const scope = app.bean.scope('a-authsimple');
9
+ const password = '12344##1xxaasDFQ,.$';
10
+ const hash = await scope.service.authSimple.calcPasswordHash(password);
11
+ let verified = await scope.service.authSimple.verifyPasswordHash(password, hash);
12
+ assert.equal(verified, true);
13
+ verified = await scope.service.authSimple.verifyPasswordHash(`${password}failed`, hash);
14
+ assert.equal(verified, false);
15
+ });
16
+
17
+ it('action:authSimple', async () => {
18
+ await app.bean.executor.mockCtx(async () => {
19
+ // login
20
+ const jwt = await app.bean.auth.authenticate('a-authsimple:simple', {
21
+ clientName: 'default',
22
+ clientOptions: { username: 'admin', password: '123456' },
23
+ });
24
+ assert.equal(!!jwt?.accessToken, true);
25
+ // isAuthenticated: isolate
26
+ const [isAuthenticated2, _err] = await catchError(async () => {
27
+ return await app.bean.executor.newCtxIsolate(async () => {
28
+ return await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated');
29
+ });
30
+ });
31
+ assert.equal(isAuthenticated2, undefined);
32
+ // isAuthenticated: isolate + header
33
+ const isAuthenticated = await app.bean.executor.newCtxIsolate(async () => {
34
+ return await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated', { authToken: jwt?.accessToken });
35
+ });
36
+ assert.equal(isAuthenticated, true);
37
+ // login again
38
+ const jwt2 = await app.bean.authSimple.authenticate(
39
+ { username: 'admin', password: '123456' },
40
+ 'default',
41
+ );
42
+ assert.equal(!!jwt2?.accessToken, true);
43
+ });
44
+ });
45
+ });
@@ -0,0 +1,16 @@
1
+ import { describe, it } from 'node:test';
2
+ import { app } from 'vona-mock';
3
+
4
+ describe('bean.test.ts', () => {
5
+ it('action:bean', async () => {
6
+ await app.bean.executor.mockCtx(async () => {
7
+ await app.bean.executor.performAction('get', '/test/vona/bean/test');
8
+ });
9
+ });
10
+
11
+ it('action:service', async () => {
12
+ await app.bean.executor.mockCtx(async () => {
13
+ await app.bean.executor.performAction('get', '/test/vona/bean/service');
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,17 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { app } from 'vona-mock';
4
+
5
+ describe('broadcast.test.ts', () => {
6
+ it('action:broadcast', async () => {
7
+ await app.bean.executor.mockCtx(async () => {
8
+ app.bean.scope('test-vona').broadcast.test.emit(
9
+ { message: 'hello' },
10
+ {
11
+ locale: 'zh-cn',
12
+ },
13
+ );
14
+ assert.equal(app.ctx.instanceName, '');
15
+ });
16
+ });
17
+ });
@@ -0,0 +1,10 @@
1
+ import { describe, it } from 'node:test';
2
+ import { app } from 'vona-mock';
3
+
4
+ describe('cacheMem.test.ts', () => {
5
+ it('action:cacheMem', async () => {
6
+ await app.bean.executor.mockCtx(async () => {
7
+ await app.bean.executor.performAction('post', '/test/vona/cacheMem');
8
+ });
9
+ });
10
+ });
@@ -0,0 +1,10 @@
1
+ import { describe, it } from 'node:test';
2
+ import { app } from 'vona-mock';
3
+
4
+ describe('cacheRedis.test.ts', () => {
5
+ it('action:cacheRedis', async () => {
6
+ await app.bean.executor.mockCtx(async () => {
7
+ await app.bean.executor.performAction('post', '/test/vona/cacheRedis');
8
+ });
9
+ });
10
+ });