From 5ad28cdbe4a003726505d6a8b5c26571088c934c Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Thu, 30 Nov 2023 11:07:42 +0900 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#62)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/service/family-member.service.spec.ts | 4 ++-- src/test/service/family-schedule.service.spec.ts | 5 +++-- src/test/service/family.service.spec.ts | 4 ++-- src/test/service/post.service.spec.ts | 5 +++-- src/test/service/user.service.spec.ts | 9 ++++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/test/service/family-member.service.spec.ts b/src/test/service/family-member.service.spec.ts index 606cd94..e970560 100644 --- a/src/test/service/family-member.service.spec.ts +++ b/src/test/service/family-member.service.spec.ts @@ -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 () => { diff --git a/src/test/service/family-schedule.service.spec.ts b/src/test/service/family-schedule.service.spec.ts index 157bc8a..e972679 100644 --- a/src/test/service/family-schedule.service.spec.ts +++ b/src/test/service/family-schedule.service.spec.ts @@ -9,6 +9,7 @@ describe('FamilyScheduleService', () => { findOne: jest.fn(), save: jest.fn(), delete: jest.fn(), + update: jest.fn(), }); const family = Family.createFamily('testFamily', 'testKeyCode'); @@ -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 () => { diff --git a/src/test/service/family.service.spec.ts b/src/test/service/family.service.spec.ts index 14823fd..fdf2211 100644 --- a/src/test/service/family.service.spec.ts +++ b/src/test/service/family.service.spec.ts @@ -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); }); }); diff --git a/src/test/service/post.service.spec.ts b/src/test/service/post.service.spec.ts index 2fc6d42..3fc155b 100644 --- a/src/test/service/post.service.spec.ts +++ b/src/test/service/post.service.spec.ts @@ -9,6 +9,7 @@ describe('PostService', () => { findOne: jest.fn(), save: jest.fn(), delete: jest.fn(), + update: jest.fn(), }); let postService: PostService; @@ -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 () => { diff --git a/src/test/service/user.service.spec.ts b/src/test/service/user.service.spec.ts index 41cac2e..2ff8618 100644 --- a/src/test/service/user.service.spec.ts +++ b/src/test/service/user.service.spec.ts @@ -13,6 +13,7 @@ describe('UserService', () => { findOne: jest.fn(), save: jest.fn(), delete: jest.fn(), + update: jest.fn(), }); let userService: UserService; @@ -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( 'test@test.com', 'test', @@ -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 () => {