11package com .somemore .domains .notification .handler ;
22
3+ import com .somemore .center .domain .NEWCenter ;
4+ import com .somemore .center .repository .NEWCenterRepository ;
35import com .somemore .domains .notification .domain .Notification ;
46import com .somemore .domains .notification .domain .NotificationSubType ;
57import com .somemore .domains .notification .event .converter .NotificationMessageConverter ;
68import com .somemore .domains .notification .event .handler .NotificationHandlerImpl ;
79import com .somemore .domains .notification .repository .NotificationRepository ;
10+ import com .somemore .global .auth .oauth .domain .OAuthProvider ;
811import com .somemore .support .IntegrationTestSupport ;
12+ import com .somemore .user .domain .User ;
13+ import com .somemore .user .domain .UserRole ;
14+ import com .somemore .user .dto .UserAuthInfo ;
15+ import com .somemore .user .repository .user .UserRepository ;
16+ import com .somemore .volunteer .domain .NEWVolunteer ;
17+ import com .somemore .volunteer .repository .NEWVolunteerRepository ;
918import org .junit .jupiter .api .DisplayName ;
1019import org .junit .jupiter .api .Test ;
1120import org .springframework .beans .factory .annotation .Autowired ;
1221import org .springframework .transaction .annotation .Transactional ;
1322
1423import java .util .List ;
15- import java .util .UUID ;
1624
1725import static org .assertj .core .api .Assertions .assertThat ;
1826
@@ -28,36 +36,58 @@ class NotificationHandlerTest extends IntegrationTestSupport {
2836 @ Autowired
2937 private NotificationRepository notificationRepository ;
3038
39+ @ Autowired
40+ private UserRepository userRepository ;
41+
42+ @ Autowired
43+ private NEWVolunteerRepository volunteerRepository ;
44+
45+ @ Autowired
46+ private NEWCenterRepository centerRepository ;
47+
3148 @ Test
3249 @ DisplayName ("handle 호출 시 Notification이 저장된다" )
3350 void handle () {
51+
3452 // given
35- String message = """
53+ UserAuthInfo volunteerUserAuthInfo = UserAuthInfo .createForOAuth (OAuthProvider .NAVER );
54+ User volunteerUser = User .of (volunteerUserAuthInfo , UserRole .VOLUNTEER );
55+ userRepository .save (volunteerUser );
56+
57+ UserAuthInfo centerUserAuthInfo = UserAuthInfo .createForOAuth (OAuthProvider .NAVER );
58+ User centerUser = User .of (centerUserAuthInfo , UserRole .CENTER );
59+ userRepository .save (centerUser );
60+
61+ NEWVolunteer volunteer = NEWVolunteer .createDefault (volunteerUser .getId ());
62+ volunteerRepository .save (volunteer );
63+
64+ NEWCenter center = NEWCenter .createDefault (centerUser .getId ());
65+ centerRepository .save (center );
66+
67+ String message = String .format ("""
3668 {
3769 "type": "NOTIFICATION",
3870 "subType": "VOLUNTEER_APPLY_STATUS_CHANGE",
39- "volunteerId": "123e4567-e89b-12d3-a456-426614174000 ",
71+ "volunteerId": "%s ",
4072 "volunteerApplyId": 123,
41- "centerId": "123e4567-e89b-12d3-a456-426614174001 ",
73+ "centerId": "%s ",
4274 "recruitBoardId": 456,
4375 "oldStatus": "WAITING",
4476 "newStatus": "APPROVED",
4577 "createdAt": "2024-12-05T10:00:00"
4678 }
47- """ ;
48-
49- UUID receiverId = UUID .fromString ("123e4567-e89b-12d3-a456-426614174000" );
79+ """ , volunteer .getId (), center .getId ());
5080
5181 Notification notification = notificationMessageConverter .from (message );
5282 // when
5383 notificationHandler .handle (notification );
5484
5585 // then
56- List <Notification > notifications = notificationRepository .findAllByUserId (receiverId );
86+ List <Notification > notifications = notificationRepository .findAllByUserId (volunteerUser . getId () );
5787 assertThat (notifications ).hasSize (1 );
5888
5989 Notification savedNotification = notifications .getFirst ();
60- assertThat (savedNotification .getReceiverId ()).isEqualTo (receiverId );
90+ assertThat (savedNotification .getReceiverId ()).isEqualTo (volunteerUser . getId () );
6191 assertThat (savedNotification .getTitle ()).isEqualTo ("봉사 활동 신청이 승인되었습니다." );
6292 assertThat (savedNotification .getType ()).isEqualTo (NotificationSubType .VOLUNTEER_APPLY_STATUS_CHANGE );
6393 assertThat (savedNotification .getRelatedId ()).isEqualTo (456L ); // 프론트 요구사항: 123L(봉사신청아이디), 456L(모집글아이디)
0 commit comments