vona-module-test-vona 5.0.45 → 5.0.47

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.
@@ -8,54 +8,50 @@ import { ModelPost, ModelPostContent, ModelRole, ModelRoleUser, ModelUser } from
8
8
  describe('dtoGet.test.ts', () => {
9
9
  it('action:dtoGet', async () => {
10
10
  await app.bean.executor.mockCtx(async () => {
11
- await app.bean.executor.mockCtx(async () => {
12
- const DtoPostNew = $Dto.get(ModelPost, {
13
- columns: ['id', 'title', 'userId'],
14
- include: {
15
- postContent: {
16
- columns: ['id', 'content'],
17
- include: {
18
- post: { include: { user: { columns: ['id'] } } },
19
- },
20
- with: {
21
- post3: $relationDynamic.belongsTo(() => ModelPostContent, () => ModelPost, 'postId', {
22
- include: {
23
- postContent: true,
24
- },
25
- }),
26
- },
11
+ const DtoPostNew = $Dto.get(ModelPost, {
12
+ columns: ['id', 'title', 'userId'],
13
+ include: {
14
+ postContent: {
15
+ columns: ['id', 'content'],
16
+ include: {
17
+ post: { include: { user: { columns: ['id'] } } },
18
+ },
19
+ with: {
20
+ post3: $relationDynamic.belongsTo(() => ModelPostContent, () => ModelPost, 'postId', {
21
+ include: {
22
+ postContent: true,
23
+ },
24
+ }),
27
25
  },
28
26
  },
29
- with: {
30
- user3: $relationDynamic.belongsTo(ModelPost, () => ModelUser, 'userId', {
31
- include: { posts: true },
32
- with: { roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId') },
33
- columns: ['id', 'name'],
34
- }),
35
- },
36
- });
37
- const rules: any = getTargetDecoratorRules(DtoPostNew.prototype);
38
- assert.equal(['ZodString', 'ZodNumber'].includes(rules.id._def.typeName), true);
39
- assert.equal(rules.title._def.typeName, 'ZodString');
40
- assert.equal(['ZodString', 'ZodNumber'].includes(rules.userId._def.typeName), true);
41
- assert.equal(rules.iid, undefined);
42
- assert.equal(rules.postContent._def.typeName, 'ZodOptional');
43
- assert.equal(rules.user._def.typeName, 'ZodOptional');
44
- assert.equal(rules.user3._def.typeName, 'ZodOptional');
27
+ },
28
+ with: {
29
+ user3: $relationDynamic.belongsTo(ModelPost, () => ModelUser, 'userId', {
30
+ include: { posts: true },
31
+ with: { roles: $relationDynamic.belongsToMany(() => ModelRoleUser, () => ModelRole, 'userId', 'roleId') },
32
+ columns: ['id', 'name'],
33
+ }),
34
+ },
45
35
  });
36
+ const rules: any = getTargetDecoratorRules(DtoPostNew.prototype);
37
+ assert.equal(['ZodString', 'ZodNumber'].includes(rules.id._def.typeName), true);
38
+ assert.equal(rules.title._def.typeName, 'ZodString');
39
+ assert.equal(['ZodString', 'ZodNumber'].includes(rules.userId._def.typeName), true);
40
+ assert.equal(rules.iid, undefined);
41
+ assert.equal(rules.postContent._def.typeName, 'ZodOptional');
42
+ assert.equal(rules.user._def.typeName, 'ZodOptional');
43
+ assert.equal(rules.user3._def.typeName, 'ZodOptional');
46
44
  });
47
45
  });
48
46
  it('action:dtoGet:categoryTree', async () => {
49
47
  await app.bean.executor.mockCtx(async () => {
50
- await app.bean.executor.mockCtx(async () => {
51
- const DtoCategoryTree = $Dto.get('test-vona:category', { columns: ['id', 'name'], include: { children: { columns: ['id'] } } });
52
- const rules: any = getTargetDecoratorRules(DtoCategoryTree.prototype);
53
- assert.equal(rules.children._def.typeName, 'ZodEffects');
54
- assert.equal(rules.iid, undefined);
55
- const DtoCategoryChain = $Dto.get('test-vona:categoryChain', { columns: ['id', 'name', 'categoryIdParent'] });
56
- const _apiJson = await app.bean.scope('a-openapi').service.openapi.generateJsonOfClass(DtoCategoryChain);
57
- // console.log(JSON.stringify(apiJson.components));
58
- });
48
+ const DtoCategoryTree = $Dto.get('test-vona:category', { columns: ['id', 'name'], include: { children: { columns: ['id'] } } });
49
+ const rules: any = getTargetDecoratorRules(DtoCategoryTree.prototype);
50
+ assert.equal(rules.children._def.typeName, 'ZodEffects');
51
+ assert.equal(rules.iid, undefined);
52
+ const DtoCategoryChain = $Dto.get('test-vona:categoryChain', { columns: ['id', 'name', 'categoryIdParent'] });
53
+ const _apiJson = await app.bean.scope('a-openapi').service.openapi.generateJsonOfClass(DtoCategoryChain);
54
+ // console.log(JSON.stringify(apiJson.components));
59
55
  });
60
56
  });
61
57
  });
@@ -8,37 +8,35 @@ import { ModelUserStatsGroup } from 'vona-module-test-vona';
8
8
  describe('dtoGroup.test.ts', () => {
9
9
  it('action:dtoGroup', async () => {
10
10
  await app.bean.executor.mockCtx(async () => {
11
- await app.bean.executor.mockCtx(async () => {
12
- const DtoUserAggr = $Dto.group('test-vona:user', ['name'], {
13
- count: ['*', 'age'],
14
- sum: ['age'],
15
- avg: 'age',
16
- // max: 'age',
17
- // min: 'age',
18
- });
19
- let rules: any;
20
- rules = getTargetDecoratorRules(DtoUserAggr.prototype);
21
- assert.equal(rules.name._def.typeName, 'ZodString');
22
- assert.equal(rules.count_all._def.typeName, 'ZodOptional');
23
- assert.equal(rules.count_all._def.innerType._def.typeName, 'ZodUnion');
24
- assert.equal(rules.count_all._def.innerType._def.options[0]._def.typeName, 'ZodString');
25
- assert.equal(rules.count_all._def.innerType._def.options[1]._def.typeName, 'ZodNumber');
26
- assert.equal(rules.count_age._def.typeName, 'ZodOptional');
27
- assert.equal(rules.sum_age._def.typeName, 'ZodOptional');
28
- assert.equal(rules.avg_age._def.typeName, 'ZodOptional');
29
- assert.equal(rules.max_age, undefined);
30
- assert.equal(rules.min_age, undefined);
31
- // group: userStats: posts: autoload
32
- const DtoUserStats = $Dto.get(() => ModelUserStatsGroup, {
33
- columns: 'name',
34
- include: { roles: true },
35
- });
36
- rules = getTargetDecoratorRules(DtoUserStats.prototype);
37
- assert.equal(rules.name._def.typeName, 'ZodString');
38
- assert.equal(rules.iid, undefined);
39
- assert.equal(rules.posts._def.typeName, 'ZodEffects');
40
- assert.equal(rules.roles._def.typeName, 'ZodEffects');
11
+ const DtoUserAggr = $Dto.group('test-vona:user', ['name'], {
12
+ count: ['*', 'age'],
13
+ sum: ['age'],
14
+ avg: 'age',
15
+ // max: 'age',
16
+ // min: 'age',
41
17
  });
18
+ let rules: any;
19
+ rules = getTargetDecoratorRules(DtoUserAggr.prototype);
20
+ assert.equal(rules.name._def.typeName, 'ZodString');
21
+ assert.equal(rules.count_all._def.typeName, 'ZodOptional');
22
+ assert.equal(rules.count_all._def.innerType._def.typeName, 'ZodUnion');
23
+ assert.equal(rules.count_all._def.innerType._def.options[0]._def.typeName, 'ZodString');
24
+ assert.equal(rules.count_all._def.innerType._def.options[1]._def.typeName, 'ZodNumber');
25
+ assert.equal(rules.count_age._def.typeName, 'ZodOptional');
26
+ assert.equal(rules.sum_age._def.typeName, 'ZodOptional');
27
+ assert.equal(rules.avg_age._def.typeName, 'ZodOptional');
28
+ assert.equal(rules.max_age, undefined);
29
+ assert.equal(rules.min_age, undefined);
30
+ // group: userStats: posts: autoload
31
+ const DtoUserStats = $Dto.get(() => ModelUserStatsGroup, {
32
+ columns: 'name',
33
+ include: { roles: true },
34
+ });
35
+ rules = getTargetDecoratorRules(DtoUserStats.prototype);
36
+ assert.equal(rules.name._def.typeName, 'ZodString');
37
+ assert.equal(rules.iid, undefined);
38
+ assert.equal(rules.posts._def.typeName, 'ZodEffects');
39
+ assert.equal(rules.roles._def.typeName, 'ZodEffects');
42
40
  });
43
41
  });
44
42
  });
@@ -8,49 +8,47 @@ import { ModelPost } from 'vona-module-test-vona';
8
8
  describe('dtoMutate.test.ts', () => {
9
9
  it('action:dtoMutate', async () => {
10
10
  await app.bean.executor.mockCtx(async () => {
11
- await app.bean.executor.mockCtx(async () => {
12
- // create
13
- const DtoUserCreate = $Dto.create('test-vona:user', {
14
- include: { posts: true },
15
- });
16
- let rules: any;
17
- rules = getTargetDecoratorRules(DtoUserCreate.prototype);
18
- assert.equal(rules.name._def.typeName, 'ZodString');
19
- assert.equal(rules.id, undefined);
20
- assert.equal(rules.iid, undefined);
21
- assert.equal(rules.deleted, undefined);
22
- assert.equal(rules.createdAt, undefined);
23
- assert.equal(rules.updatedAt, undefined);
24
- assert.equal(rules.posts._def.typeName, 'ZodOptional');
25
- // update
26
- const DtoUserUpdate = $Dto.update('test-vona:user', {
27
- with: {
28
- posts: $relationDynamic.hasMany(() => ModelPost, 'userId', { columns: ['id', 'title'] }),
29
- },
30
- });
31
- rules = getTargetDecoratorRules(DtoUserUpdate.prototype);
32
- assert.equal(rules.name._def.typeName, 'ZodString'); // ZodOptional
33
- assert.equal(rules.id, undefined);
34
- assert.equal(rules.iid, undefined);
35
- assert.equal(rules.deleted, undefined);
36
- assert.equal(rules.createdAt, undefined);
37
- assert.equal(rules.updatedAt, undefined);
38
- assert.equal(rules.posts._def.typeName, 'ZodOptional');
39
- // create: not mutate post(belongsTo)
40
- const DtoPostCreate = $Dto.create('test-vona:post', {
41
- include: {
42
- postContent: true,
43
- user: true,
44
- },
45
- });
46
- rules = getTargetDecoratorRules(DtoPostCreate.prototype);
47
- assert.equal(rules.title._def.typeName, 'ZodString'); // ZodOptional
48
- assert.equal(rules.stars._def.typeName, 'ZodOptional');
49
- assert.equal(['ZodString', 'ZodNumber'].includes(rules.userId._def.typeName), true);
50
- assert.equal(rules.postContent._def.typeName, 'ZodOptional');
51
- assert.equal(rules.user, undefined);
52
- assert.equal(rules.id, undefined);
11
+ // create
12
+ const DtoUserCreate = $Dto.create('test-vona:user', {
13
+ include: { posts: true },
53
14
  });
15
+ let rules: any;
16
+ rules = getTargetDecoratorRules(DtoUserCreate.prototype);
17
+ assert.equal(rules.name._def.typeName, 'ZodString');
18
+ assert.equal(rules.id, undefined);
19
+ assert.equal(rules.iid, undefined);
20
+ assert.equal(rules.deleted, undefined);
21
+ assert.equal(rules.createdAt, undefined);
22
+ assert.equal(rules.updatedAt, undefined);
23
+ assert.equal(rules.posts._def.typeName, 'ZodOptional');
24
+ // update
25
+ const DtoUserUpdate = $Dto.update('test-vona:user', {
26
+ with: {
27
+ posts: $relationDynamic.hasMany(() => ModelPost, 'userId', { columns: ['id', 'title'] }),
28
+ },
29
+ });
30
+ rules = getTargetDecoratorRules(DtoUserUpdate.prototype);
31
+ assert.equal(rules.name._def.typeName, 'ZodString'); // ZodOptional
32
+ assert.equal(rules.id, undefined);
33
+ assert.equal(rules.iid, undefined);
34
+ assert.equal(rules.deleted, undefined);
35
+ assert.equal(rules.createdAt, undefined);
36
+ assert.equal(rules.updatedAt, undefined);
37
+ assert.equal(rules.posts._def.typeName, 'ZodOptional');
38
+ // create: not mutate post(belongsTo)
39
+ const DtoPostCreate = $Dto.create('test-vona:post', {
40
+ include: {
41
+ postContent: true,
42
+ user: true,
43
+ },
44
+ });
45
+ rules = getTargetDecoratorRules(DtoPostCreate.prototype);
46
+ assert.equal(rules.title._def.typeName, 'ZodString'); // ZodOptional
47
+ assert.equal(rules.stars._def.typeName, 'ZodOptional');
48
+ assert.equal(['ZodString', 'ZodNumber'].includes(rules.userId._def.typeName), true);
49
+ assert.equal(rules.postContent._def.typeName, 'ZodOptional');
50
+ assert.equal(rules.user, undefined);
51
+ assert.equal(rules.id, undefined);
54
52
  });
55
53
  });
56
54
  });
@@ -0,0 +1,55 @@
1
+ import type { IQueryParams } from 'vona-module-a-orm';
2
+ import assert from 'node:assert';
3
+ import { describe, it } from 'node:test';
4
+ import { isNil } from '@cabloy/utils';
5
+ import { app } from 'vona-mock';
6
+
7
+ describe('dtoQuery.test.ts', () => {
8
+ it('action:dtoQuery', async () => {
9
+ await app.bean.executor.mockCtx(async () => {
10
+ // findManyEcho
11
+ const resEcho: IQueryParams = await app.bean.executor.performAction('get', '/test/vona/post/findManyEcho', {
12
+ query: {
13
+ columns: 'id,title', // ['id', 'title'],
14
+ where: {
15
+ stars: {
16
+ _gt_: 12,
17
+ },
18
+ },
19
+ orders: [['testVonaPost.createdAt', 'desc']],
20
+ pageNo: 2,
21
+ pageSize: 30,
22
+ title: 'ai',
23
+ userName: 'tom',
24
+ },
25
+ });
26
+ assert.deepEqual(resEcho.columns, ['id', 'title']);
27
+ assert.deepEqual(resEcho.where, {
28
+ 'stars': { _gt_: 12 },
29
+ 'title': { _includesI_: 'ai' },
30
+ 'testVonaUser.name': 'tom',
31
+ });
32
+ assert.deepEqual(resEcho.orders, [['testVonaPost.createdAt', 'desc']]);
33
+ assert.equal(resEcho.offset, 30);
34
+ assert.equal(resEcho.limit, 30);
35
+ // findMany
36
+ const res = await app.bean.executor.performAction('get', '/test/vona/post/findMany', {
37
+ query: {
38
+ columns: 'id,title', // ['id', 'title'],
39
+ where: {
40
+ stars: {
41
+ _gt_: 12,
42
+ },
43
+ },
44
+ orders: [['testVonaPost.createdAt', 'desc']],
45
+ pageNo: 2,
46
+ pageSize: 30,
47
+ title: 'ai',
48
+ userName: 'tom',
49
+ },
50
+ });
51
+ assert.equal(Array.isArray(res.list), true);
52
+ assert.equal(!isNil(res.total), true);
53
+ });
54
+ });
55
+ });
@@ -32,6 +32,17 @@ describe('modelRelationsJoins.test.ts', () => {
32
32
  orders: [['testVonaUser.id', 'asc']],
33
33
  }, {}, ['test-vona:user']);
34
34
  assert.equal(itemsJoins2.length, 0);
35
+ // joins: manual: no table prefix
36
+ const itemsJoins3 = await scopeTest.model.post.select({
37
+ columns: ['id', 'title'],
38
+ joins: [['innerJoin', 'testVonaUser', ['userId', 'testVonaUser.id']]],
39
+ where: {
40
+ 'testVonaUser.id': userJimmy.id,
41
+ 'userId': userJimmy.id,
42
+ },
43
+ orders: [['testVonaUser.id', 'asc'], ['testVonaPost.createdAt', 'asc']],
44
+ }, {}, ['test-vona:user']);
45
+ assert.equal(itemsJoins3.length, 0);
35
46
  // test data: delete
36
47
  await scopeTest.service.testData.drop(testData);
37
48
  });
@@ -18,7 +18,7 @@ describe('performAction.test.ts', () => {
18
18
  const result: { id: number; url: string } = await app.bean.executor.mockCtx(async () => {
19
19
  return await app.bean.executor.performAction('post', '/test/vona/performAction/echo', {
20
20
  onions: {
21
- pipe: { 'a-validation:valid': { enable: false } },
21
+ pipe: { 'a-web:valid': { enable: false } },
22
22
  },
23
23
  });
24
24
  });