-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ve-pokemon-query [BE-REFACTOR] Pokemon 쿼리 개선
- Loading branch information
Showing
6 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ permissions: | |
contents: read | ||
|
||
jobs: | ||
build: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
|
@@ -26,13 +26,36 @@ jobs: | |
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Set up MySQL | ||
- name: Set up Local MySQL | ||
uses: mirromutth/[email protected] | ||
with: | ||
mysql database: 'pokerogue' | ||
mysql user: ${{ secrets.TEST_DB_USERNAME }} | ||
mysql password: ${{ secrets.TEST_DB_PASSWORD }} | ||
|
||
- name: Set up Docker Compose | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y docker-compose | ||
- name: Set up Test MySQL | ||
run: | | ||
sudo touch docker-compose.yml | ||
echo "${{ secrets.DOCKER_COMPOSE_TEST_DB }}" | sudo tee docker-compose.yml > /dev/null | ||
docker-compose -f docker-compose.yml up -d | ||
- name: Wait for Test MySQL to be ready | ||
run: | | ||
for i in {1..30}; do | ||
if docker-compose exec -T pokerogue-db mysqladmin ping --host 127.0.0.1 --user ${{ secrets.TEST_DB_USERNAME }} --password=${{ secrets.TEST_DB_PASSWORD }} --silent; then | ||
echo "MySQL is up and running!" | ||
break | ||
else | ||
echo "Waiting for MySQL to be ready..." | ||
sleep 5 | ||
fi | ||
done | ||
- name: Run Test | ||
run: SPRING_PROFILES_ACTIVE=local-mysql ./gradlew clean test | ||
working-directory: ./backend/pokerogue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule resources
updated
from 260eea to 5903df
57 changes: 57 additions & 0 deletions
57
...okerogue/src/test/java/com/pokerogue/helper/pokemon/repository/PokemonRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.pokerogue.helper.pokemon.repository; | ||
|
||
import com.pokerogue.environment.repository.RepositoryTest; | ||
import com.pokerogue.helper.pokemon.domain.Pokemon; | ||
import com.pokerogue.helper.pokemon.domain.PokemonAbilityMapping; | ||
import com.pokerogue.helper.pokemon.domain.PokemonTypeMapping; | ||
import com.pokerogue.helper.type.domain.PokemonType; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
class PokemonRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired | ||
private PokemonRepository pokemonRepository; | ||
|
||
@Test | ||
@DisplayName("모든 포켓몬을 타입 정보와 함께 조회한다.") | ||
void findAllWithTypes() { | ||
List<Pokemon> pokemons = pokemonRepository.findAllWithTypes(); | ||
|
||
List<PokemonType> pokemonTypes = selectedPokemonTypes(pokemons); | ||
assertAll(() -> { | ||
assertThat(pokemons).isNotEmpty(); | ||
assertThat(pokemonTypes).isNotEmpty(); | ||
}); | ||
} | ||
|
||
private List<PokemonType> selectedPokemonTypes(List<Pokemon> pokemons) { | ||
return pokemons.stream() | ||
.map(Pokemon::getPokemonTypeMappings) | ||
.flatMap(pokemonTypeMappings -> pokemonTypeMappings.stream() | ||
.map(PokemonTypeMapping::getPokemonType)) | ||
.toList(); | ||
} | ||
|
||
@Test | ||
@DisplayName("id로 포켓몬 상세 정보를 타입, 특성 정보와 함께 조회한다.") | ||
void findDetailsById() { | ||
Pokemon pokemon = pokemonRepository.findAllWithTypes().get(0); | ||
Long firstPokemonId = pokemon.getId(); | ||
|
||
Pokemon queriedPokemon = pokemonRepository.findDetailsById(firstPokemonId).get(); | ||
|
||
assertAll(() -> { | ||
assertThat(queriedPokemon.getPokemonAbilityMappings().stream() | ||
.map(PokemonAbilityMapping::getPokemonAbility).toList()).isNotEmpty(); | ||
assertThat(queriedPokemon.getPokemonTypeMappings().stream() | ||
.map(PokemonTypeMapping::getPokemonType).toList()).isNotEmpty(); | ||
}); | ||
} | ||
} |