Add owned-games DTO and full profile support

Introduce SteamOwnedGamesResponse and SteamProfileAndGamesResponse DTOs and extend SteamApiService with getOwnedGames(...) and getFullPlayerProfile(...) to fetch and combine player summary and owned games. Update SteamTestController to return the combined profile/games response. Remove redundant Steam service URL entries from application.yml. Add SteamApiServiceTest to cover player summary, owned games (including null fields), and the combined profile flow; service falls back to empty lists on errors.
This commit is contained in:
lobo committed 2026-04-19 15:15:15 +02:00
1 parent 1dc2efba01
commit be9b70c541
6 files changed
+243 -6

No files matched your search

@@ -0,0 +1,170 @@
package core_service.modules.steam_adapter.service;
import core_service.modules.steam_adapter.api.dto.response.SteamOwnedGamesResponse;
import core_service.modules.steam_adapter.api.dto.response.SteamPlayerSummaryResponse;
import core_service.modules.steam_adapter.api.dto.response.SteamProfileAndGamesResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestClient;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.containsString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.queryParam;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
class SteamApiServiceTest {
private SteamApiService steamApiService;
private MockRestServiceServer server;
@BeforeEach
void setUp() {
RestClient.Builder builder = RestClient.builder();
server = MockRestServiceServer.bindTo(builder).build();
steamApiService = new SteamApiService(builder.build());
ReflectionTestUtils.setField(steamApiService, "apiKey", "test-api-key");
}
@Test
void getPlayerSummary_shouldReturnPlayer() {
String steamId = "76561197960435530";
String jsonResponse = """
{
"response": {
"players": [
{
"steamid": "76561197960435530",
"personaname": "TestUser",
"profileurl": "http://steamcommunity.com/id/testuser/",
"avatarfull": "http://media.steampowered.com/avatar.jpg"
}
]
}
}
""";
server.expect(requestTo(containsString("/ISteamUser/GetPlayerSummaries/v0002/")))
.andExpect(queryParam("steamids", steamId))
.andExpect(queryParam("key", "test-api-key"))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
Optional<SteamPlayerSummaryResponse.Player> result = steamApiService.getPlayerSummary(steamId);
assertThat(result).isPresent();
assertThat(result.get().personaname()).isEqualTo("TestUser");
}
@Test
void getOwnedGames_shouldReturnGames() {
String steamId = "76561197960435530";
String jsonResponse = """
{
"response": {
"game_count": 1,
"games": [
{
"appid": 10,
"name": "Counter-Strike",
"playtime_forever": 32,
"img_icon_url": "icon_url",
"has_community_visible_stats": true
}
]
}
}
""";
server.expect(requestTo(containsString("/IPlayerService/GetOwnedGames/v0001/")))
.andExpect(queryParam("steamid", steamId))
.andExpect(queryParam("key", "test-api-key"))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
List<SteamOwnedGamesResponse.Game> result = steamApiService.getOwnedGames(steamId);
assertThat(result).hasSize(1);
assertThat(result.get(0).name()).isEqualTo("Counter-Strike");
}
@Test
void getOwnedGames_shouldReturnGamesEvenWithNullValues() {
String steamId = "76561197960435530";
String jsonResponse = """
{
"response": {
"game_count": 1,
"games": [
{
"appid": 10,
"name": "Counter-Strike"
}
]
}
}
""";
server.expect(requestTo(containsString("/IPlayerService/GetOwnedGames/v0001/")))
.andRespond(withSuccess(jsonResponse, MediaType.APPLICATION_JSON));
List<SteamOwnedGamesResponse.Game> result = steamApiService.getOwnedGames(steamId);
assertThat(result).hasSize(1);
assertThat(result.get(0).name()).isEqualTo("Counter-Strike");
assertThat(result.get(0).playtimeForever()).isNull();
assertThat(result.get(0).hasCommunityVisibleStats()).isNull();
}
@Test
void getFullPlayerProfile_shouldReturnCombinedResult() {
String steamId = "76561197960435530";
String summaryJson = """
{
"response": {
"players": [
{
"steamid": "76561197960435530",
"personaname": "TestUser",
"profileurl": "url",
"avatarfull": "avatar"
}
]
}
}
""";
String gamesJson = """
{
"response": {
"game_count": 1,
"games": [
{
"appid": 10,
"name": "Counter-Strike",
"playtime_forever": 32,
"img_icon_url": "icon_url",
"has_community_visible_stats": true
}
]
}
}
""";
server.expect(requestTo(containsString("/ISteamUser/GetPlayerSummaries/v0002/")))
.andRespond(withSuccess(summaryJson, MediaType.APPLICATION_JSON));
server.expect(requestTo(containsString("/IPlayerService/GetOwnedGames/v0001/")))
.andRespond(withSuccess(gamesJson, MediaType.APPLICATION_JSON));
Optional<SteamProfileAndGamesResponse> result = steamApiService.getFullPlayerProfile(steamId);
assertThat(result).isPresent();
assertThat(result.get().player().personaname()).isEqualTo("TestUser");
assertThat(result.get().games()).hasSize(1);
assertThat(result.get().games().get(0).name()).isEqualTo("Counter-Strike");
}
}