-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 아이템 정보 테이블 PK 변경 #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
259b930
feat: item info table pk 변경 flyway script 작성
dev-ant 6d6c1fd
fix: item category enum 오타 수정
dev-ant ae9973b
feat: item_info pk 변경 사항 코드 반영
dev-ant 15335cd
feat: item info 테스트 코드 작성
dev-ant 68583ea
fix: item info 테스트 코드 sub cateogry top category 혼동 사용 수정
dev-ant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/until/the/eternity/iteminfo/domain/entity/ItemInfoId.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package until.the.eternity.iteminfo.domain.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Embeddable; | ||
| import java.io.Serializable; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Embeddable | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| @EqualsAndHashCode | ||
| public class ItemInfoId implements Serializable { | ||
|
|
||
| @Column(name = "name", nullable = false) | ||
| private String name; | ||
|
|
||
| @Column(name = "sub_category", nullable = false) | ||
| private String subCategory; | ||
|
|
||
| @Column(name = "top_category", nullable = false) | ||
| private String topCategory; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ALTER TABLE item_info | ||
| DROP PRIMARY KEY, | ||
| ADD PRIMARY KEY (name, sub_category, top_category); |
116 changes: 116 additions & 0 deletions
116
src/test/java/until/the/eternity/iteminfo/application/service/ItemInfoServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package until.the.eternity.iteminfo.application.service; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import until.the.eternity.iteminfo.domain.entity.ItemInfo; | ||
| import until.the.eternity.iteminfo.domain.repository.ItemInfoRepositoryPort; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemCategoryResponse; | ||
| import until.the.eternity.iteminfo.interfaces.rest.dto.response.ItemInfoResponse; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class ItemInfoServiceTest { | ||
|
|
||
| @Mock private ItemInfoRepositoryPort itemInfoRepository; | ||
|
|
||
| @InjectMocks private ItemInfoService itemInfoService; | ||
|
|
||
| @Test | ||
| @DisplayName("모든 아이템 카테고리를 조회하면 카테고리 목록을 반환한다") | ||
| void findItemCategories_should_return_all_categories() { | ||
| // when | ||
| List<ItemCategoryResponse> result = itemInfoService.findItemCategories(); | ||
|
|
||
| // then | ||
| assertThat(result).isNotEmpty(); | ||
| assertThat(result).extracting("subCategory").contains("한손 장비", "검", "활"); | ||
| assertThat(result).extracting("topCategory").contains("근거리 장비", "원거리 장비"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("모든 아이템 정보를 조회하면 아이템 목록을 반환한다") | ||
| void findAll_should_return_all_items() { | ||
| // given | ||
| ItemInfo item1 = createItemInfo("나뭇가지", "한손검", "무기"); | ||
| ItemInfo item2 = createItemInfo("숏소드", "한손검", "무기"); | ||
| when(itemInfoRepository.findAll()).thenReturn(List.of(item1, item2)); | ||
|
|
||
| // when | ||
| List<ItemInfoResponse> result = itemInfoService.findAll(); | ||
|
|
||
| // then | ||
| assertThat(result).hasSize(2); | ||
| assertThat(result).extracting("name").containsExactly("나뭇가지", "숏소드"); | ||
| verify(itemInfoRepository).findAll(); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("상위 카테고리로 아이템을 조회하면 해당 카테고리의 아이템 목록을 반환한다") | ||
| void findByTopCategory_should_return_items_by_top_category() { | ||
| // given | ||
| String topCategory = "소모품"; | ||
| ItemInfo item1 = createItemInfo("염색 앰플", "염색 앰플", topCategory); | ||
| ItemInfo item2 = createItemInfo("지정 색상 염색 앰플", "염색 앰플", topCategory); | ||
| when(itemInfoRepository.findByTopCategory(topCategory)).thenReturn(List.of(item1, item2)); | ||
|
|
||
| // when | ||
| List<ItemInfoResponse> result = itemInfoService.findByTopCategory(topCategory); | ||
|
|
||
| // then | ||
| assertThat(result).hasSize(2); | ||
| assertThat(result).extracting("topCategory").containsOnly("소모품"); | ||
| assertThat(result).extracting("name").containsExactly("염색 앰플", "지정 색상 염색 앰플"); | ||
| verify(itemInfoRepository).findByTopCategory(topCategory); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("하위 카테고리로 아이템을 조회하면 해당 카테고리의 아이템 목록을 반환한다") | ||
| void findBySubCategory_should_return_items_by_sub_category() { | ||
| // given | ||
| String topCategory = "소모품"; | ||
| String subCategory = "염색 앰플"; | ||
| ItemInfo item1 = createItemInfo("염색 앰플", subCategory, topCategory); | ||
| ItemInfo item2 = createItemInfo("지정 색상 염색 앰플", subCategory, topCategory); | ||
| when(itemInfoRepository.findBySubCategory(subCategory)).thenReturn(List.of(item1, item2)); | ||
|
|
||
| // when | ||
| List<ItemInfoResponse> result = itemInfoService.findBySubCategory(subCategory); | ||
|
|
||
| // then | ||
| assertThat(result).hasSize(2); | ||
| assertThat(result).extracting("subCategory").containsOnly("염색 앰플"); | ||
| assertThat(result).extracting("name").containsExactly("염색 앰플", "지정 색상 염색 앰플"); | ||
| verify(itemInfoRepository).findBySubCategory(subCategory); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("아이템 정보가 없으면 빈 목록을 반환한다") | ||
| void findAll_should_return_empty_list_when_no_data() { | ||
| // given | ||
| when(itemInfoRepository.findAll()).thenReturn(List.of()); | ||
|
|
||
| // when | ||
| List<ItemInfoResponse> result = itemInfoService.findAll(); | ||
|
|
||
| // then | ||
| assertThat(result).isEmpty(); | ||
| verify(itemInfoRepository).findAll(); | ||
| } | ||
|
|
||
| private ItemInfo createItemInfo(String name, String subCategory, String topCategory) { | ||
| ItemInfo itemInfo = mock(ItemInfo.class); | ||
|
|
||
| when(itemInfo.getName()).thenReturn(name); | ||
| when(itemInfo.getSubCategory()).thenReturn(subCategory); | ||
| when(itemInfo.getTopCategory()).thenReturn(topCategory); | ||
|
|
||
| return itemInfo; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.