vona-module-test-vona 5.0.39 → 5.0.41

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 (118) hide show
  1. package/dist/.metadata/index.d.ts +12 -1
  2. package/dist/index.js +239 -128
  3. package/dist/service/order.d.ts +4 -0
  4. package/dist/service/post.d.ts +2 -0
  5. package/package.json +4 -2
  6. package/src/.metadata/index.ts +1741 -0
  7. package/src/.metadata/this.ts +2 -0
  8. package/src/bean/aop.regExp.ts +30 -0
  9. package/src/bean/aop.simple.ts +58 -0
  10. package/src/bean/aopMethod.test.ts +42 -0
  11. package/src/bean/bean.testCtx.ts +55 -0
  12. package/src/bean/broadcast.test.ts +22 -0
  13. package/src/bean/cacheMem.test.ts +7 -0
  14. package/src/bean/cacheRedis.post.ts +10 -0
  15. package/src/bean/cacheRedis.test.ts +7 -0
  16. package/src/bean/event.helloEcho.ts +8 -0
  17. package/src/bean/eventListener.helloEcho.ts +21 -0
  18. package/src/bean/meta.version.ts +81 -0
  19. package/src/bean/queue.test.ts +18 -0
  20. package/src/bean/schedule.test.ts +12 -0
  21. package/src/bean/schedule.test3.ts +12 -0
  22. package/src/bean/summerCache.test.ts +29 -0
  23. package/src/config/config.ts +5 -0
  24. package/src/config/locale/en-us.ts +19 -0
  25. package/src/config/locale/zh-cn.ts +17 -0
  26. package/src/controller/bean.ts +95 -0
  27. package/src/controller/cacheMem.ts +63 -0
  28. package/src/controller/cacheRedis.ts +55 -0
  29. package/src/controller/dtoTest.ts +63 -0
  30. package/src/controller/guardPassport.ts +25 -0
  31. package/src/controller/onion.ts +92 -0
  32. package/src/controller/passport.ts +48 -0
  33. package/src/controller/performAction.ts +18 -0
  34. package/src/controller/queue.ts +25 -0
  35. package/src/controller/summer.ts +125 -0
  36. package/src/controller/tail.ts +32 -0
  37. package/src/controller/transaction.ts +29 -0
  38. package/src/controller/upload.ts +57 -0
  39. package/src/dto/categoryTree.ts +8 -0
  40. package/src/dto/orderCreate.ts +10 -0
  41. package/src/dto/orderResult.ts +9 -0
  42. package/src/dto/orderUpdate.ts +9 -0
  43. package/src/dto/postCreate.ts +9 -0
  44. package/src/dto/profile.ts +14 -0
  45. package/src/dto/roleLazy.ts +15 -0
  46. package/src/dto/user.ts +19 -0
  47. package/src/dto/userCreate.ts +8 -0
  48. package/src/dto/userLazy.ts +18 -0
  49. package/src/dto/userUpdate.ts +8 -0
  50. package/src/entity/category.ts +14 -0
  51. package/src/entity/order.ts +18 -0
  52. package/src/entity/post.ts +17 -0
  53. package/src/entity/postContent.ts +14 -0
  54. package/src/entity/product.ts +24 -0
  55. package/src/entity/role.ts +11 -0
  56. package/src/entity/roleUser.ts +14 -0
  57. package/src/entity/test.ts +18 -0
  58. package/src/entity/user.ts +17 -0
  59. package/src/index.ts +1 -0
  60. package/src/model/category.ts +17 -0
  61. package/src/model/categoryChain.ts +16 -0
  62. package/src/model/order.ts +26 -0
  63. package/src/model/orderStats.ts +27 -0
  64. package/src/model/post.ts +16 -0
  65. package/src/model/postContent.ts +17 -0
  66. package/src/model/product.ts +8 -0
  67. package/src/model/role.ts +15 -0
  68. package/src/model/roleUser.ts +8 -0
  69. package/src/model/test.ts +8 -0
  70. package/src/model/testDynamicTable.ts +21 -0
  71. package/src/model/user.ts +21 -0
  72. package/src/model/userStats.ts +15 -0
  73. package/src/model/userStatsGroup.ts +15 -0
  74. package/src/service/aopMethod.ts +38 -0
  75. package/src/service/caching.ts +75 -0
  76. package/src/service/order.ts +65 -0
  77. package/src/service/post.ts +219 -0
  78. package/src/service/test.ts +9 -0
  79. package/src/service/testApp.ts +13 -0
  80. package/src/service/testClass.ts +15 -0
  81. package/src/service/testData.ts +67 -0
  82. package/src/service/transaction.ts +20 -0
  83. package/test/aopMethod.test.ts +21 -0
  84. package/test/authSimple.test.ts +45 -0
  85. package/test/bean.test.ts +16 -0
  86. package/test/broadcast.test.ts +17 -0
  87. package/test/cache/cacheMem.test.ts +10 -0
  88. package/test/cache/cacheRedis.test.ts +10 -0
  89. package/test/cache/caching.test.ts +58 -0
  90. package/test/cache/summer.test.ts +10 -0
  91. package/test/database/database.test.ts +127 -0
  92. package/test/database/dtoAggregate.test.ts +44 -0
  93. package/test/database/dtoGet.test.ts +61 -0
  94. package/test/database/dtoGroup.test.ts +44 -0
  95. package/test/database/dtoLazy.test.ts +45 -0
  96. package/test/database/dtoMutate.test.ts +56 -0
  97. package/test/database/modelAggregate.test.ts +197 -0
  98. package/test/database/modelCache.test.ts +37 -0
  99. package/test/database/modelGeneral.test.ts +18 -0
  100. package/test/database/modelGroup.test.ts +211 -0
  101. package/test/database/modelRelations.test.ts +203 -0
  102. package/test/database/modelRelationsJoins.test.ts +39 -0
  103. package/test/database/modelRelationsMutate.test.ts +354 -0
  104. package/test/database/modelWhere.test.ts +138 -0
  105. package/test/database/orm.test.ts +22 -0
  106. package/test/database/transaction.test.ts +142 -0
  107. package/test/event.test.ts +14 -0
  108. package/test/guardPassport.test.ts +44 -0
  109. package/test/jwt.test.ts +27 -0
  110. package/test/locale.test.ts +51 -0
  111. package/test/passport.test.ts +57 -0
  112. package/test/queue.test.ts +11 -0
  113. package/test/tail.test.ts +21 -0
  114. package/test/upload.test.ts +58 -0
  115. package/test/utils/cabloyUtils.test.ts +22 -0
  116. package/test/utils/celjs.test.ts +26 -0
  117. package/test/utils/mappedTypes.test.ts +65 -0
  118. package/test/utils/performAction.test.ts +28 -0
