Skip to content

Commit

Permalink
Merge pull request #172 from prgrms-web-devcourse-final-project/fix/#171
Browse files Browse the repository at this point in the history


fix: ์‹ ๊ณ  ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ปดํŒŒ์ผ ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
hgh1472 authored Dec 8, 2024
2 parents 9272e0f + 39f3059 commit 62861dc
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class ComplaintsTest {
@DisplayName("ํ•œ ํŽธ์ง€์˜ ์‹ ๊ณ ์ž๊ฐ€ 2๋ช…์ผ ๊ฒฝ์šฐ, DuplicateComplainException ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.")
public void duplicateException() {
// GIVEN
Complaints complaints = Complaints.from(List.of(KeywordComplaint.create(1L, 1L, "์š•์„ค ์‚ฌ์šฉ")));
Complaint complaint = Complaint.create(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
Complaint duplicate = Complaint.create(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
Complaints complaints = Complaints.from(List.of(complaint));

// WHEN - THEN
assertThatThrownBy(() -> complaints.validateDuplication(1L)).isInstanceOf(DuplicateComplainException.class);
assertThatThrownBy(() -> complaints.add(duplicate)).isInstanceOf(DuplicateComplainException.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import postman.bottler.complaint.domain.Complaint;
import postman.bottler.complaint.domain.Complaints;
import postman.bottler.complaint.domain.KeywordComplaint;
import postman.bottler.complaint.service.KeywordComplaintRepository;

@DisplayName("ํ‚ค์›Œ๋“œ ์‹ ๊ณ  ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ํ…Œ์ŠคํŠธ")
Expand All @@ -21,12 +21,12 @@ public class KeywordComplaintRepositoryTest {
@DisplayName("ํŽธ์ง€ ID๋กœ ์ฐพ์€ ์‹ ๊ณ  ๊ฐ์ฒด๋“ค์€ mutable์ด์–ด์•ผ ํ•œ๋‹ค.")
public void mutable() {
// GIVEN
keywordComplaintRepository.save(KeywordComplaint.create(1L, 1L, "์„ค๋ช…"));
keywordComplaintRepository.save(Complaint.create(1L, 1L, "์„ค๋ช…"));

// WHEN
Complaints find = keywordComplaintRepository.findByLetterId(1L);

// THEN
Assertions.assertDoesNotThrow(() -> find.add(KeywordComplaint.create(1L, 1L, "์„ค๋ช…")));
Assertions.assertDoesNotThrow(() -> find.add(Complaint.create(1L, 1L, "์„ค๋ช…")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import postman.bottler.complaint.domain.Complaint;
import postman.bottler.complaint.domain.Complaints;
import postman.bottler.complaint.domain.MapComplaint;
import postman.bottler.complaint.service.MapComplaintRepository;

@DisplayName("์ง€๋„ ํŽธ์ง€ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ํ…Œ์ŠคํŠธ")
Expand All @@ -21,12 +21,12 @@ public class MapComplaintRepositoryTest {
@DisplayName("ํŽธ์ง€ ID๋กœ ์ฐพ์€ ์‹ ๊ณ  ๊ฐ์ฒด๋“ค์€ mutable์ด์–ด์•ผ ํ•œ๋‹ค.")
public void mutable() {
// GIVEN
mapComplaintRepository.save(MapComplaint.create(1L, 1L, "์„ค๋ช…"));
mapComplaintRepository.save(Complaint.create(1L, 1L, "์„ค๋ช…"));

// WHEN
Complaints find = mapComplaintRepository.findByLetterId(1L);

// THEN
Assertions.assertDoesNotThrow(() -> find.add(MapComplaint.create(1L, 1L, "์„ค๋ช…")));
Assertions.assertDoesNotThrow(() -> find.add(Complaint.create(1L, 1L, "์„ค๋ช…")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static postman.bottler.complaint.domain.ComplaintType.KEYWORD_LETTER;
import static postman.bottler.complaint.domain.ComplaintType.KEYWORD_REPLY_LETTER;
import static postman.bottler.complaint.domain.ComplaintType.MAP_LETTER;
import static postman.bottler.complaint.domain.ComplaintType.MAP_REPLY_LETTER;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -14,11 +18,8 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import postman.bottler.complaint.domain.Complaint;
import postman.bottler.complaint.domain.Complaints;
import postman.bottler.complaint.domain.KeywordComplaint;
import postman.bottler.complaint.domain.KeywordReplyComplaint;
import postman.bottler.complaint.domain.MapComplaint;
import postman.bottler.complaint.domain.MapReplyComplaint;
import postman.bottler.complaint.dto.response.ComplaintResponseDTO;
import postman.bottler.complaint.exception.DuplicateComplainException;

Expand All @@ -42,10 +43,10 @@ public void complainKeywordLetter() {
// GIVEN
when(keywordComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()));
when(keywordComplaintRepository.save(any())).thenReturn(
KeywordComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));
Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));

// WHEN
ComplaintResponseDTO response = complaintService.complainKeywordLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
ComplaintResponseDTO response = complaintService.complain(KEYWORD_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// THEN
assertThat(response.id()).isEqualTo(1L);
Expand All @@ -55,14 +56,14 @@ public void complainKeywordLetter() {
@DisplayName("๊ฐ™์€ ํ‚ค์›Œ๋“œ ํŽธ์ง€๋ฅผ 2ํšŒ ์ด์ƒ ์‹ ๊ณ  ์‹œ๋„ํ•  ๊ฒฝ์šฐ, DuplicateComplainException์„ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.")
public void duplicateKeywordComplain() {
// GIVEN
KeywordComplaint complaint = KeywordComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
Complaint complaint = Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
when(keywordComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()))
.thenReturn(Complaints.from(List.of(complaint)));
when(keywordComplaintRepository.save(any())).thenReturn(complaint);
complaintService.complainKeywordLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
complaintService.complain(KEYWORD_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// WHEN - THEN
assertThatThrownBy(() -> complaintService.complainKeywordLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
assertThatThrownBy(() -> complaintService.complain(KEYWORD_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
.isInstanceOf(DuplicateComplainException.class);
}

Expand All @@ -71,10 +72,10 @@ public void duplicateKeywordComplain() {
public void complainMapLetter() {
// GIVEN
when(mapComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()));
when(mapComplaintRepository.save(any())).thenReturn(MapComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));
when(mapComplaintRepository.save(any())).thenReturn(Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));

// WHEN
ComplaintResponseDTO response = complaintService.complainMapLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
ComplaintResponseDTO response = complaintService.complain(MAP_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// THEN
assertThat(response.id()).isEqualTo(1L);
Expand All @@ -84,14 +85,14 @@ public void complainMapLetter() {
@DisplayName("๊ฐ™์€ ์ง€๋„ ํŽธ์ง€๋ฅผ 2ํšŒ ์ด์ƒ ์‹ ๊ณ  ์‹œ๋„ํ•  ๊ฒฝ์šฐ, DuplicateComplainException์„ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.")
public void duplicateMapComplain() {
// GIVEN
MapComplaint complaint = MapComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
Complaint complaint = Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
when(mapComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()))
.thenReturn(Complaints.from(List.of(complaint)));
when(mapComplaintRepository.save(any())).thenReturn(complaint);
complaintService.complainMapLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
complaintService.complain(MAP_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// WHEN - THEN
assertThatThrownBy(() -> complaintService.complainMapLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
assertThatThrownBy(() -> complaintService.complain(MAP_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
.isInstanceOf(DuplicateComplainException.class);
}

Expand All @@ -101,10 +102,10 @@ public void complainKeywordReplyLetter() {
// GIVEN
when(keywordReplyComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()));
when(keywordReplyComplaintRepository.save(any())).thenReturn(
KeywordReplyComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));
Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));

// WHEN
ComplaintResponseDTO response = complaintService.complainKeywordReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
ComplaintResponseDTO response = complaintService.complain(KEYWORD_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// THEN
assertThat(response.id()).isEqualTo(1L);
Expand All @@ -114,14 +115,14 @@ public void complainKeywordReplyLetter() {
@DisplayName("๊ฐ™์€ ๋‹ต์žฅ ํŽธ์ง€๋ฅผ 2ํšŒ ์ด์ƒ ์‹ ๊ณ  ์‹œ๋„ํ•  ๊ฒฝ์šฐ, DuplicateComplainException์„ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.")
public void duplicateKeywordReplyComplain() {
// GIVEN
KeywordReplyComplaint complaint = KeywordReplyComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
Complaint complaint = Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
when(keywordReplyComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()))
.thenReturn(Complaints.from(List.of(complaint)));
when(keywordReplyComplaintRepository.save(any())).thenReturn(complaint);
complaintService.complainKeywordReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
complaintService.complain(KEYWORD_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// WHEN - THEN
assertThatThrownBy(() -> complaintService.complainKeywordReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
assertThatThrownBy(() -> complaintService.complain(KEYWORD_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
.isInstanceOf(DuplicateComplainException.class);
}

Expand All @@ -131,10 +132,10 @@ public void complainMapReplyLetter() {
// GIVEN
when(mapReplyComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()));
when(mapReplyComplaintRepository.save(any())).thenReturn(
MapReplyComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));
Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now()));

// WHEN
ComplaintResponseDTO response = complaintService.complainMapReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
ComplaintResponseDTO response = complaintService.complain(MAP_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// THEN
assertThat(response.id()).isEqualTo(1L);
Expand All @@ -144,14 +145,14 @@ public void complainMapReplyLetter() {
@DisplayName("๊ฐ™์€ ๋‹ต์žฅ ํŽธ์ง€๋ฅผ 2ํšŒ ์ด์ƒ ์‹ ๊ณ  ์‹œ๋„ํ•  ๊ฒฝ์šฐ, DuplicateComplainException์„ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.")
public void duplicateMapReplyComplain() {
// GIVEN
MapReplyComplaint complaint = MapReplyComplaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
Complaint complaint = Complaint.of(1L, 1L, 1L, "์š•์„ค์‚ฌ์šฉ", LocalDateTime.now());
when(mapReplyComplaintRepository.findByLetterId(1L)).thenReturn(Complaints.from(new ArrayList<>()))
.thenReturn(Complaints.from(List.of(complaint)));
when(mapReplyComplaintRepository.save(any())).thenReturn(complaint);
complaintService.complainMapReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ");
complaintService.complain(MAP_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ");

// WHEN - THEN
assertThatThrownBy(() -> complaintService.complainMapReplyLetter(1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
assertThatThrownBy(() -> complaintService.complain(MAP_REPLY_LETTER, 1L, 1L, "์š•์„ค ์‚ฌ์šฉ"))
.isInstanceOf(DuplicateComplainException.class);
}
}
43 changes: 43 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,49 @@ spring:
host: ${REDIS_HOST}
port: ${REDIS_PORT}

logging:
level:
org.springframework.jdbc.core.JdbcTemplate: DEBUG
org.springframework.jdbc.core.StatementCreatorUtils: TRACE


fcm:
private-key: ${BOTTLER_FCM_BASE64}

jwt:
secret: ${JWT_SECRET_KEY} # JWT ๋น„๋ฐ€ ํ‚ค
access:
token:
expiration: 1800000 # ์•ก์„ธ์Šค ํ† ํฐ ์œ ํšจ ์‹œ๊ฐ„ (30๋ถ„)
# expiration: 10000 # ์•ก์„ธ์Šค ํ† ํฐ ์œ ํšจ ์‹œ๊ฐ„ (10์ดˆ)
refresh:
token:
expiration: 604800000 # ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ ์œ ํšจ ์‹œ๊ฐ„ (7์ผ)

mail:
host: smtp.gmail.com
port: 587
username: ${EMAIL_USER_NAME}
password: ${EMAIL_PASSWORD}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
connectiontimeout: 5000
timeout: 5000
writetimeout: 5000

kakao:
client:
id: ${KAKAO_CLIENT_ID}
secret: ${KAKAO_CLIENT_SECRET}
redirect:
url: ${KAKAO_REDIRECT_URL}

slack:
token: ${SLACK_TOKEN}


0 comments on commit 62861dc

Please sign in to comment.