Skip to content
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

[BE] refactor: artist 테스트 패키지에서 엔티티 생성을 픽스쳐를 사용하여 생성하도록 변경 (#811) #818

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.festago.artist.dto.command.ArtistUpdateCommand;
import com.festago.artist.repository.ArtistRepository;
import com.festago.artist.repository.MemoryArtistRepository;
import com.festago.support.fixture.ArtistFixture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
Expand Down Expand Up @@ -37,14 +38,13 @@ void setUp() {
Long artistId = artistCommandService.save(command);

// then
Artist actual = artistRepository.getOrThrow(artistId);
assertThat(actual.getId()).isPositive();
assertThat(artistRepository.findById(artistId)).isPresent();
}

@Test
void 아티스트_정보를_변경한다() {
// given
Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image1.png")).getId();
Long artistId = artistRepository.save(ArtistFixture.builder().name("고윤하").build()).getId();
ArtistUpdateCommand command = new ArtistUpdateCommand("윤하", "https://image.com/image2.png",
"https://image.com/image2.png");

Expand All @@ -57,13 +57,14 @@ void setUp() {
assertSoftly(softly -> {
softly.assertThat(actual.getName()).isEqualTo(command.name());
softly.assertThat(actual.getProfileImage()).isEqualTo(command.profileImageUrl());
softly.assertThat(actual.getBackgroundImageUrl()).isEqualTo(command.backgroundImageUrl());
});
}

@Test
void 아티스트를_삭제한다() {
// given
Long artistId = artistRepository.save(new Artist("고윤하", "https://image.com/image.png")).getId();
Long artistId = artistRepository.save(ArtistFixture.builder().name("고윤하").build()).getId();

// when
artistCommandService.delete(artistId);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.mockito.BDDMockito.given;

import com.festago.artist.application.ArtistCommandService;
import com.festago.artist.application.ArtistDetailV1QueryService;
import com.festago.artist.domain.Artist;
import com.festago.artist.dto.ArtistFestivalDetailV1Response;
import com.festago.artist.dto.ArtistMediaV1Response;
import com.festago.artist.dto.command.ArtistCreateCommand;
import com.festago.artist.repository.ArtistRepository;
import com.festago.common.exception.ErrorCode;
import com.festago.common.exception.NotFoundException;
import com.festago.festival.application.command.FestivalCreateService;
import com.festago.festival.dto.command.FestivalCreateCommand;
import com.festago.school.application.SchoolCommandService;
import com.festago.festival.domain.Festival;
import com.festago.festival.repository.FestivalRepository;
import com.festago.school.domain.School;
import com.festago.school.domain.SchoolRegion;
import com.festago.school.dto.SchoolCreateCommand;
import com.festago.school.repository.SchoolRepository;
import com.festago.socialmedia.domain.OwnerType;
import com.festago.socialmedia.domain.SocialMedia;
import com.festago.socialmedia.domain.SocialMediaType;
import com.festago.socialmedia.repository.SocialMediaRepository;
import com.festago.stage.application.command.StageCreateService;
import com.festago.stage.dto.command.StageCreateCommand;
import com.festago.stage.domain.Stage;
import com.festago.stage.repository.StageArtistRepository;
import com.festago.stage.repository.StageRepository;
import com.festago.support.ApplicationIntegrationTest;
import com.festago.support.TimeInstantProvider;
import com.festago.support.fixture.ArtistFixture;
import com.festago.support.fixture.FestivalFixture;
import com.festago.support.fixture.SchoolFixture;
import com.festago.support.fixture.SocialMediaFixture;
import com.festago.support.fixture.StageArtistFixture;
import com.festago.support.fixture.StageFixture;
import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -48,16 +53,19 @@ class ArtistDetailV1QueryServiceIntegrationTest extends ApplicationIntegrationTe
ArtistDetailV1QueryService artistDetailV1QueryService;

@Autowired
ArtistCommandService artistCommandService;
ArtistRepository artistRepository;

@Autowired
FestivalCreateService festivalCreateService;
FestivalRepository festivalRepository;

@Autowired
SchoolCommandService schoolCommandService;
SchoolRepository schoolRepository;

@Autowired
StageCreateService stageCreateService;
StageRepository stageRepository;

@Autowired
StageArtistRepository stageArtistRepository;

@Autowired
SocialMediaRepository socialMediaRepository;
Expand All @@ -68,7 +76,7 @@ class 아티스트_상세_정보_조회 {
@Test
void 조회할_수_있다() {
// given
Long 아티스트_식별자 = createArtist("pooh");
Long 아티스트_식별자 = createArtist("pooh").getId();
makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.INSTAGRAM);
makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.YOUTUBE);

Expand All @@ -85,7 +93,7 @@ class 아티스트_상세_정보_조회 {
@Test
void 소셜_미디어가_없어도_조회할_수_있다() {
// given
Long 아티스트_식별자 = createArtist("pooh");
Long 아티스트_식별자 = createArtist("pooh").getId();

// when
var actual = artistDetailV1QueryService.findArtistDetail(아티스트_식별자);
Expand All @@ -100,7 +108,7 @@ class 아티스트_상세_정보_조회 {
@Test
void 소셜_미디어의_주인_아이디가_같더라도_주인의_타입에_따라_구분하여_조회한다() {
// given
Long 아티스트_식별자 = createArtist("pooh");
Long 아티스트_식별자 = createArtist("pooh").getId();
makeSocialMedia(아티스트_식별자, OwnerType.ARTIST, SocialMediaType.INSTAGRAM);

// when
Expand All @@ -122,8 +130,11 @@ class 아티스트_상세_정보_조회 {
}

Long makeSocialMedia(Long ownerId, OwnerType ownerType, SocialMediaType socialMediaType) {
SocialMedia socialMedia = new SocialMedia(ownerId, ownerType, socialMediaType, "총학생회",
"https://image.com/logo.png", "https://instgram.com/blahblah");
var socialMedia = SocialMediaFixture.builder()
.ownerId(ownerId)
.ownerType(ownerType)
.mediaType(socialMediaType)
.build();
return socialMediaRepository.save(socialMedia).getId();
}
}
Expand All @@ -141,49 +152,58 @@ class 아티스트가_참여한_축제_목록_조회 {
LocalDate _6월_15일 = LocalDate.parse("2077-06-15");
LocalDate _6월_16일 = LocalDate.parse("2077-06-16");

Long 아티스트A_식별자;
Artist 아티스트A;

Long 서울대학교_축제_식별자;
Long 부산대학교_축제_식별자;
Long 대구대학교_축제_식별자;
Festival 서울대학교_축제;
Festival 부산대학교_축제;
Festival 대구대학교_축제;

@BeforeEach
void setUp() {
Long 서울대학교_식별자 = createSchool("서울대학교", "seoul.ac.kr", SchoolRegion.서울);
Long 부산대학교_식별자 = createSchool("부산대학교", "busan.ac.kr", SchoolRegion.부산);
Long 대구대학교_식별자 = createSchool("대구대학교", "daegu.ac.kr", SchoolRegion.대구);

서울대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand(
"서울대학교 축제", _6월_14일, _6월_14일, "https://image.com/posterImage.png", 서울대학교_식별자
));
부산대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand(
"부산대학교 축제", _6월_15일, _6월_15일, "https://image.com/posterImage.png", 부산대학교_식별자
));
대구대학교_축제_식별자 = festivalCreateService.createFestival(new FestivalCreateCommand(
"대구대학교 축제", _6월_16일, _6월_16일, "https://image.com/posterImage.png", 대구대학교_식별자
));

아티스트A_식별자 = createArtist("아티스트A");

stageCreateService.createStage(new StageCreateCommand(
서울대학교_축제_식별자, _6월_14일.atTime(18, 0), _6월_14일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자)
));
stageCreateService.createStage(new StageCreateCommand(
부산대학교_축제_식별자, _6월_15일.atTime(18, 0), _6월_15일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자)
));
stageCreateService.createStage(new StageCreateCommand(
대구대학교_축제_식별자, _6월_16일.atTime(18, 0), _6월_16일.minusWeeks(1).atStartOfDay(), List.of(아티스트A_식별자)
));
School 서울대학교 = createSchool("서울대학교", "seoul.ac.kr", SchoolRegion.서울);
School 부산대학교 = createSchool("부산대학교", "busan.ac.kr", SchoolRegion.부산);
School 대구대학교 = createSchool("대구대학교", "daegu.ac.kr", SchoolRegion.대구);

서울대학교_축제 = createFestival("서울대학교 축제", _6월_14일, _6월_14일, 서울대학교);
부산대학교_축제 = createFestival("부산대학교 축제", _6월_15일, _6월_15일, 부산대학교);
대구대학교_축제 = createFestival("대구대학교 축제", _6월_16일, _6월_16일, 대구대학교);

아티스트A = createArtist("아티스트A");

createStage(서울대학교_축제, _6월_14일.atTime(18, 0), 아티스트A);
createStage(부산대학교_축제, _6월_15일.atTime(18, 0), 아티스트A);
createStage(대구대학교_축제, _6월_16일.atTime(18, 0), 아티스트A);

given(clock.instant())
.willReturn(TimeInstantProvider.from(now));
}

private Festival createFestival(String festivalName, LocalDate startDate, LocalDate endDate, School school) {
return festivalRepository.save(FestivalFixture.builder()
.name(festivalName)
.startDate(startDate)
.endDate(endDate)
.school(school)
.build()
);
}

private void createStage(Festival festival, LocalDateTime startTime, Artist... artists) {
Stage stage = stageRepository.save(StageFixture.builder()
.festival(festival)
.startTime(startTime)
.build()
);
for (Artist artist : artists) {
stageArtistRepository.save(StageArtistFixture.builder(stage.getId(), artist.getId()).build());
}
}

@Test
void 진행중인_축제_조회가_가능하다() {
// given & when
var actual = artistDetailV1QueryService.findArtistFestivals(
아티스트A_식별자,
아티스트A.getId(),
null,
null,
false,
Expand All @@ -193,14 +213,14 @@ void setUp() {
// then
assertThat(actual.getContent())
.map(ArtistFestivalDetailV1Response::id)
.containsExactly(부산대학교_축제_식별자, 대구대학교_축제_식별자);
.containsExactly(부산대학교_축제.getId(), 대구대학교_축제.getId());
}

@Test
void 종료된_축제_조회가_가능하다() {
// given & when
var actual = artistDetailV1QueryService.findArtistFestivals(
아티스트A_식별자,
아티스트A.getId(),
null,
null,
true,
Expand All @@ -210,14 +230,14 @@ void setUp() {
// then
assertThat(actual.getContent())
.map(ArtistFestivalDetailV1Response::id)
.containsExactly(서울대학교_축제_식별자);
.containsExactly(서울대학교_축제.getId());
}

@Test
void 커서_기반_페이징이_가능하다() {
// given
var firstResponse = artistDetailV1QueryService.findArtistFestivals(
아티스트A_식별자,
아티스트A.getId(),
null,
null,
false,
Expand All @@ -228,7 +248,7 @@ void setUp() {

// when
var secondResponse = artistDetailV1QueryService.findArtistFestivals(
아티스트A_식별자,
아티스트A.getId(),
firstFestivalResponse.id(),
firstFestivalResponse.startDate(),
false,
Expand All @@ -238,25 +258,23 @@ void setUp() {
// then
assertThat(secondResponse.getContent())
.map(ArtistFestivalDetailV1Response::id)
.containsExactly(대구대학교_축제_식별자);
.containsExactly(대구대학교_축제.getId());
}
}

private Long createSchool(String schoolName, String domain, SchoolRegion region) {
return schoolCommandService.createSchool(new SchoolCreateCommand(
schoolName,
domain,
region,
"https://image.com/logo.png",
"https://image.com/background.png"
));
private School createSchool(String schoolName, String domain, SchoolRegion region) {
return schoolRepository.save(SchoolFixture.builder()
.name(schoolName)
.domain(domain)
.region(region)
.build()
);
}

private Long createArtist(String artistName) {
return artistCommandService.save(new ArtistCreateCommand(
artistName,
"https://image.com/profileImage.png",
"https://image.com/backgroundImage.png"
));
private Artist createArtist(String artistName) {
return artistRepository.save(ArtistFixture.builder()
.name(artistName)
.build()
);
}
}
Loading
Loading