1+ package com .somemore .center .service .query ;
2+
3+ import com .somemore .IntegrationTestSupport ;
4+ import com .somemore .center .domain .Center ;
5+ import com .somemore .center .repository .CenterRepository ;
6+ import com .somemore .global .exception .BadRequestException ;
7+ import org .junit .jupiter .api .DisplayName ;
8+ import org .junit .jupiter .api .Test ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .transaction .annotation .Transactional ;
11+
12+ import java .util .UUID ;
13+
14+ import static com .somemore .global .exception .ExceptionMessage .NOT_EXISTS_CENTER ;
15+ import static org .assertj .core .api .Assertions .assertThat ;
16+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
17+
18+ @ Transactional
19+ class CenterSignServiceTest extends IntegrationTestSupport {
20+
21+ @ Autowired
22+ private CenterSignService centerSignService ;
23+
24+ @ Autowired
25+ private CenterRepository centerRepository ;
26+
27+ @ DisplayName ("계정 ID로 센터 ID를 조회할 수 있다." )
28+ @ Test
29+ void getIdByAccountId () {
30+ //given
31+ Center center = createCenter ();
32+ centerRepository .save (center );
33+
34+ //when
35+ UUID centerId = centerSignService .getIdByAccountId ("account123" );
36+
37+ //then
38+ assertThat (centerId ).isNotNull ();
39+ assertThat (centerId ).isEqualTo (center .getId ());
40+ }
41+
42+ @ DisplayName ("존재하지 않는 계정 ID로 센터 ID를 조회하면 예외가 발생한다." )
43+ @ Test
44+ void getIdByNonExistentAccountId () {
45+ //given
46+ String nonExistentAccountId = "nonExistentAccount123" ;
47+
48+ //when
49+ //then
50+ assertThatThrownBy (() -> centerSignService .getIdByAccountId (nonExistentAccountId ))
51+ .isInstanceOf (BadRequestException .class )
52+ .hasMessage (NOT_EXISTS_CENTER .getMessage ());
53+ }
54+
55+ @ DisplayName ("계정 ID로 비밀번호를 조회할 수 있다." )
56+ @ Test
57+ void getPasswordByAccountId () {
58+ //given
59+ Center center = createCenter ();
60+ centerRepository .save (center );
61+
62+ //when
63+ String password = centerSignService .getPasswordByAccountId ("account123" );
64+
65+ //then
66+ assertThat (password ).isNotNull ();
67+ assertThat (password ).isEqualTo ("password123" );
68+ }
69+
70+ @ DisplayName ("존재하지 않는 계정 ID로 비밀번호를 조회하면 예외가 발생한다." )
71+ @ Test
72+ void getPasswordByNonExistentAccountId () {
73+ //given
74+ String nonExistentAccountId = "nonExistentAccount123" ;
75+
76+ //when
77+ //then
78+ assertThatThrownBy (() -> centerSignService .getPasswordByAccountId (nonExistentAccountId ))
79+ .isInstanceOf (BadRequestException .class )
80+ .hasMessage (NOT_EXISTS_CENTER .getMessage ());
81+ }
82+
83+ private static Center createCenter () {
84+ return Center .create (
85+ "기본 기관 이름" ,
86+ "010-1234-5678" ,
87+ "http://example.com/image.jpg" ,
88+ "기관 소개 내용" ,
89+ "http://example.com" ,
90+ "account123" ,
91+ "password123"
92+ );
93+ }
94+ }
0 commit comments