add base subscriber

This commit is contained in:
liuyi 2025-06-04 22:50:04 +08:00
parent 4991b83641
commit a92ad374e1
4 changed files with 22 additions and 8 deletions

View File

@ -48,7 +48,7 @@ export class PostEntity extends BaseEntity {
type: PostBodyType; type: PostBodyType;
@Expose() @Expose()
@Column({ comment: '发布时间', type: 'varchar', nullable: true }) @Column({ comment: '发布时间', type: 'timestamp', nullable: true })
publishedAt?: Date | null; publishedAt?: Date | null;
@Expose() @Expose()

View File

@ -19,6 +19,10 @@ export class CategoryService extends BaseService<CategoryEntity, CategoryReposit
return this.repository.findTrees(); return this.repository.findTrees();
} }
async detail(id: string) {
return this.repository.findOneOrFail({ where: { id }, relations: ['parent', 'children'] });
}
async create(data: CreateCategoryDto) { async create(data: CreateCategoryDto) {
const item = await this.repository.save({ const item = await this.repository.save({
...data, ...data,

View File

@ -16,6 +16,8 @@ import {
TagRepository, TagRepository,
} from '@/modules/content/repositories'; } from '@/modules/content/repositories';
import { MeiliService } from '@/modules/meilisearch/meili.service';
import { generateRandomNumber, generateUniqueRandomNumbers } from './generate-mock-data'; import { generateRandomNumber, generateUniqueRandomNumbers } from './generate-mock-data';
import { categoriesData, commentData, INIT_DATA, postData, tagData } from './test-data'; import { categoriesData, commentData, INIT_DATA, postData, tagData } from './test-data';
@ -31,6 +33,7 @@ describe('nest app test', () => {
let categories: CategoryEntity[]; let categories: CategoryEntity[];
let tags: TagEntity[]; let tags: TagEntity[];
let comments: CommentEntity[]; let comments: CommentEntity[];
let searchService: MeiliService;
beforeAll(async () => { beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({ const module: TestingModule = await Test.createTestingModule({
@ -45,11 +48,15 @@ describe('nest app test', () => {
tagRepository = module.get<TagRepository>(TagRepository); tagRepository = module.get<TagRepository>(TagRepository);
postRepository = module.get<PostRepository>(PostRepository); postRepository = module.get<PostRepository>(PostRepository);
commentRepository = module.get<CommentRepository>(CommentRepository); commentRepository = module.get<CommentRepository>(CommentRepository);
searchService = module.get<MeiliService>(MeiliService);
datasource = module.get<DataSource>(DataSource); datasource = module.get<DataSource>(DataSource);
if (!datasource.isInitialized) { if (!datasource.isInitialized) {
await datasource.initialize(); await datasource.initialize();
} }
if (INIT_DATA) { if (INIT_DATA) {
const client = searchService.getClient();
client.deleteIndex('content');
const queryRunner = datasource.createQueryRunner(); const queryRunner = datasource.createQueryRunner();
try { try {
await queryRunner.query('SET FOREIGN_KEY_CHECKS = 0'); await queryRunner.query('SET FOREIGN_KEY_CHECKS = 0');
@ -377,7 +384,10 @@ describe('nest app test', () => {
}, },
}); });
expect(result.json()).toEqual({ expect(result.json()).toEqual({
message: ['The format of the parent category ID is incorrect.'], message: [
'The format of the parent category ID is incorrect.',
'The parent category does not exist',
],
error: 'Bad Request', error: 'Bad Request',
statusCode: 400, statusCode: 400,
}); });
@ -592,7 +602,7 @@ describe('nest app test', () => {
}); });
it('update category with duplicate name in same parent', async () => { it('update category with duplicate name in same parent', async () => {
const parentCategory = categories.find((c) => c.children && c.children.length > 1); const parentCategory = categories.find((c) => c.children?.length > 1);
const [child1, child2] = parentCategory.children; const [child1, child2] = parentCategory.children;
const result = await app.inject({ const result = await app.inject({
@ -1120,8 +1130,8 @@ describe('nest app test', () => {
}); });
expect(result.json()).toEqual({ expect(result.json()).toEqual({
message: [ message: [
'body should not be empty', 'Comment content cannot be empty',
'body must be shorter than or equal to 1000 characters', 'The length of the comment content cannot exceed 1000',
], ],
error: 'Bad Request', error: 'Bad Request',
statusCode: 400, statusCode: 400,
@ -1135,7 +1145,7 @@ describe('nest app test', () => {
body: { body: 'Test comment' }, body: { body: 'Test comment' },
}); });
expect(result.json()).toEqual({ expect(result.json()).toEqual({
message: ['The ID must be specified', 'The ID format is incorrect'], message: ['The post ID must be specified', 'The ID format is incorrect'],
error: 'Bad Request', error: 'Bad Request',
statusCode: 400, statusCode: 400,
}); });
@ -1152,7 +1162,7 @@ describe('nest app test', () => {
}, },
}); });
expect(result.json()).toEqual({ expect(result.json()).toEqual({
message: ['body must be shorter than or equal to 1000 characters'], message: ['The length of the comment content cannot exceed 1000'],
error: 'Bad Request', error: 'Bad Request',
statusCode: 400, statusCode: 400,
}); });