Skip to content

Commit

Permalink
✅ test: 로직 변경에 따른 테스트 코드 수정 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Nov 30, 2023
1 parent e7fd7c2 commit 5ad28cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/test/service/family-member.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ describe('FamilyMemberService', () => {
user.id = 1;
familyMember.setId(1);

jest.spyOn(familyMemberRepository, 'save').mockResolvedValue(familyMember);
jest.spyOn(familyMemberRepository, 'update').mockResolvedValue(familyMember);
jest.spyOn(userRepository, 'findOne').mockResolvedValue(user);
jest.spyOn(familyRepository, 'findOne').mockResolvedValue(family);
jest.spyOn(familyMemberRepository, 'findOne').mockResolvedValue(family);

await familyMemberService.updateFamilyMember(updateFamilyMemberDto);
expect(familyMemberRepository.save).toBeCalled();
expect(familyMemberRepository.update).toBeCalled();
});

it('should delete family-member', async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/test/service/family-schedule.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('FamilyScheduleService', () => {
findOne: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
update: jest.fn(),
});

const family = Family.createFamily('testFamily', 'testKeyCode');
Expand Down Expand Up @@ -98,12 +99,12 @@ describe('FamilyScheduleService', () => {
.spyOn(familyScheduleRepository, 'findOne')
.mockResolvedValue(familySchedule);
jest
.spyOn(familyScheduleRepository, 'save')
.spyOn(familyScheduleRepository, 'update')
.mockResolvedValue(familySchedule);

await familyScheduleService.updateFamilySchedule(updateFamilyScheduleDto);

expect(familyScheduleRepository.save).toBeCalledTimes(1);
expect(familyScheduleRepository.update).toBeCalledTimes(1);
});

it('should delete family schedule', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/service/family.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ describe('FamilyService', () => {
familyName: 'testUpdated',
};
const family = Family.createFamily('test', familyKeyCode);
jest.spyOn(familyRepository, 'save').mockResolvedValue(1);
jest.spyOn(familyRepository, 'update').mockResolvedValue(1);
jest.spyOn(familyRepository, 'findOne').mockResolvedValue(family);

await familyService.updateFamily(updateFamilyDto);

expect(familyRepository.save).toBeCalledTimes(1);
expect(familyRepository.update).toBeCalledTimes(1);
expect(familyRepository.findOne).toBeCalledTimes(1);
});
});
5 changes: 3 additions & 2 deletions src/test/service/post.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('PostService', () => {
findOne: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
update: jest.fn(),
});

let postService: PostService;
Expand Down Expand Up @@ -96,14 +97,14 @@ describe('PostService', () => {
};

jest.spyOn(postRepository, 'findOne').mockResolvedValue(post);
jest.spyOn(postRepository, 'save').mockResolvedValue(post);
jest.spyOn(postRepository, 'update').mockResolvedValue(post);
jest
.spyOn(familyMemberRepository, 'findOne')
.mockResolvedValue(familyMember);

await postService.updatePost(updatePostDto);

expect(postRepository.save).toHaveBeenCalled();
expect(postRepository.update).toHaveBeenCalled();
});

it('should delete post', async () => {
Expand Down
9 changes: 6 additions & 3 deletions src/test/service/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('UserService', () => {
findOne: jest.fn(),
save: jest.fn(),
delete: jest.fn(),
update: jest.fn(),
});

let userService: UserService;
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('UserService', () => {
});

describe('updateUser', () => {
it('should update user', async () => {
it('should update user and should crypt password', async () => {
const user: User = User.createUser(
'[email protected]',
'test',
Expand All @@ -84,11 +85,13 @@ describe('UserService', () => {
gender: 1,
};
jest.spyOn(userRepository, 'findOne').mockResolvedValue(user);
jest.spyOn(userRepository, 'save').mockResolvedValue(1);
jest.spyOn(userRepository, 'update').mockResolvedValue(1);
jest.spyOn(userService, 'hashPassword').mockResolvedValue('@@#');

await userService.updateUser(1, updateUserDto);
expect(userRepository.findOne).toHaveBeenCalled();
expect(userRepository.save).toHaveBeenCalled();
expect(userRepository.update).toHaveBeenCalled();
expect(userService.hashPassword).toHaveBeenCalled();
});

it('should delete user', async () => {
Expand Down

0 comments on commit 5ad28cd

Please sign in to comment.