Skip to content

Commit

Permalink
fix: 로그인시 디바이스 활성화가 안되던 이슈 수정 (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectick authored Nov 16, 2023
1 parent 70b333f commit 79409c5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AuthService {
* @param loginRequest 로그인에 필요한 정보
* @return 로그인한 사용자의 식별자
*/
@Transactional
public MemberId login(final LoginRequest loginRequest) {
final Member member = authenticateMember(loginRequest.email(), loginRequest.password());
publisher.publishEvent(new LoginEvent(member, loginRequest.deviceToken()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import edonymyeon.backend.image.application.ImageService;
import edonymyeon.backend.image.domain.ImageInfo;
import edonymyeon.backend.image.profileimage.domain.ProfileImageInfo;
import edonymyeon.backend.member.application.DeviceRepository;
import edonymyeon.backend.member.application.MemberService;
import edonymyeon.backend.member.application.dto.ActiveMemberId;
import edonymyeon.backend.member.domain.Device;
import edonymyeon.backend.member.domain.Email;
import edonymyeon.backend.member.domain.Member;
import edonymyeon.backend.member.domain.SocialInfo;
Expand All @@ -41,6 +43,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.jdbc.Sql;

@DisplayNameGeneration(ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
Expand Down Expand Up @@ -81,6 +84,19 @@ class AuthServiceTest {
assertThat(member.getDevices()).hasSize(1);
}

@Test
void 최초의_소셜로그인시_사용한_디바이스_정보를_함께_저장한다(@Autowired EntityManager entityManager) {
doNothing().when(settingService).initializeSettings(any());

authService.loginByKakao(new KakaoLoginResponse(1L), "testDeviceToken");

final Member member = entityManager.createQuery(
"select m from Member m left join fetch m.devices where m.socialInfo.socialId = :socialId", Member.class)
.setParameter("socialId", 1L)
.getSingleResult();
assertThat(member.getDevices()).hasSize(1);
}

@Test
void 회원_이후_설정초기화_작업을_수행한다() {
doNothing().when(settingService).initializeSettings(any());
Expand All @@ -99,22 +115,48 @@ class AuthServiceTest {
}

@Test
void 로그인_이후_디바이스_교체_작업을_수행한다() {
doNothing().when(memberService).activateDevice(any(), any());

authService.joinMember(
new JoinRequest("[email protected]", "@testPassword234", "testNickname", "testDeviceToken"));
authService.login(new LoginRequest("[email protected]", "@testPassword234", "testToken"));
verify(memberService, atLeastOnce()).activateDevice(any(), any());
void 로그인_이후_디바이스_교체_작업을_수행한다(@Autowired DeviceRepository deviceRepository) {
//given
final JoinRequest joinRequest = new JoinRequest("[email protected]", "@testPassword234", "testNickname",
"testDeviceToken");
authService.joinMember(joinRequest);

//when
final LoginRequest loginRequest = new LoginRequest("[email protected]", "@testPassword234", "testToken");
authService.login(loginRequest);

//then
assertSoftly(
softAssertions -> {
final Device originalDevice = deviceRepository.findByDeviceToken(joinRequest.deviceToken()).get();
final Optional<Device> changedDevice = deviceRepository.findByDeviceToken(loginRequest.deviceToken());
assertThat(changedDevice.isPresent()).isTrue();
assertThat(changedDevice.get().isActive()).isTrue();
assertThat(originalDevice.isActive()).isFalse();
}
);
}

@Test
void 소셜로그인_이후에도_디바이스_교체_작업을_수행한다() {
doNothing().when(memberService).activateDevice(any(), any());

authService.loginByKakao(new KakaoLoginResponse(1L), "testDeviceToken");

verify(memberService, atLeastOnce()).activateDevice(any(), any());
void 소셜로그인_이후에도_디바이스_교체_작업을_수행한다(@Autowired DeviceRepository deviceRepository) {
//given
final String originalDeviceToken = "testDeviceToken";
authService.loginByKakao(new KakaoLoginResponse(1L), originalDeviceToken);

//when
final String changedDeviceToken = "testDeviceToken2";
authService.loginByKakao(new KakaoLoginResponse(1L), changedDeviceToken);

//then
assertSoftly(
softAssertions -> {
final Device originalDevice = deviceRepository.findByDeviceToken(originalDeviceToken).get();
final Optional<Device> changedDevice = deviceRepository.findByDeviceToken(changedDeviceToken);
assertThat(changedDevice.isPresent()).isTrue();
assertThat(changedDevice.get().isActive()).isTrue();
assertThat(originalDevice.isActive()).isFalse();
}
);
}

@Test
Expand Down

0 comments on commit 79409c5

Please sign in to comment.