Skip to content

Commit

Permalink
refactor: MemberPart 기능 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
somsom13 committed Oct 19, 2023
1 parent be42a90 commit 8d98dad
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static MyPartsResponse of(final Song song, final MemberPart memberPart) {
song.getId(),
song.getTitle(),
song.getVideoId(),
song.getSinger(),
song.getArtistName(),
song.getAlbumCoverUrl(),
memberPart.getId(),
memberPart.getStartSecond(),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ schedules:
in-memory-token:
cron: "0/1 * * * * *"
in-memory-song:
cron: "0/1 * * * * *" # 1초
cron: "0 0/1 * * * *" # 1분
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import shook.shook.member.domain.Member;
import shook.shook.member_part.exception.MemberPartException;
import shook.shook.song.domain.Artist;
import shook.shook.song.domain.Genre;
import shook.shook.song.domain.KillingParts;
import shook.shook.song.domain.Song;
Expand All @@ -17,6 +18,7 @@ class MemberPartTest {

private static Song SONG;
private static Member MEMBER;
private static Artist ARTIST;

@BeforeEach
void setUp() {
Expand All @@ -27,8 +29,8 @@ void setUp() {
KillingPart.forSave(1, 10)
)
);

SONG = new Song("title", "12345678901", "albumCover", "singer", 300, Genre.DANCE, killingParts);
ARTIST = new Artist("profile", "image");
SONG = new Song("title", "12345678901", "albumCover", ARTIST, 300, Genre.DANCE, killingParts);
MEMBER = new Member("[email protected]", "shook");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import shook.shook.member.domain.repository.MemberRepository;
import shook.shook.member_part.domain.MemberPart;
import shook.shook.member_part.domain.repository.dto.SongMemberPartCreatedAtDto;
import shook.shook.song.domain.Artist;
import shook.shook.song.domain.Genre;
import shook.shook.song.domain.KillingParts;
import shook.shook.song.domain.Song;
import shook.shook.song.domain.killingpart.KillingPart;
import shook.shook.song.domain.repository.ArtistRepository;
import shook.shook.song.domain.repository.SongRepository;
import shook.shook.support.UsingJpaTest;

Expand All @@ -31,6 +33,9 @@ class MemberPartRepositoryTest extends UsingJpaTest {
@Autowired
private SongRepository songRepository;

@Autowired
private ArtistRepository artistRepository;

@DisplayName("멤버 아이디와 멤버 파트 아이디로 멤버 파트를 조회한다.")
@Test
void findByMemberIdAndId() {
Expand All @@ -42,7 +47,7 @@ void findByMemberIdAndId() {

// when
final Optional<MemberPart> optionalMember = memberPartRepository.findByMemberIdAndId(member.getId(),
memberPart.getId());
memberPart.getId());
final MemberPart savedMemberPart = optionalMember.get();

// then
Expand All @@ -56,8 +61,10 @@ private Song createNewSongWithKillingPartsAndSaveSong() {
final KillingPart secondKillingPart = KillingPart.forSave(15, 5);
final KillingPart thirdKillingPart = KillingPart.forSave(20, 5);

final Artist artist = new Artist("profile", "name");
artistRepository.save(artist);
final Song song = new Song(
"제목", "비디오ID는 11글자", "이미지URL", "가수", 180, Genre.from("댄스"),
"제목", "비디오ID는 11글자", "이미지URL", artist, 180, Genre.from("댄스"),
new KillingParts(List.of(firstKillingPart, secondKillingPart, thirdKillingPart)));

return songRepository.save(song);
Expand Down Expand Up @@ -90,16 +97,16 @@ void findBySongIdIn() {

// when
final List<MemberPart> memberParts = memberPartRepository.findByMemberAndSongIdIn(member,
List.of(firstSong.getId(),
secondSong.getId(),
thirdSong.getId()));
List.of(firstSong.getId(),
secondSong.getId(),
thirdSong.getId()));

// then
assertThat(memberParts).hasSize(3);
assertThat(memberParts.stream()
.map(MemberPart::getSong)
.map(Song::getId)
.toList()).contains(firstSong.getId(), secondSong.getId(), thirdSong.getId());
.map(MemberPart::getSong)
.map(Song::getId)
.toList()).contains(firstSong.getId(), secondSong.getId(), thirdSong.getId());
}

@DisplayName("나의 파트를 조회한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.test.context.jdbc.Sql;
import shook.shook.member.domain.Member;
import shook.shook.member.domain.repository.MemberRepository;
import shook.shook.part.domain.PartLength;
import shook.shook.song.application.dto.ArtistResponse;
import shook.shook.song.application.dto.ArtistWithSongSearchResponse;
import shook.shook.song.domain.Artist;
Expand All @@ -33,6 +32,7 @@
import shook.shook.song.exception.ArtistException;
import shook.shook.support.UsingJpaTest;

@SuppressWarnings("NonAsciiCharacters")
@Sql("classpath:/killingpart/initialize_killing_part_song.sql")
class ArtistSearchServiceTest extends UsingJpaTest {

Expand Down Expand Up @@ -159,9 +159,9 @@ private void saveSong(final Song song) {
}

private Song createNewSongWithArtist(final Artist artist) {
final KillingPart firstKillingPart = KillingPart.forSave(10, PartLength.SHORT);
final KillingPart secondKillingPart = KillingPart.forSave(15, PartLength.SHORT);
final KillingPart thirdKillingPart = KillingPart.forSave(20, PartLength.SHORT);
final KillingPart firstKillingPart = KillingPart.forSave(10, 5);
final KillingPart secondKillingPart = KillingPart.forSave(15, 5);
final KillingPart thirdKillingPart = KillingPart.forSave(20, 5);

return new Song(
"title",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package shook.shook.song.application;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -8,10 +10,6 @@
import org.springframework.test.context.jdbc.Sql;
import shook.shook.song.domain.InMemorySongs;

import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

@Sql(value = "classpath:/killingpart/initialize_killing_part_song.sql")
@EnableScheduling
@SpringBootTest
Expand All @@ -33,16 +31,4 @@ void recreateCachedSong() {
// then
assertThat(inMemorySongs.getSongs()).hasSize(4);
}

@DisplayName("Scheduler 가 1초마다 실행된다.")
@Test
void schedule() throws InterruptedException {
// given
// when
inMemorySongs.recreate(Collections.emptyList());
Thread.sleep(1000);

// then
assertThat(inMemorySongs.getSongs()).hasSize(4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,27 @@ void findById_exist_login_member() {
saveAndClearEntityManager();
final SongSwipeResponse response =
songService.findSongByIdForFirstSwipe(song.getId(),
new MemberInfo(member.getId(), Authority.MEMBER));
new MemberInfo(member.getId(), Authority.MEMBER));

//then
assertAll(
() -> assertThat(response.getPrevSongs()).isEmpty(),
() -> assertThat(response.getNextSongs()).isEmpty(),
() -> assertThat(response.getCurrentSong().getKillingParts().get(0))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(0).getId())
song.getLikeCountSortedKillingParts().get(0).getId())
.hasFieldOrPropertyWithValue("rank", 1)
.hasFieldOrPropertyWithValue("likeStatus", true),

() -> assertThat(response.getCurrentSong().getKillingParts().get(1))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(1).getId())
song.getLikeCountSortedKillingParts().get(1).getId())
.hasFieldOrPropertyWithValue("rank", 2)
.hasFieldOrPropertyWithValue("likeStatus", true),

() -> assertThat(response.getCurrentSong().getKillingParts().get(2))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(2).getId())
song.getLikeCountSortedKillingParts().get(2).getId())
.hasFieldOrPropertyWithValue("rank", 3)
.hasFieldOrPropertyWithValue("likeStatus", true),
() -> assertThat(response.getCurrentSong().getMemberPart().getId()).isNotNull()
Expand All @@ -167,27 +167,27 @@ void findById_exist_not_login_member() {
saveAndClearEntityManager();
final SongSwipeResponse response =
songService.findSongByIdForFirstSwipe(song.getId(),
new MemberInfo(0L, Authority.ANONYMOUS));
new MemberInfo(0L, Authority.ANONYMOUS));

//then
assertAll(
() -> assertThat(response.getPrevSongs()).isEmpty(),
() -> assertThat(response.getNextSongs()).isEmpty(),
() -> assertThat(response.getCurrentSong().getKillingParts().get(0))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(0).getId())
song.getLikeCountSortedKillingParts().get(0).getId())
.hasFieldOrPropertyWithValue("rank", 1)
.hasFieldOrPropertyWithValue("likeStatus", false),

() -> assertThat(response.getCurrentSong().getKillingParts().get(1))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(1).getId())
song.getLikeCountSortedKillingParts().get(1).getId())
.hasFieldOrPropertyWithValue("rank", 2)
.hasFieldOrPropertyWithValue("likeStatus", false),

() -> assertThat(response.getCurrentSong().getKillingParts().get(2))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(2).getId())
song.getLikeCountSortedKillingParts().get(2).getId())
.hasFieldOrPropertyWithValue("rank", 3)
.hasFieldOrPropertyWithValue("likeStatus", false),
() -> assertThat(response.getCurrentSong().getMemberPart()).isNull()
Expand All @@ -203,9 +203,9 @@ void findById_notExist() {
//when
//then
assertThatThrownBy(() -> songService.findSongByIdForFirstSwipe(
0L,
new MemberInfo(member.getId(), Authority.MEMBER)
)
0L,
new MemberInfo(member.getId(), Authority.MEMBER)
)
).isInstanceOf(SongException.SongNotExistException.class);
}

