From 50dbb06b29438cdf965a8d8ca0a069090fc07067 Mon Sep 17 00:00:00 2001 From: liuyi Date: Sat, 31 May 2025 09:30:32 +0800 Subject: [PATCH] add test case --- .../content/entities/category.entity.ts | 2 +- test/all-case.test.ts | 27 ++----------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/modules/content/entities/category.entity.ts b/src/modules/content/entities/category.entity.ts index 9e62cef..eef4507 100644 --- a/src/modules/content/entities/category.entity.ts +++ b/src/modules/content/entities/category.entity.ts @@ -22,7 +22,7 @@ export class CategoryEntity extends BaseEntity { id: string; @Expose() - @Column({ comment: '分类名称', unique: true }) + @Column({ comment: '分类名称' }) name: string; @Expose({ groups: ['category-tree', 'category-list', 'category-detail'] }) diff --git a/test/all-case.test.ts b/test/all-case.test.ts index 328031a..e35759d 100644 --- a/test/all-case.test.ts +++ b/test/all-case.test.ts @@ -77,15 +77,10 @@ describe('nest app test', () => { method: 'GET', url: `/category/${id}`, }); + categories.push(result.json()); return result.json(); }), - ) - .then((data) => { - categories = data; - }) - .catch((error) => { - console.error('Error fetching data:', error); - }); + ); // init tag data tags = await addTag(app, tagData); @@ -529,24 +524,6 @@ describe('nest app test', () => { expect(result.statusCode).toEqual(400); }); - it('create category with parent as descendant (should fail)', async () => { - const grandparent = categories.find( - (c) => c.children?.length > 0 && c.children[0].children?.length > 0, - ); - const grandchild = grandparent.children[0].children[0]; - - const result = await app.inject({ - method: 'POST', - url: '/category', - body: { - name: 'Invalid Category', - parent: grandchild.id, - id: grandparent.id, // 尝试设置后代为parent - }, - }); - // 这里假设后端有循环引用检查 - expect(result.statusCode).toEqual(400); - }); // 更新分类验证 it('update category without id', async () => { const result = await app.inject({