@@ -3,7 +3,8 @@ import { AuthService } from './auth.service';
33import { UserRepository } from '../user/user.repository' ;
44import { SignUpDto } from './dtos/signUp.dto' ;
55import { User } from '../user/user.entity' ;
6- import { Snowflake } from '@theinternetfolks/snowflake' ;
6+ import { UpdateUserDto } from './dtos/UpdateUser.dto' ;
7+ import { UserNotFoundException } from '../exception/user.exception' ;
78
89describe ( 'AuthService' , ( ) => {
910 let authService : AuthService ;
@@ -17,6 +18,7 @@ describe('AuthService', () => {
1718 provide : UserRepository ,
1819 useValue : {
1920 findOne : jest . fn ( ) ,
21+ findOneBy : jest . fn ( ) ,
2022 create : jest . fn ( ) ,
2123 save : jest . fn ( ) ,
2224 } ,
@@ -66,7 +68,9 @@ describe('AuthService', () => {
6668 provider : 'naver' ,
67696870 } ;
69- const generatedSnowflakeId = Snowflake . generate ( ) ; // Snowflake.generate()의 mock 값을 준비
71+ const generated
72+
73+ flakeId = Snowflake . generate ( ) ; // Snowflake.generate()의 mock 값을 준비
7074 const newDate = new Date ( ) ;
7175 const createdUser = {
7276 providerId : dto . providerId ,
@@ -99,4 +103,55 @@ describe('AuthService', () => {
99103 expect ( userRepository . save ) . toHaveBeenCalledWith ( createdUser ) ;
100104 } ) ;
101105 } ) ;
106+
107+ describe ( 'updateUser' , ( ) => {
108+ it ( '사용자를 성공적으로 갱신한다' , async ( ) => {
109+ const dto : UpdateUserDto = {
110+ cursorColor : '#FFFFFF' ,
111+ nickname : 'new-nickname' ,
112+ } ;
113+
114+ // 현재 날짜
115+ const currentDate = new Date ( ) ;
116+ const originUser = {
117+ id : 1 ,
118+ snowflakeId : '123456789012345678' ,
119+ providerId : 'kakao_12345' ,
120+ provider : 'kakao' ,
121+ 122+ cursorColor : '#FF8A8A' ,
123+ nickname : 'origin-nickname' ,
124+ profileImage : 'https://example.com/profile.jpg' ,
125+ createdAt : currentDate ,
126+ } as User ;
127+
128+ const newUser = {
129+ id : 1 ,
130+ snowflakeId : '123456789012345678' ,
131+ providerId : 'kakao_12345' ,
132+ provider : 'kakao' ,
133+ 134+ cursorColor : '#FFFFFF' ,
135+ nickname : 'new-nickname' ,
136+ profileImage : 'https://example.com/profile.jpg' ,
137+ createdAt : currentDate ,
138+ } ;
139+
140+ jest . spyOn ( userRepository , 'findOneBy' ) . mockResolvedValue ( originUser ) ;
141+ await authService . updateUser ( 1 , dto ) ;
142+ expect ( userRepository . save ) . toHaveBeenCalledWith ( newUser ) ;
143+ } ) ;
144+
145+ it ( '사용자가 존재하지 않으면 예외를 던진다.' , async ( ) => {
146+ const dto : UpdateUserDto = {
147+ cursorColor : '#FFFFFF' ,
148+ nickname : 'new-nickname' ,
149+ } ;
150+
151+ jest . spyOn ( userRepository , 'findOneBy' ) . mockResolvedValue ( null ) ;
152+ expect ( authService . updateUser ( 1 , dto ) ) . rejects . toThrow (
153+ UserNotFoundException ,
154+ ) ;
155+ } ) ;
156+ } ) ;
102157} ) ;
0 commit comments