Expand Down Expand Up @@ -316,28 +316,28 @@ void firstFindByMember() {
// when
final SongSwipeResponse result =
songService.findSongByIdForFirstSwipe(fifthSong.getId(),
new MemberInfo(member.getId(), Authority.MEMBER));
new MemberInfo(member.getId(), Authority.MEMBER));

// then
assertAll(
() -> assertThat(result.getCurrentSong().getId()).isEqualTo(fifthSong.getId()),
() -> assertThat(result.getPrevSongs()).hasSize(2),
() -> assertThat(result.getNextSongs()).hasSize(2),
() -> assertThat(result.getPrevSongs().stream()
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(4L, 3L)),
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(4L, 3L)),
() -> assertThat(result.getNextSongs().stream()
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 1L)),
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 1L)),
() -> assertThat(result.getCurrentSong().getMemberPart()).isNull(),
() -> assertThat(result.getPrevSongs().stream()
.map(songResponse -> songResponse.getMemberPart().getId())
.toList())
.map(songResponse -> songResponse.getMemberPart().getId())
.toList())
.usingRecursiveComparison()
.isEqualTo(List.of(4L, 3L)),
() -> assertThat(result.getNextSongs().stream()
.map(songResponse -> songResponse.getMemberPart().getId())
.toList())
.map(songResponse -> songResponse.getMemberPart().getId())
.toList())
.usingRecursiveComparison()
.isEqualTo(List.of(2L, 1L))
);
Expand All @@ -354,15 +354,15 @@ void firstFindByAnonymous() {
// then
assertThatThrownBy(
() -> songService.findSongByIdForFirstSwipe(notExistSongId,
new MemberInfo(member.getId(), Authority.MEMBER)))
new MemberInfo(member.getId(), Authority.MEMBER)))
.isInstanceOf(SongException.SongNotExistException.class);
assertThatThrownBy(
() -> songService.findSongByIdForBeforeSwipe(notExistSongId,
new MemberInfo(member.getId(), Authority.MEMBER)))
new MemberInfo(member.getId(), Authority.MEMBER)))
.isInstanceOf(SongException.SongNotExistException.class);
assertThatThrownBy(
() -> songService.findSongByIdForAfterSwipe(notExistSongId,
new MemberInfo(member.getId(), Authority.MEMBER)))
new MemberInfo(member.getId(), Authority.MEMBER)))
.isInstanceOf(SongException.SongNotExistException.class);
}

