add base subscriber
This commit is contained in:
parent
4991b83641
commit
a92ad374e1
@ -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()
|
||||||
|
@ -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,
|
||||||
|
@ -32,7 +32,7 @@ type SubscriberEvent<T extends ObjectLiteral> =
|
|||||||
|
|
||||||
@EventSubscriber()
|
@EventSubscriber()
|
||||||
export abstract class BaseSubscriber<T extends ObjectLiteral>
|
export abstract class BaseSubscriber<T extends ObjectLiteral>
|
||||||
implements EntitySubscriberInterface<T>
|
implements EntitySubscriberInterface<T>
|
||||||
{
|
{
|
||||||
protected abstract entity: ObjectType<T>;
|
protected abstract entity: ObjectType<T>;
|
||||||
|
|
||||||
|
@ -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,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user