Search in sources :

Example 11 with Ability

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

the class AbilityTest method colorDuplicateException.

@DisplayName("서로 다른 역량끼리 색상이 같은 경우 예외가 발생한다.")
@Test
void colorDuplicateException() {
    // given
    String color = "색상";
    Ability ability1 = Ability.parent(1L, "역량1", "너잘의 3인칭 역량", color, member);
    Ability ability2 = Ability.parent(2L, "역량2", "아따따뚜겐", color, member);
    // when, then
    assertThatThrownBy(() -> ability1.validateDuplicateColor(Collections.singletonList(ability2))).isExactlyInstanceOf(AbilityParentColorDuplicateException.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 12 with Ability

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

the class AbilityTest method parametersForIsParent.

private static Stream<Arguments> parametersForIsParent() {
    Member member = mock(Member.class);
    Ability parent = Ability.parent(1L, "Language", "discription", "red", member);
    return Stream.of(Arguments.of(parent, true), Arguments.of(Ability.child(2L, "Language", "discription", "red", parent, member), false));
}
Also used : Ability(wooteco.prolog.ability.domain.Ability) Member(wooteco.prolog.member.domain.Member)

Example 13 with Ability

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

the class AbilityServiceTest method updateAbilityChildCanNotChangeColor.

@DisplayName("역량 정보를 수정할 때 자식 역량의 경우 색상이 변경되지 않는다.")
@Test
void updateAbilityChildCanNotChangeColor() {
    // given
    String legacyColor = "#111111";
    AbilityCreateRequest createParentRequest1 = new AbilityCreateRequest("부모 프로그래밍", "프로그래밍 역량입니다.", legacyColor, null);
    abilityService.createAbility(member.getId(), createParentRequest1);
    HierarchyAbilityResponse createdParentResponse = abilityService.findParentAbilitiesByMemberId(member.getId()).get(0);
    AbilityCreateRequest createChildRequest1 = new AbilityCreateRequest("자식 프로그래밍", "부모 프로그래밍의 자식입니다.", createdParentResponse.getColor(), createdParentResponse.getId());
    abilityService.createAbility(member.getId(), createChildRequest1);
    AbilityResponse childAbilityDto = abilityService.findParentAbilitiesByMemberId(member.getId()).get(0).getChildren().get(0);
    String newColor = "#ffffff";
    String newName = "완전히 새로운 이름";
    String newDescription = "완전히 새로운건데요?!";
    AbilityUpdateRequest request = new AbilityUpdateRequest(childAbilityDto.getId(), newName, newDescription, newColor);
    // when
    abilityService.updateAbility(member.getId(), request.getId(), request);
    // then
    Ability ability = abilityService.findAbilityById(childAbilityDto.getId());
    assertThat(ability.getName()).isEqualTo(newName);
    assertThat(ability.getDescription()).isEqualTo(newDescription);
    assertThat(ability.getColor()).isEqualTo(legacyColor);
}
Also used : AbilityCreateRequest(wooteco.prolog.ability.application.dto.AbilityCreateRequest) AbilityResponse(wooteco.prolog.ability.application.dto.AbilityResponse) HierarchyAbilityResponse(wooteco.prolog.ability.application.dto.HierarchyAbilityResponse) DefaultAbility(wooteco.prolog.ability.domain.DefaultAbility) Ability(wooteco.prolog.ability.domain.Ability) AbilityUpdateRequest(wooteco.prolog.ability.application.dto.AbilityUpdateRequest) 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 14 with Ability

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

the class AbilityServiceTest method deleteParentAbilityAndChildrenAbilities.

// 스펙이 변경되어 Disabled 처리함
@Disabled
@DisplayName("부모 역량 삭제에 성공하면 부모의 자역 역량도 모두 삭제된다.")
@Test
void deleteParentAbilityAndChildrenAbilities() {
    // given
    Ability parentAbility = abilityRepository.save(Ability.parent("브라운", "파파 브라운", "갈색", member));
    Ability childAbility1 = abilityRepository.save(Ability.child("현구막", "썬 현구막", "갈색", parentAbility, member));
    Ability childAbility2 = abilityRepository.save(Ability.child("서니", "도터 서니", "갈색", parentAbility, member));
    // when
    assertThat(abilityRepository.findAll()).containsExactly(parentAbility, childAbility1, childAbility2);
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).hasSize(3);
    abilityService.deleteAbility(member.getId(), parentAbility.getId());
    // then
    assertThat(abilityService.findAbilitiesByMemberId(member.getId())).isEmpty();
    assertThat(abilityRepository.findById(parentAbility.getId())).isNotPresent();
    assertThat(abilityRepository.findById(childAbility1.getId())).isNotPresent();
    assertThat(abilityRepository.findById(childAbility2.getId())).isNotPresent();
}
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) Disabled(org.junit.jupiter.api.Disabled)

Example 15 with Ability

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

the class AbilityServiceTest method deleteChildAbility.

@DisplayName("자식 역량 삭제에 성공하면 부모 역량과 관계가 끊어진다.")
@Test
void deleteChildAbility() {
    // given
    Ability parentAbility = abilityRepository.save(Ability.parent("zi존브라운123", "이견 있습니까?", "이견을 피로 물들이는 붉은 색", member));
    Ability childAbility = abilityRepository.save(Ability.child("손너잘", "내안으어두미", "이견을 피로 물들이는 붉은 색", parentAbility, member));
    // when
    assertThat(parentAbility.getChildren()).containsExactly(childAbility);
    abilityService.deleteAbility(member.getId(), childAbility.getId());
    List<HierarchyAbilityResponse> abilityResponses = abilityService.findAbilitiesByMemberId(member.getId());
    List<Long> abilityIds = abilityResponses.stream().map(HierarchyAbilityResponse::getId).collect(Collectors.toList());
    // then
    assertThat(abilityIds).containsExactly(parentAbility.getId());
}
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)

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