Expand Down Expand Up @@ -398,16 +398,16 @@ void findSongByIdForBeforeSwipe() {
// when
final List<SongResponse> beforeResponses =
songService.findSongByIdForBeforeSwipe(standardSong.getId(),
new MemberInfo(member.getId(), Authority.MEMBER));
new MemberInfo(member.getId(), Authority.MEMBER));

// then
assertThat(beforeResponses.stream()
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 4L, 1L, 5L));
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 4L, 1L, 5L));
assertThat(beforeResponses.stream()
.map(SongResponse::getMemberPart)
.map(MemberPartResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 4L, 1L, 5L));
.map(SongResponse::getMemberPart)
.map(MemberPartResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(2L, 4L, 1L, 5L));
}

@DisplayName("이후 노래를 1. 좋아요 순 내림차순, 2. id 내림차순으로 조회한다.")
Expand Down Expand Up @@ -442,16 +442,16 @@ void findSongByIdForAfterSwipe() {
// when
final List<SongResponse> afterResponses =
songService.findSongByIdForAfterSwipe(standardSong.getId(),
new MemberInfo(member.getId(), Authority.MEMBER));
new MemberInfo(member.getId(), Authority.MEMBER));

// then
assertThat(afterResponses.stream()
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(1L, 5L, 3L));
.map(SongResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(1L, 5L, 3L));
assertThat(afterResponses.stream()
.map(SongResponse::getMemberPart)
.map(MemberPartResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(1L, 5L, 3L));
.map(SongResponse::getMemberPart)
.map(MemberPartResponse::getId)
.toList()).usingRecursiveComparison().isEqualTo(List.of(1L, 5L, 3L));
}
}

