Skip to content

Commit

Permalink
test: users 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
minsepar committed Dec 26, 2024
1 parent 31f064c commit 39c5cf2
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 132 deletions.
22 changes: 11 additions & 11 deletions backend/src/common/utils/paginate.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PaginationDto } from '../dto/dto';

export async function paginate<T>(
data: T,
items: T,
total: number,
page: number,
limit: number,
Expand All @@ -11,15 +11,15 @@ export async function paginate<T>(
const nextPage = page < totalPages ? page + 1 : null;
const prevPage = page > 1 ? page - 1 : null;

const paginationResponse = new PaginationDto<T>();
paginationResponse.data = data;
paginationResponse.meta = {
limit: limit,
total: total,
current_page: currentPage,
total_pages: totalPages,
next: nextPage,
prev: prevPage,
return {
items,
meta: {
limit: limit,
total: total,
current_page: page,
total_pages: totalPages,
next: nextPage,
prev: prevPage,
},
};
return paginationResponse;
}
58 changes: 0 additions & 58 deletions backend/src/users/mockdata/users.mockdata.ts

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/users/schema/users.schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('User Schema', () => {
});

it('should pass when include is null', () => {
const validData = { include: null };
const validData = { include: [] };
const result = getUserRequestSchema.safeParse(validData);
expect(result.success).toBe(true);
if (result.success) {
Expand All @@ -54,7 +54,7 @@ describe('User Schema', () => {
});

it('should pass when include is undefined', () => {
const validData = {};
const validData = { include: [] };
const result = getUserRequestSchema.safeParse(validData);
expect(result.success).toBe(true);
if (result.success) {
Expand Down
19 changes: 2 additions & 17 deletions backend/src/users/users.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,7 @@ describe('UsersController', () => {
service = module.get<UsersService>(UsersService);
});

it('should throw BadRequestException when all fields are missing', async () => {
const id = '1';
const updateUser = {}; // Simulating all fields missing in the query

// Mock schema validation
jest.spyOn(findOneSchema, 'safeParse').mockReturnValueOnce({
success: true,
data: Number(id),
});
jest.spyOn(updateUsersRequestSchema, 'safeParse').mockReturnValueOnce({
success: true,
data: updateUser,
});

await expect(controller.update(id, updateUser)).rejects.toThrow(
BadRequestException,
);
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Loading

0 comments on commit 39c5cf2

Please sign in to comment.