-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OING-341] feature: 가족 이름 수정 API 추가 및 조회 API 응답 수정 (#264)
* feature: add familyName field in api * feature: add UpdateFamilyName API * fix: fix failed test related to family * test: add updateFamilyName test code * refactor: add familyNameEditorId to FamilyResponse
- Loading branch information
Showing
13 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
family/src/main/java/com/oing/dto/request/UpdateFamilyNameRequest.java
This file contains 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,13 @@ | ||
package com.oing.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Size; | ||
|
||
@Schema(description = "가족 이름 수정 요청") | ||
public record UpdateFamilyNameRequest( | ||
|
||
@Size(max = 10) | ||
@Schema(description = "가족 이름", example = "오잉") | ||
String familyName | ||
) { | ||
} |
This file contains 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 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 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
80 changes: 80 additions & 0 deletions
80
family/src/test/java/com/oing/service/FamilyServiceTest.java
This file contains 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,80 @@ | ||
package com.oing.service; | ||
|
||
import com.oing.domain.Family; | ||
import com.oing.repository.FamilyRepository; | ||
import com.oing.util.IdentityGenerator; | ||
import jakarta.transaction.Transactional; | ||
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 org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.security.InvalidParameterException; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
@Transactional | ||
@ActiveProfiles("test") | ||
@ExtendWith(MockitoExtension.class) | ||
public class FamilyServiceTest { | ||
|
||
@InjectMocks | ||
private FamilyService familyService; | ||
@Mock | ||
private FamilyRepository familyRepository; | ||
@Mock | ||
private FamilyTopPercentageHistoryService familyTopPercentageHistoryService; | ||
@Mock | ||
private FamilyScoreBridge familyScoreBridge; | ||
@Mock | ||
private IdentityGenerator identityGenerator; | ||
|
||
@Test | ||
void 가족_이름_수정_테스트() { | ||
// given | ||
String newName = "new-name"; | ||
String memberId = "1"; | ||
String familyId = "1"; | ||
|
||
// when | ||
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null))); | ||
Family family = familyService.updateFamilyName(familyId, memberId, newName); | ||
|
||
// then | ||
assertEquals(newName, family.getFamilyName()); | ||
assertEquals(memberId, family.getFamilyNameEditorId()); | ||
} | ||
|
||
@Test | ||
void 열_자_초과_가족_이름_수정_예외_검증() { | ||
// given | ||
String newName = "wrong-length-name"; | ||
String memberId = "1"; | ||
String familyId = "1"; | ||
|
||
// when | ||
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null))); | ||
|
||
// then | ||
assertThrows(InvalidParameterException.class, () -> familyService.updateFamilyName(familyId, memberId, newName)); | ||
} | ||
|
||
@Test | ||
void 공백만을_포함한_이름_수정_예외_검증() { | ||
// given | ||
String newName = " "; | ||
String memberId = "1"; | ||
String familyId = "1"; | ||
|
||
// when | ||
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null))); | ||
|
||
// then | ||
assertThrows(InvalidParameterException.class, () -> familyService.updateFamilyName(familyId, memberId, newName)); | ||
} | ||
} |
This file contains 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 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
1 change: 1 addition & 0 deletions
1
.../resources/db/migration/V202406211527__add_family_name_editor_id_column_to_family_tbl.sql
This file contains 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 @@ | ||
ALTER TABLE `family` ADD COLUMN (`family_name_editor_id` CHAR(26) COMMENT 'ULID'); |
This file contains 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 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 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