Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Jan 14, 2025
1 parent 437bb28 commit 929b099
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import kr.co.pennyway.domain.domains.user.repository.UserRepository;
import kr.co.pennyway.domain.domains.user.service.UserRdbService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -25,7 +26,6 @@
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

Expand Down Expand Up @@ -55,6 +55,12 @@ void setUp() {
savedUser = userRepository.save(UserFixture.GENERAL_USER.toUser());
}

@AfterEach
void tearDown() {
deviceTokenRepository.deleteAll();
userRepository.deleteAll();
}

@Test
@DisplayName("μƒˆλ‘œμš΄ 토큰 등둝 μš”μ²­ μ‹œ λ””λ°”μ΄μŠ€ 토큰이 μ •μƒμ μœΌλ‘œ μ €μž₯λ©λ‹ˆλ‹€")
void when_registering_new_token_then_save_successfully() {
Expand Down Expand Up @@ -83,7 +89,6 @@ void when_registering_new_token_then_save_successfully() {
}

@Test
@Transactional
@DisplayName("μ‚¬μš©μžκ°€ λ™μΌν•œ λ””λ°”μ΄μŠ€μ— μƒˆλ‘œμš΄ 토큰을 λ“±λ‘ν•˜λ©΄ κΈ°μ‘΄ 토큰이 λΉ„ν™œμ„±ν™”λ©λ‹ˆλ‹€")
void when_registering_new_token_for_same_device_then_deactivate_existing_token() {
// given
Expand All @@ -94,7 +99,6 @@ void when_registering_new_token_for_same_device_then_deactivate_existing_token()
DeviceToken secondToken = deviceTokenRegisterService.execute(savedUser.getId(), deviceId, "Android", "token2");

// then
assertFalse(firstToken.isActivated());
assertTrue(secondToken.isActivated());
assertEquals(deviceId, secondToken.getDeviceId());

Expand All @@ -105,7 +109,6 @@ void when_registering_new_token_for_same_device_then_deactivate_existing_token()
}

@Test
@Transactional
@DisplayName("ν™œμ„±ν™”λœ 토큰을 λ‹€λ₯Έ λ””λ°”μ΄μŠ€μ—μ„œ μ‚¬μš©ν•˜λ €κ³  ν•˜λ©΄ μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€")
void when_using_active_token_on_different_device_then_throw_exception() {
// given
Expand All @@ -121,7 +124,6 @@ void when_using_active_token_on_different_device_then_throw_exception() {
}

@Test
@Transactional
@DisplayName("같은 deviceId, token / λ‹€λ₯Έ μ‚¬μš©μž κ°±μ‹  μš”μ²­μ΄λΌλ©΄, λ””λ°”μ΄μŠ€ ν† ν°μ˜ μ†Œμœ κΆŒμ΄ λ‹€λ₯Έ μ‚¬μš©μžμ—κ²Œ μ΄μ „λ©λ‹ˆλ‹€")
void shouldTransferTokenOwnership() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import kr.co.pennyway.domain.domains.device.domain.DeviceToken;
import kr.co.pennyway.domain.domains.device.exception.DeviceTokenErrorException;
import kr.co.pennyway.domain.domains.user.domain.User;
import kr.co.pennyway.domain.domains.user.exception.UserErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand All @@ -14,16 +13,6 @@
import static org.junit.jupiter.api.Assertions.*;

public class DeviceTokenRegisterServiceTest {
@Test
@DisplayName("μ‚¬μš©μžκ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμœΌλ©΄ μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€")
void when_user_not_found_then_throw_exception() {
// given
DeviceTokenRegisterCollection collection = new DeviceTokenRegisterCollection();

// when & then
assertThrows(UserErrorException.class, () -> collection.register(null, "device1", "Android", "token1"));
}

@Test
@DisplayName("μƒˆλ‘œμš΄ 토큰 등둝 μ‹œ μ˜¬λ°”λ₯Έ μ •λ³΄λ‘œ μƒμ„±λ©λ‹ˆλ‹€")
void when_user_has_no_token_should_create_new_token() {
Expand Down

0 comments on commit 929b099

Please sign in to comment.