Search in sources :

Example 1 with Ability

use of wooteco.prolog.ability.domain.Ability in project prolog by woowacourse.

the class AbilityTest method nameDuplicateException.

@DisplayName("역량끼리 이름이 같은 경우 예외가 발생한다.")
@Test
void nameDuplicateException() {
    // given
    String name = "역량";
    Ability ability1 = Ability.parent(1L, "역량", "너잘의 3인칭 역량", "파란색", member);
    Ability ability2 = Ability.parent(2L, "역량", "아따따뚜겐", "초록색", member);
    // when, then
    assertThatThrownBy(() -> ability1.validateDuplicateName(Collections.singletonList(ability2))).isExactlyInstanceOf(AbilityNameDuplicateException.class);
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Ability

use of wooteco.prolog.ability.domain.Ability in project prolog by woowacourse.

the class AbilityServiceTest method parentAbilities.

@DisplayName("부모 역량만을 조회한다. (자식 정보가 포함되지 않는다.)")
@Test
void parentAbilities() {
    // given
    Ability parentAbility = abilityRepository.save(Ability.parent("메타버스", "폴리곤 덩어리들", "123456", member));
    Ability childAbility = abilityRepository.save(Ability.child("마자용", "마자아아아~용", "123456", parentAbility, member));
    HierarchyAbilityResponse expectResponse = new HierarchyAbilityResponse(parentAbility.getId(), parentAbility.getName(), parentAbility.getDescription(), parentAbility.getColor(), parentAbility.isParent(), AbilityResponse.listOf(Collections.singletonList(childAbility)));
    // when
    List<HierarchyAbilityResponse> responses = abilityService.findParentAbilitiesByMemberId(member.getId());
    // then
    assertThat(responses).hasSize(1);
    assertThat(responses.get(0)).usingRecursiveComparison().isEqualTo(expectResponse);
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Ability

use of wooteco.prolog.ability.domain.Ability in project prolog by woowacourse.

the class AbilityServiceTest method deleteParentAbility.

@DisplayName("부모 역량 삭제에 성공하면 조회되지 않는다.")
@Test
void deleteParentAbility() {
    // given
    Ability ability = abilityRepository.save(Ability.parent("zi존브라운123", "이견 있습니까?", "이견을 피로 물들이는 붉은 색", member));
    // when
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).usingRecursiveComparison().isEqualTo(HierarchyAbilityResponse.listOf(Collections.singletonList(ability)));
    abilityService.deleteAbility(member.getId(), ability.getId());
    // then
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).isEmpty();
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Ability

use of wooteco.prolog.ability.domain.Ability in project prolog by woowacourse.

the class AbilityServiceTest method findAbilitiesByMemberUsername.

@DisplayName("username을 통해 해당 멤버의 역량 목록을 조회한다.")
@Test
void findAbilitiesByMemberUsername() {
    // given
    Ability ability1 = abilityRepository.save(Ability.parent("나는ZI존브라운이다.", "이견있나?", "피의 붉은 색", member));
    Ability ability2 = abilityRepository.save(Ability.parent("나는킹갓브라운이다.", "이견은 없겠지?", "무지개 색", member));
    // when
    List<HierarchyAbilityResponse> abilityResponses = abilityService.findAbilitiesByMemberUsername(member.getUsername());
    // then
    assertThat(abilityResponses).usingRecursiveComparison().isEqualTo(HierarchyAbilityResponse.listOf(Arrays.asList(ability1, ability2)));
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Ability

use of wooteco.prolog.ability.domain.Ability in project prolog by woowacourse.

the class AbilityService method createAbility.

@Transactional
public AbilityResponse createAbility(Long memberId, AbilityCreateRequest request) {
    Member member = memberService.findById(memberId);
    Ability ability = extractAbility(member, request);
    return AbilityResponse.of(abilityRepository.save(ability));
}
Also used : DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) Member(wooteco.prolog.member.domain.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Ability (wooteco.prolog.ability.domain.Ability)21 DefaultAbility (wooteco.prolog.ability.domain.DefaultAbility)14 DisplayName (org.junit.jupiter.api.DisplayName)11 Test (org.junit.jupiter.api.Test)11 Member (wooteco.prolog.member.domain.Member)7 IntegrationTest (wooteco.support.utils.IntegrationTest)6 Transactional (org.springframework.transaction.annotation.Transactional)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 HierarchyAbilityResponse (wooteco.prolog.ability.application.dto.HierarchyAbilityResponse)4 AbilityResponse (wooteco.prolog.ability.application.dto.AbilityResponse)2 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Disabled (org.junit.jupiter.api.Disabled)1 EventListener (org.springframework.context.event.EventListener)1 Page (org.springframework.data.domain.Page)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1