@@ -0,0 +1,44 @@
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('guardPassport.test.ts', () => {
7
+ it('action:guardPassport:userName', async () => {
8
+ await app.bean.executor.mockCtx(async () => {
9
+ const jwt = await app.bean.passport.signinMock();
10
+ const res = await app.bean.executor.performAction('get', '/test/vona/guardPassport/testUserName', {
11
+ innerAccess: false,
12
+ authToken: jwt.accessToken,
13
+ });
14
+ assert.equal(res, undefined);
15
+ const [_, err] = await catchError(() => {
16
+ return app.bean.executor.performAction('get', '/test/vona/guardPassport/testUserNameFail', {
17
+ innerAccess: false,
18
+ authToken: jwt.accessToken,
19
+ });
20
+ });
21
+ assert.equal(err?.code, 403);
22
+ await app.bean.passport.signout();
23
+ });
24
+ });
25
+
26
+ it('action:guardPassport:roleName', async () => {
27
+ await app.bean.executor.mockCtx(async () => {
28
+ const jwt = await app.bean.passport.signinMock();
29
+ const res = await app.bean.executor.performAction('get', '/test/vona/guardPassport/testRoleName', {
30
+ innerAccess: false,
31
+ authToken: jwt.accessToken,
32
+ });
33
+ assert.equal(res, undefined);
34
+ const [_, err] = await catchError(() => {
35
+ return app.bean.executor.performAction('get', '/test/vona/guardPassport/testRoleNameFail', {
36
+ innerAccess: false,
37
+ authToken: jwt.accessToken,
38
+ });
39
+ });
40
+ assert.equal(err?.code, 403);
41
+ await app.bean.passport.signout();
42
+ });
43
+ });
44
+ });
@@ -0,0 +1,27 @@
1
+ import type { IPayloadDataBase } from 'vona-module-a-jwt';
2
+ import assert from 'node:assert';
3
+ import { describe, it } from 'node:test';
4
+ import { catchError } from '@cabloy/utils';
5
+ import { app } from 'vona-mock';
6
+
7
+ describe('jwt.test.ts', () => {
8
+ it('action:jwt', async () => {
9
+ await app.bean.executor.mockCtx(async () => {
10
+ // sign
11
+ const payloadData: IPayloadDataBase = { userId: 1, authId: 1 };
12
+ const token = await app.bean.jwt.get('access').sign(payloadData);
13
+ assert.equal(token.split('.').length, 3);
14
+ // verify
15
+ const [payloadDataVerified1] = await catchError(async () => {
16
+ return await app.bean.jwt.get('refresh').verify(token);
17
+ });
18
+ assert.equal(payloadDataVerified1, undefined);
19
+ // verify
20
+ const payloadDataVerified2 = await app.bean.jwt.get('access').verify(token);
21
+ assert.deepEqual(payloadData, payloadDataVerified2);
22
+ // create jwt token
23
+ const jwtToken = await app.bean.jwt.create(payloadData);
24
+ assert.equal(!!jwtToken.accessToken, true);
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,51 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { app, mockModuleInfo } from 'vona-mock';
4
+ import { __ThisModule__ } from '../src/.metadata/this.ts';
5
+
6
+ describe('locale.test.ts', () => {
7
+ it('action:locale', async () => {
8
+ const moduleInfo = mockModuleInfo();
9
+ assert.equal(moduleInfo.relativeName, __ThisModule__);
10
+ await app.bean.executor.mockCtx(
11
+ async () => {
12
+ const ctx = app.ctx;
13
+ // ctx.locale
14
+ assert.equal(ctx.locale, 'zh-cn');
15
+ // getText
16
+ assert.equal(
17
+ app.meta.locale.getText(false, moduleInfo.relativeName, ctx.locale, 'TestHelloWorld'),
18
+ '您好,世界',
19
+ );
20
+ assert.equal(app.meta.locale.getText(false, undefined, ctx.locale, 'test-vona::TestHelloWorld'), '您好,世界');
21
+ // scope locale
22
+ const scopeTest = app.bean.scope('test-vona');
23
+ assert.equal(scopeTest.locale.TestHelloWorld(), '您好,世界');
24
+ },
25
+ { locale: 'zh-cn' },
26
+ );
27
+ });
28
+
29
+ it('action:locale:plurals', async () => {
30
+ await app.bean.executor.mockCtx(async () => {
31
+ // scope
32
+ const scopeTest = app.bean.scope('test-vona');
33
+ // english
34
+ assert.equal(scopeTest.locale.TestApples.locale('en-us', 0), 'no apples');
35
+ assert.equal(scopeTest.locale.TestApples.locale('en-us', 1), 'one apple');
36
+ assert.equal(scopeTest.locale.TestApples.locale('en-us', 2), '2 apples');
37
+ // chinese
38
+ assert.equal(scopeTest.locale.TestApples.locale('zh-cn', 0), '没有苹果');
39
+ assert.equal(scopeTest.locale.TestApples.locale('zh-cn', 1), '1个苹果');
40
+ assert.equal(scopeTest.locale.TestApples.locale('zh-cn', 2), '2个苹果');
41
+ // english
42
+ assert.equal(scopeTest.locale.TestNameApples_.locale('en-us', 'Mike', 0), 'Mike has no apples');
43
+ assert.equal(scopeTest.locale.TestNameApples_.locale('en-us', 'Mike', 1), 'Mike has one apple');
44
+ assert.equal(scopeTest.locale.TestNameApples_.locale('en-us', 'Mike', 2), 'Mike has 2 apples');
45
+ // chinese
46
+ assert.equal(scopeTest.locale.TestNameApples_.locale('zh-cn', 'Mike', 0), 'Mike没有苹果');
47
+ assert.equal(scopeTest.locale.TestNameApples_.locale('zh-cn', 'Mike', 1), 'Mike有1个苹果');
48
+ assert.equal(scopeTest.locale.TestNameApples_.locale('zh-cn', 'Mike', 2), 'Mike有2个苹果');
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,57 @@
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('passport.test.ts', () => {
7
+ it('action:passport:simple', async () => {
8
+ await app.bean.executor.mockCtx(async () => {
9
+ await app.bean.passport.signinMock();
10
+ assert.equal(app.bean.passport.isAuthenticated, true);
11
+ await app.bean.executor.performAction('get', '/test/vona/passport/echo/:name', { params: { name: 'admin' } });
12
+ await app.bean.passport.signout();
13
+ assert.equal(app.bean.passport.isAuthenticated, false);
14
+ });
15
+ });
16
+
17
+ it('action:passport:full', async () => {
18
+ await app.bean.executor.mockCtx(async () => {
19
+ // login
20
+ const jwt = await app.bean.executor.performAction('post', '/test/vona/passport/login', {
21
+ body: {
22
+ name: 'admin',
23
+ },
24
+ });
25
+ assert.equal(!!jwt?.accessToken, true);
26
+ // isAuthenticated
27
+ let isAuthenticated = await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated');
28
+ assert.equal(isAuthenticated, true);
29
+ // isAuthenticated: isolate
30
+ const [isAuthenticated2, _err] = await catchError(async () => {
31
+ return await app.bean.executor.newCtxIsolate(async () => {
32
+ return await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated');
33
+ });
34
+ });
35
+ assert.equal(isAuthenticated2, undefined);
36
+ // isAuthenticated: isolate + header
37
+ isAuthenticated = await app.bean.executor.newCtxIsolate(async () => {
38
+ return await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated', { authToken: jwt.accessToken });
39
+ });
40
+ assert.equal(isAuthenticated, true);
41
+ // refresh
42
+ const jwtNew = await app.bean.executor.performAction('post', '/test/vona/passport/refresh', {
43
+ body: {
44
+ refreshToken: jwt.refreshToken,
45
+ },
46
+ });
47
+ assert.notEqual(jwt?.accessToken, jwtNew.accessToken);
48
+ // logout
49
+ await app.bean.executor.performAction('post', '/test/vona/passport/logout');
50
+ // isAuthenticated: isolate + header
51
+ const [isAuthenticated3] = await catchError(async () => {
52
+ return await app.bean.executor.performAction('get', '/test/vona/passport/isAuthenticated');
53
+ });
54
+ assert.equal(isAuthenticated3, undefined);
55
+ });
56
+ });
57
+ });
@@ -0,0 +1,11 @@
1
+ import { describe, it } from 'node:test';
2
+ import { app } from 'vona-mock';
3
+
4
+ describe('queue.test.ts', () => {
5
+ it('action:queue', async () => {
6
+ await app.bean.executor.mockCtx(async () => {
7
+ await app.bean.executor.performAction('post', '/test/vona/queue/pushAsync');
8
+ await app.bean.executor.performAction('post', '/test/vona/queue/push');
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,21 @@
1
+ import { describe, it } from 'node:test';
2
+ import { cast } from 'vona';
3
+ import { app } from 'vona-mock';
4
+
5
+ describe('tail.test.ts', () => {
6
+ it('action:tail', async () => {
7
+ await app.bean.executor.mockCtx(async () => {
8
+ cast(app.ctx)._tail_test_caller = 1;
9
+ await app.bean.executor.performAction('post', '/test/vona/tail');
10
+ });
11
+ });
12
+
13
+ it('action:tail:transaction', async () => {
14
+ await app.bean.executor.mockCtx(async () => {
15
+ cast(app.ctx)._tail_test_als_caller = 1;
16
+ await app.ctx.db.transaction.begin(async () => {
17
+ await app.bean.executor.performAction('post', '/test/vona/tail');
18
+ });
19
+ });
20
+ });
21
+ });
@@ -0,0 +1,58 @@
1
+ import assert from 'node:assert';
2
+ import { Blob } from 'node:buffer';
3
+ import { describe, it } from 'node:test';
4
+ import { app } from 'vona-mock';
5
+ import { $apiPath } from 'vona-module-a-web';
6
+
7
+ describe('upload.test.ts', () => {
8
+ it('action:upload:fields', async () => {
9
+ await app.bean.executor.mockCtx(async () => {
10
+ const formData = new FormData();
11
+ formData.append('name', 'zhennann');
12
+ formData.append('checkes', 'apple');
13
+ formData.append('checkes', 'pear');
14
+ // formData.append('checkes', ['apple', 'pear']);
15
+ const url = app.util.getAbsoluteUrlByApiPath($apiPath('/test/vona/upload/fields'));
16
+ const res = await fetch(url, {
17
+ method: 'POST',
18
+ body: formData,
19
+ });
20
+ const data = await res.json();
21
+ assert.equal(data.data.fields.find(item => item.name === 'name')?.value, 'zhennann');
22
+ });
23
+ });
24
+ it('action:upload:file', async () => {
25
+ await app.bean.executor.mockCtx(async () => {
26
+ const formData = new FormData();
27
+ formData.append('name', 'zhennann');
28
+ formData.append('welcome', new (Blob as any)(['hello world!']), 'file-test.txt');
29
+ const url = app.util.getAbsoluteUrlByApiPath($apiPath('/test/vona/upload/file'));
30
+ const res = await fetch(url, {
31
+ method: 'POST',
32
+ body: formData,
33
+ });
34
+ const data = await res.json();
35
+ assert.equal(data.data.fields.find(item => item.name === 'name')?.value, 'zhennann');
36
+ assert.equal(data.data.files.find(item => item.name === 'welcome')?.info.filename, 'file-test.txt');
37
+ });
38
+ });
39
+ it('action:upload:files', async () => {
40
+ await app.bean.executor.mockCtx(async () => {
41
+ const formData = new FormData();
42
+ formData.append('name', 'zhennann');
43
+ formData.append('welcome1', new (Blob as any)(['hello world!'], { type: 'text/plain' }), 'file-test1.txt');
44
+ formData.append('welcome2', new (Blob as any)(['hello world!'], { type: 'text/plain' }), 'file-test2.txt');
45
+ formData.append('images', new (Blob as any)(['hello world!'], { type: 'text/plain' }));
46
+ formData.append('images', new (Blob as any)(['hello world!'], { type: 'text/plain' }));
47
+ const url = app.util.getAbsoluteUrlByApiPath($apiPath('/test/vona/upload/files'));
48
+ const res = await fetch(url, {
49
+ method: 'POST',
50
+ body: formData,
51
+ });
52
+ const data = await res.json();
53
+ assert.equal(data.data.fields.find(item => item.name === 'name')?.value, 'zhennann');
54
+ assert.equal(data.data.files.find(item => item.name === 'welcome1')?.info.filename, 'file-test1.txt');
55
+ assert.equal(data.data.files.find(item => item.name === 'welcome2')?.info.filename, 'file-test2.txt');
56
+ });
57
+ });
58
+ });
@@ -0,0 +1,22 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { getProperty } from '@cabloy/utils';
4
+
5
+ describe('cabloyUtils.test.ts', () => {
6
+ it('action:getProperty', async () => {
7
+ const user = {
8
+ id: 1,
9
+ name: 'tom',
10
+ role: { name: 'admin' },
11
+ books: [
12
+ { name: 'piao' },
13
+ { name: 'flying' },
14
+ ],
15
+ };
16
+ assert.equal(getProperty(user, 'id'), 1);
17
+ assert.equal(getProperty(user, 'role.name'), 'admin');
18
+ assert.equal(getProperty(user, 'role.xx'), undefined);
19
+ assert.equal(getProperty(user, 'role.xx.yy'), undefined);
20
+ assert.equal(getProperty(user, 'books[0].name'), 'piao');
21
+ });
22
+ });
@@ -0,0 +1,26 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { evaluateExpressions } from '@cabloy/utils';
4
+ import { cast } from 'vona';
5
+ import { app } from 'vona-mock';
6
+
7
+ describe('celjs.test.ts', () => {
8
+ it('action:celjs', async () => {
9
+ await app.bean.executor.mockCtx(async () => {
10
+ //
11
+ const beanJwt = app.bean.jwt;
12
+ assert.equal(evaluateExpressions('cel://self.app.config.server.workers', { self: beanJwt, app: cast(beanJwt).app, ctx: cast(beanJwt).ctx }) > 0, true);
13
+ assert.equal(evaluateExpressions('cel://app.config.server.workers', { self: beanJwt, app: cast(beanJwt).app, ctx: cast(beanJwt).ctx }) > 0, true);
14
+ assert.equal(evaluateExpressions('cel://ctx.app.config.server.workers', { self: beanJwt, app: cast(beanJwt).app, ctx: cast(beanJwt).ctx }) > 0, true);
15
+ // map
16
+ assert.deepEqual(evaluateExpressions('cel://{"a": 1, "b": true}'), { a: 1, b: true });
17
+ assert.deepEqual(evaluateExpressions('cel://{"id": 1, "name": "tom"}'), { id: 1, name: 'tom' });
18
+ // array
19
+ assert.deepEqual(evaluateExpressions('cel://concat(1,[2,3],4)'), [1, 2, 3, 4]);
20
+ assert.deepEqual(evaluateExpressions('cel://join(concat(1,[2,3],4),"_")'), '1_2_3_4');
21
+ // +
22
+ assert.equal(evaluateExpressions('cel://1+"a"'), '1a');
23
+ assert.equal(evaluateExpressions('cel://"a"+1'), 'a1');
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,65 @@
1
+ import type { IDecoratorDtoOptions } from 'vona-module-a-web';
2
+ import assert from 'node:assert';
3
+ import { describe, it } from 'node:test';
4
+ import { catchError } from '@cabloy/utils';
5
+ import { $Class, cast } from 'vona';
6
+ import { app } from 'vona-mock';
7
+ import { Api } from 'vona-module-a-openapi';
8
+ import { Dto } from 'vona-module-a-web';
9
+ import { DtoProfile } from '../../src/dto/profile.ts';
10
+ import { DtoUser } from '../../src/dto/user.ts';
11
+
12
+ interface IDtoOptionsUserWithMarried extends IDecoratorDtoOptions {}
13
+
14
+ @Dto<IDtoOptionsUserWithMarried>()
15
+ class DtoUserWithMarried extends $Class.omit(DtoUser, ['married']) {
16
+ @Api.field()
17
+ married: boolean;
18
+ }
19
+
20
+ describe('mappedTypes.test.ts', () => {
21
+ it('action:mappedTypes', async () => {
22
+ await app.bean.executor.mockCtx(async () => {
23
+ const serviceValidator = app.bean.validator;
24
+ const data = { id: 1, name: 'tom', married: true };
25
+ // original
26
+ const [dataNew, err] = await catchError(async () => {
27
+ return await serviceValidator.validate(DtoUser, data, { strict: true });
28
+ });
29
+ assert.deepEqual(dataNew, data, JSON.stringify(err, null, 2));
30
+ // OmitClass
31
+ const [, err2] = await catchError(async () => {
32
+ return await serviceValidator.validate($Class.omit(DtoUser, ['married']), data, { strict: true });
33
+ });
34
+ assert.equal(cast(err2?.message)[0]?.keys[0], 'married');
35
+ // OmitClass and inherit
36
+ const [dataNew3] = await catchError(async () => {
37
+ return await serviceValidator.validate(DtoUserWithMarried, data, { strict: true });
38
+ });
39
+ assert.deepEqual(dataNew3, data);
40
+ // PickClass
41
+ const [, err4] = await catchError(async () => {
42
+ return await serviceValidator.validate($Class.pick(DtoUser, ['id', 'name']), data, { strict: true });
43
+ });
44
+ assert.equal(cast(err4?.message)[0]?.keys[0], 'married');
45
+ // PartialClass
46
+ const [dataNew5] = await catchError(async () => {
47
+ return await serviceValidator.validate($Class.partial(DtoUser), {}, { strict: true });
48
+ });
49
+ assert.deepEqual(dataNew5, {});
50
+ const [dataNew6] = await catchError(async () => {
51
+ return await serviceValidator.validate(
52
+ $Class.partial(DtoUser, ['id', 'name']),
53
+ { married: true },
54
+ { strict: true },
55
+ );
56
+ });
57
+ assert.deepEqual(dataNew6, { married: true });
58
+ // MixinClass
59
+ const [_, err7] = await catchError(async () => {
60
+ return await serviceValidator.validate($Class.mixin(DtoUser, DtoProfile), data, { strict: true });
61
+ });
62
+ assert.equal(cast(err7?.message)[0]?.path[0], 'email');
63
+ });
64
+ });
65
+ });
@@ -0,0 +1,28 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+ import { app, mockUrl } from 'vona-mock';
4
+
5
+ describe('performAction.test.ts', () => {
6
+ it('action:performAction', async () => {
7
+ const result: { id: number; url: string } = await app.bean.executor.mockCtx(async () => {
8
+ return await app.bean.executor.performAction('post', '/test/vona/performAction/echo', {
9
+ body: {
10
+ id: 123,
11
+ },
12
+ });
13
+ });
14
+ assert.equal(result.id, 123);
15
+ assert.equal(result.url, mockUrl('performAction/echo'));
16
+ });
17
+ it('action:performAction:onionsDynamic', async () => {
18
+ const result: { id: number; url: string } = await app.bean.executor.mockCtx(async () => {
19
+ return await app.bean.executor.performAction('post', '/test/vona/performAction/echo', {
20
+ onions: {
21
+ pipe: { 'a-validation:valid': { enable: false } },
22
+ },
23
+ });
24
+ });
25
+ assert.equal(result.id, undefined);
26
+ assert.equal(result.url, mockUrl('performAction/echo'));
27
+ });
28
+ });