@@ -21,43 +21,49 @@ beforeEach(async () => {
2121 prismaMock . worry . findUnique . mockResolvedValue ( worry ) ;
2222} )
2323
24+ afterEach ( ( ) => {
25+ // 각 테스트 후에 spyOn 리셋
26+ jest . restoreAllMocks ( ) ;
27+ } ) ;
28+
2429describe ( "[PUT] /review 리뷰 등록 및 수정" , ( ) => {
2530
2631 describe ( "올바른 요청일 경우" , ( ) => {
2732
2833 const DTO = {
2934 worryId : 1 ,
3035 userId : 1 ,
31- review : "후기이이ㅣㅣㅣㅣㅣ~! " ,
36+ review : "후기1 " ,
3237 } ;
3338 const review = {
3439 worry_id : 1 ,
3540 user_id :3 ,
36- content : "후기이이ㅣㅣㅣㅣㅣ~ !" ,
37- created_at : new Date ( ) ,
38- updated_at : new Date ( )
41+ content : "후기1 !" ,
42+ created_at : new Date ( '2020-01-01' ) ,
43+ updated_at : new Date ( '2020-01-01' ) ,
3944 } ;
45+
46+ const kst_updated_at = '2020-01-01'
4047
41- // test("리뷰가 존재하지 않을 경우, 리뷰를 생성", async () => {
42- // prismaMock.review.findUnique.mockResolvedValue(null);
43- // prismaMock.review.create.mockResolvedValue(review);
44- // const moment = require('moment');
45- // const kst_updated_at = moment(review.updated_at).utc().utcOffset(9).format('YYYY-MM-DD');
48+ test ( "리뷰가 존재하지 않을 경우, 리뷰를 생성" , async ( ) => {
49+ prismaMock . review . findUnique . mockResolvedValue ( review ) ;
50+
51+ const data = {
52+ isNew : 1 ,
53+ result :{
54+ updatedAt : kst_updated_at
55+ }
56+
57+ }
58+ // jest.spyOn(reviewService, 'patchReview').mockResolvedValue(data);
4659
47- // await expect(reviewService.patchReview(DTO)).resolves.toEqual({
48- // isNew: 1,
49- // result:{
50- // updatedAt: kst_updated_at
51- // }
52- // })
60+
61+ await expect ( reviewService . patchReview ( DTO ) ) . resolves . toEqual ( data ) ;
5362
54- // })
63+ } )
5564
5665 test ( "리뷰가 존재할 경우, 리뷰를 수정" , async ( ) => {
5766 prismaMock . review . findUnique . mockResolvedValue ( review ) ;
58- prismaMock . review . update . mockResolvedValue ( review ) ;
59- const moment = require ( 'moment' ) ;
60- const kst_updated_at = moment ( review . updated_at ) . utc ( ) . utcOffset ( 9 ) . format ( 'YYYY-MM-DD' ) ;
6167
6268 await expect ( reviewService . patchReview ( DTO ) ) . resolves . toEqual ( {
6369 isNew : 0 ,
0 commit comments