Skip to content

Commit

Permalink
YEL-134 [update] 푸시 알림 메세지 변경 및 테스트 코드 수정
Browse files Browse the repository at this point in the history
YEL-134 [update] 푸시 알림 메세지 변경 및 테스트 코드 수정
  • Loading branch information
devkwonsehoon authored Aug 20, 2023
2 parents 6360c35 + 677bba9 commit 08925eb
Show file tree
Hide file tree
Showing 15 changed files with 626 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.infrastructure.redis.repository.TokenRepository;
import java.util.Optional;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Builder
@Component
@RequiredArgsConstructor
public class AuthManagerImpl implements AuthManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TokenJwtProvider implements TokenProvider {
public static final String ACCESS_TOKEN = "accessToken";
public static final String REFRESH_TOKEN = "refreshToken";

private static final Long ACCESS_TOKEN_VALID_TIME = ofHours(1).toMillis();
private static final Long ACCESS_TOKEN_VALID_TIME = ofHours(4).toMillis();
private static final Long REFRESH_TOKEN_VALID_TIME = ofDays(14).toMillis();

public String secretKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,22 @@
import com.yello.server.domain.purchase.repository.PurchaseRepository;
import com.yello.server.domain.user.entity.Subscribe;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yello.server.domain.purchase.entity.Gateway;
import com.yello.server.domain.purchase.entity.ProductType;
import com.yello.server.domain.purchase.entity.Purchase;
import com.yello.server.domain.purchase.repository.PurchaseRepository;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class PurchaseManagerImpl implements PurchaseManager {

private final PurchaseRepository purchaseRepository;
private final UserRepository userRepository;

@Override
public Purchase createSubscribe(User user, Gateway gateway, String transactionId) {
user.setSubscribe(Subscribe.ACTIVE);
Purchase newPurchase =
Purchase.createPurchase(user, ProductType.YELLO_PLUS, gateway, transactionId);

return purchaseRepository.save(newPurchase);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Question(String nameHead, String nameFoot, String keywordHead, String key

private static String deleteBracket(String target) {
val slashIndex = target.indexOf('/');
return slashIndex != -1 ? target.substring(slashIndex + 1) : target;
return slashIndex!=-1 ? target.substring(slashIndex + 1) : target;
}

public static Question of(String nameHead, String nameFoot, String keywordHead, String keywordFoot) {
Expand All @@ -67,19 +67,19 @@ public void addKeyword(Keyword keyword) {
}

public String toNotificationSentence() {
val foot = deleteBracket(this.nameFoot);
if (this.nameHead == null) {
return MessageFormat.format("{0} ... ", foot);
}
return MessageFormat.format("{0} 너{1} ... ", this.nameHead, foot);
final String nameFootPart = deleteBracket(this.nameFoot);
final String nameHeadPart = (this.nameHead!=null) ? MessageFormat.format("{0} ", this.nameHead) : "";
final String keywordHeadPart = (this.keywordHead!=null) ? MessageFormat.format(" {0}", this.keywordHead) : "";

return MessageFormat.format("{0}너{1}{2} ...", nameHeadPart, nameFootPart, keywordHeadPart);
}

@Override
public boolean equals(Object o) {
if (this == o) {
if (this==o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (o==null || getClass()!=o.getClass()) {
return false;
}
Question question = (Question) o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class UserManagerImpl implements UserManager {
public User getOfficialUser(Gender gender) {
final String uuid =
"M".equals(gender.getIntial()) ? OFFICIAL_FEMALE_ID : OFFICIAL_MALE_ID;

return userRepository.findByUuid(uuid)
.orElseGet(() ->
userRepository.save(makeOfficialUser(OFFICIAL_NAME, uuid, gender.reverse()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.yello.server.small.domain.authorization;

import static com.yello.server.global.common.ErrorCode.NOT_SIGNIN_USER_EXCEPTION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.yello.server.domain.authorization.dto.ServiceTokenVO;
import com.yello.server.domain.authorization.exception.NotSignedInException;
import com.yello.server.domain.authorization.service.AuthManager;
import com.yello.server.domain.authorization.service.AuthManagerImpl;
import com.yello.server.domain.authorization.service.TokenJwtProvider;
import com.yello.server.domain.authorization.service.TokenProvider;
import com.yello.server.domain.cooldown.repository.CooldownRepository;
import com.yello.server.domain.friend.repository.FriendRepository;
import com.yello.server.domain.question.repository.QuestionRepository;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.repository.VoteRepository;
import com.yello.server.infrastructure.redis.repository.TokenRepository;
import com.yello.server.small.domain.cooldown.FakeCooldownRepository;
import com.yello.server.small.domain.friend.FakeFriendRepository;
import com.yello.server.small.domain.question.FakeQuestionRepository;
import com.yello.server.small.domain.user.FakeUserRepository;
import com.yello.server.small.domain.vote.FakeVoteRepository;
import com.yello.server.small.global.redis.FakeTokenRepository;
import com.yello.server.util.TestDataUtil;
import java.util.Base64;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AuthManagerTest {

private final String secretKey = Base64.getEncoder().encodeToString(
"keyForTestkeyForTestkeyForTestkeyForTestkeyForTestkeyForTestkeyForTestkeyForTestkeyForTest".getBytes());

private final UserRepository userRepository = new FakeUserRepository();
private final FriendRepository friendRepository = new FakeFriendRepository();
private final CooldownRepository cooldownRepository = new FakeCooldownRepository();
private final TokenRepository tokenRepository = new FakeTokenRepository();
private final QuestionRepository questionRepository = new FakeQuestionRepository();
private final VoteRepository voteRepository = new FakeVoteRepository();

private final TestDataUtil testDataUtil = new TestDataUtil(
userRepository,
voteRepository,
questionRepository,
friendRepository
);

private final TokenProvider tokenProvider = new TokenJwtProvider(secretKey);

private AuthManager authManager;

@BeforeEach
void init() {
this.authManager = AuthManagerImpl.builder()
.friendRepository(friendRepository)
.cooldownRepository(cooldownRepository)
.userRepository(userRepository)
.tokenRepository(tokenRepository)
.tokenProvider(tokenProvider)
.build();

// soft-deleted User
testDataUtil.generateDeletedUser(0L, 1L);

for (int i = 1; i <= 3; i++) {
testDataUtil.generateUser(i, 1L);
}
}

@Test
void uuid_가입한_유저를_가져옵니다() {
// given
final String uuid = "1";

// when
final User user = authManager.getSignedInUserByUuid(uuid);

// then
assertThat(user.getName()).isEqualTo("name1");
}

@Test
void uuid_가입한_유저_조회에_실패합니다() {
// given
final String uuid = "wrong_uuid";

// when
// then
assertThatThrownBy(() -> authManager.getSignedInUserByUuid(uuid))
.isInstanceOf(NotSignedInException.class)
.hasMessageContaining(NOT_SIGNIN_USER_EXCEPTION.getMessage());
}

@Test
void 토큰을_등록합니다() {
// given
final User user = userRepository.getById(1L);

// when
final ServiceTokenVO serviceTokenVO = authManager.registerToken(user);

// then
assertThat(serviceTokenVO.accessToken()).isNotEmpty();
assertThat(serviceTokenVO.refreshToken()).isNotEmpty();
}

@Test
void 새로운_액세스_토큰을_등록합니다() {
// given

// when

// then
}

@Test
void 새로운_액세스_토큰_등록__시크릿__인증에_실패합니다() {
// given
// when
// then
}

@Test
void 새로운_액세스_토큰_등록__유저_조회에_실패합니다() {
// given
// when
// then
}

@Test
void 회원_요청_객체_검증에_성공합니다() {
// given
// when
// then
}

@Test
void 회원_요청_객체가_이미_가입한_유저인_경우_실패합니다() {
// given
// when
// then
}

@Test
void 회원_요청_객체가_중복_yelloId_경우_실패합니다() {
// given
// when
// then
}

@Test
void 유저_입에_성공합니다() {
// given
// when
// then
}

@Test
void 탈퇴하지_않은_유저이거나_삭제_30일이_넘은_경우__처리를_진행하지_않습니다() {
// given
// when
// then
}
}
Loading

0 comments on commit 08925eb

Please sign in to comment.