Expand Down Expand Up @@ -490,7 +490,7 @@ void findSongsByGenre() {
assertAll(
() -> assertThat(response).hasSize(5),
() -> assertThat(response.stream()
.map(HighLikedSongResponse::getId).toList())
.map(HighLikedSongResponse::getId).toList())
.containsExactly(2L, 1L, 3L, 5L, 4L)
);
}
Expand All @@ -509,30 +509,30 @@ void findSongById() {

// when
final SongResponse response = songService.findSongById(song.getId(),
new MemberInfo(member.getId(), Authority.MEMBER));
new MemberInfo(member.getId(), Authority.MEMBER));

// then
assertAll(
() -> assertThat(response.getId()).isEqualTo(song.getId()),
() -> assertThat(response.getTitle()).isEqualTo(song.getTitle()),
() -> assertThat(response.getAlbumCoverUrl()).isEqualTo(song.getAlbumCoverUrl()),
() -> assertThat(response.getSinger()).isEqualTo(song.getSinger()),
() -> assertThat(response.getSinger()).isEqualTo(song.getArtistName()),
() -> assertThat(response.getKillingParts()).hasSize(3),
() -> assertThat(response.getKillingParts().get(0))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(0).getId())
song.getLikeCountSortedKillingParts().get(0).getId())
.hasFieldOrPropertyWithValue("rank", 1)
.hasFieldOrPropertyWithValue("likeStatus", true),

() -> assertThat(response.getKillingParts().get(1))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(1).getId())
song.getLikeCountSortedKillingParts().get(1).getId())
.hasFieldOrPropertyWithValue("rank", 2)
.hasFieldOrPropertyWithValue("likeStatus", true),

() -> assertThat(response.getKillingParts().get(2))
.hasFieldOrPropertyWithValue("id",
song.getLikeCountSortedKillingParts().get(2).getId())
song.getLikeCountSortedKillingParts().get(2).getId())
.hasFieldOrPropertyWithValue("rank", 3)
.hasFieldOrPropertyWithValue("likeStatus", true),
() -> assertThat(response.getMemberPart().getId()).isNotNull()
Expand Down

0 comments on commit 8d98dad

Please sign in to comment.