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

๐Ÿ”€ :: (#261) ๋žญํ‚น ๊ด€๋ จ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ #262

Closed
wants to merge 1 commit into from
Closed
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
@@ -0,0 +1,117 @@
package io.github.opgg.music_ward_server.controller;

import io.github.opgg.music_ward_server.BaseIntegrationTest;
import io.github.opgg.music_ward_server.entity.champion.Champion;
import io.github.opgg.music_ward_server.entity.champion.ChampionRepository;
import io.github.opgg.music_ward_server.entity.playlist.Image;
import io.github.opgg.music_ward_server.entity.playlist.Playlist;
import io.github.opgg.music_ward_server.entity.playlist.PlaylistRepository;
import io.github.opgg.music_ward_server.entity.playlist.Provider;
import io.github.opgg.music_ward_server.entity.user.User;
import io.github.opgg.music_ward_server.entity.user.UserRepository;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class RankingControllerTest extends BaseIntegrationTest {

@Autowired
private UserRepository userRepository;

@Autowired
private ChampionRepository championRepository;

@Autowired
private PlaylistRepository playlistRepository;

static Champion generateChampion() {
return Champion.builder()
.name("๊ฐ€๋ Œ")
.title("๋ฐ๋งˆ์‹œ์•„์˜ ํž˜")
.englishName("Garen")
.story("๊ฐ€๋ Œ์€ ๋ถˆ๊ตด์˜ ์„ ๋ด‰๋Œ€๋ฅผ ์ด๋„๋Š” ๊ณ ๊ฒฐํ•˜๊ณ  ์ž๊ธ์‹ฌ ๊ฐ•ํ•œ ๊ตฐ์ธ์ด๋‹ค.")
.position("์ „์‚ฌ")
.profileImageUrl("/images/profile/garen.jpg")
.imageUrl("/images/garen.jpg")
.build();
}

static Playlist generatePlaylist(User user, Champion champion) {
return Playlist.builder()
.originalId("1234")
.provider(Provider.YOUTUBE)
.title("ํ…Œ์ŠคํŠธ ํ”Œ๋ ˆ์ด ๋ฆฌ์ŠคํŠธ")
.description("ํ…Œ์ŠคํŠธ ํ”Œ๋ ˆ์ด ๋ฆฌ์ŠคํŠธ ์„ค๋ช…")
.image(new Image("url", "640", "640"))
.externalUrl("์™ธ๋ถ€ url")
.user(user)
.champion(champion)
.build();
}

private User getUser() {
return userRepository.findById(1L).get();
}

@Test
@DisplayName("GET ranking?type=champion")
void getRankingByChampion() throws Exception {

// given
User user = getUser();
Champion champion = generateChampion();
Playlist playlist = generatePlaylist(user, champion);

championRepository.save(champion);
playlistRepository.save(playlist);

// when
String type = "champion";

// then
mockMvc.perform(get("/ranking")
.param("type", type))
.andDo(print())
.andExpect(status().isOk());
}

@Test
@DisplayName("GET ranking?type=playlist")
void getRankingByPlaylist() throws Exception {

// given
User user = getUser();
Champion champion = generateChampion();
Playlist playlist = generatePlaylist(user, champion);

championRepository.save(champion);
playlistRepository.save(playlist);

// when
String type = "playlist";

// then
mockMvc.perform(get("/ranking")
.param("type", type))
.andDo(print())
.andExpect(status().isOk());
}

@Test
@DisplayName("GET ranking - UnsupportedRankingTypeException")
void getRankingFail() throws Exception {

// given & when
String type = "champion1";

// then
mockMvc.perform(get("/ranking")
.param("type", type))
.andDo(print())
.andExpect(status().isBadRequest());
}
}