Skip to content

Commit d044b59

Browse files
committed
fix: add test:cov script and fix prettier formatting
1 parent a5b57ad commit d044b59

11 files changed

Lines changed: 34 additions & 39 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dev": "npm run proto:generate && nest start --watch",
1616
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
1717
"test": "jest --config test/jest.json --runInBand",
18+
"test:cov": "jest --config test/jest.json --runInBand --coverage",
1819
"proto:generate": "npx nestjs-grpc generate --proto ./src/protos --output ./src/generated",
1920
"prepare": "husky"
2021
},

src/common/services/query-builder.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export class QueryBuilderService {
2828
sortBy,
2929
sortOrder: sortOrder as 'asc' | 'desc',
3030
relations,
31-
customFilters: { ...this.buildExtraFilters(dto), ...customFilters } as Record<string, unknown>,
31+
customFilters: { ...this.buildExtraFilters(dto), ...customFilters } as Record<
32+
string,
33+
unknown
34+
>,
3235
});
3336

3437
return result as unknown as PaginatedResult<T>;

src/modules/post/dtos/post-bulk-request.dto.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { faker } from '@faker-js/faker';
22
import { ApiProperty } from '@nestjs/swagger';
3-
import {
4-
ArrayMinSize,
5-
ArrayUnique,
6-
IsArray,
7-
IsNotEmpty,
8-
} from 'class-validator';
3+
import { ArrayMinSize, ArrayUnique, IsArray, IsNotEmpty } from 'class-validator';
94

105
export class PostBulkRequestDto {
116
@ApiProperty({

src/modules/post/dtos/post-create.dto.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ export class PostCreateDto {
2020

2121
@ApiProperty({
2222
description: 'Array of image URLs associated with the post',
23-
example: [
24-
'https://example.com/image1.jpg',
25-
'https://example.com/image2.jpg',
26-
],
23+
example: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
2724
type: [String],
2825
required: false,
2926
})

src/modules/post/dtos/post.response.dto.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ export class PostResponseDto {
3030

3131
@ApiProperty({
3232
description: 'Array of image URLs associated with the post',
33-
example: [
34-
'https://example.com/image1.jpg',
35-
'https://example.com/image2.jpg',
36-
],
33+
example: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
3734
type: [String],
3835
})
3936
images: string[];
@@ -65,8 +62,7 @@ export class PostResponseDto {
6562
deletedBy?: UserResponseDto;
6663

6764
@ApiProperty({
68-
description:
69-
'The date and time when the post was deleted, if applicable',
65+
description: 'The date and time when the post was deleted, if applicable',
7066
example: '2024-02-23T12:00:00Z',
7167
required: false,
7268
})

src/modules/post/dtos/post.update.dto.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ export class PostUpdateDto {
2222

2323
@ApiProperty({
2424
description: 'Array of image URLs',
25-
example: [
26-
'https://example.com/image1.jpg',
27-
'https://example.com/image2.jpg',
28-
],
25+
example: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
2926
required: false,
3027
type: [String],
3128
})

src/modules/post/services/post-mapping.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,4 @@ export class PostMappingService {
7979
},
8080
};
8181
}
82-
8382
}

test/unit/database.service.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ describe('DatabaseService', () => {
8484
jest.spyOn(service['logger'], 'error').mockImplementation();
8585
mockPostRepository.count.mockRejectedValue(mockError);
8686
const result = await service.isHealthy();
87-
expect(result).toEqual({ database: { status: 'down', connection: 'failed', error: mockError.message } });
87+
expect(result).toEqual({
88+
database: { status: 'down', connection: 'failed', error: mockError.message },
89+
});
8890
});
8991
});
90-

test/unit/grpc.auth.service.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ describe('GrpcAuthService', () => {
9898

9999
const result = await service.getUserById('user-1');
100100

101-
expect(mockGrpcClientService.call).toHaveBeenCalledWith(
102-
'AuthService',
103-
'GetUserById',
104-
{ id: 'user-1' },
105-
);
101+
expect(mockGrpcClientService.call).toHaveBeenCalledWith('AuthService', 'GetUserById', {
102+
id: 'user-1',
103+
});
106104
expect(result).toEqual(mockUser);
107105
});
108106

@@ -119,11 +117,9 @@ describe('GrpcAuthService', () => {
119117

120118
const result = await service.getUserById('');
121119

122-
expect(mockGrpcClientService.call).toHaveBeenCalledWith(
123-
'AuthService',
124-
'GetUserById',
125-
{ id: '' },
126-
);
120+
expect(mockGrpcClientService.call).toHaveBeenCalledWith('AuthService', 'GetUserById', {
121+
id: '',
122+
});
127123
expect(result).toEqual(mockUser);
128124
});
129125
});

test/unit/post.service.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ describe('PostService', () => {
303303

304304
it('should get posts with page 1 and multiple pages', async () => {
305305
const query = { page: 1, limit: 5 };
306-
mockPostRepository.findMany.mockResolvedValue(buildResult(Array(5).fill(mockPost), 15, 1, 5));
306+
mockPostRepository.findMany.mockResolvedValue(
307+
buildResult(Array(5).fill(mockPost), 15, 1, 5),
308+
);
307309
jest.spyOn(postMappingService, 'mapToResponse').mockReturnValue(mockPost as any);
308310

309311
const result = await service.getPosts(query);
@@ -315,7 +317,9 @@ describe('PostService', () => {
315317

316318
it('should get posts with page 2 and multiple pages', async () => {
317319
const query = { page: 2, limit: 5 };
318-
mockPostRepository.findMany.mockResolvedValue(buildResult(Array(5).fill(mockPost), 15, 2, 5));
320+
mockPostRepository.findMany.mockResolvedValue(
321+
buildResult(Array(5).fill(mockPost), 15, 2, 5),
322+
);
319323
jest.spyOn(postMappingService, 'mapToResponse').mockReturnValue(mockPost as any);
320324

321325
const result = await service.getPosts(query);
@@ -327,7 +331,9 @@ describe('PostService', () => {
327331

328332
it('should get posts with last page', async () => {
329333
const query = { page: 3, limit: 5 };
330-
mockPostRepository.findMany.mockResolvedValue(buildResult(Array(5).fill(mockPost), 15, 3, 5));
334+
mockPostRepository.findMany.mockResolvedValue(
335+
buildResult(Array(5).fill(mockPost), 15, 3, 5),
336+
);
331337
jest.spyOn(postMappingService, 'mapToResponse').mockReturnValue(mockPost as any);
332338

333339
const result = await service.getPosts(query);
@@ -363,7 +369,9 @@ describe('PostService', () => {
363369

364370
it('should get posts with page equal to totalPages', async () => {
365371
const query = { page: 2, limit: 5 };
366-
mockPostRepository.findMany.mockResolvedValue(buildResult(Array(5).fill(mockPost), 10, 2, 5));
372+
mockPostRepository.findMany.mockResolvedValue(
373+
buildResult(Array(5).fill(mockPost), 10, 2, 5),
374+
);
367375
jest.spyOn(postMappingService, 'mapToResponse').mockReturnValue(mockPost as any);
368376

369377
const result = await service.getPosts(query);

0 commit comments

Comments
 (0)