Skip to content

Commit

Permalink
Fix #268 : MpgStatsClient.getStats - 404 Not Found / Content
Browse files Browse the repository at this point in the history
  • Loading branch information
axel3rd committed Nov 24, 2024
1 parent cb0f8b9 commit 5a98969
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/blondin/mpg/stats/MpgStatsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public synchronized Championship getStats(ChampionshipStatsType type) {
Date leagueDateRefresh = getLeaguesRefresh().getDate(championship.getInfos().getId());
if (leagueDateRefresh == null || championship.getDate().before(leagueDateRefresh)) {
// Force refresh by using a mini cache time
championship = get("leagues/" + type.getValue(), Championship.class, 1);
championship = get("leagues/" + type.getValue() + "_v2.json", Championship.class, 1);
}
cache.put(type, championship);
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/blondin/mpg/stats/MpgStatsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@

public class MpgStatsClientTest extends AbstractMockTestClient {

@Test
public void testApiV2DateRefreshMechanismNoRefreshDate() {
// No league date refresh
stubFor(get("/builds.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20220327-no-L1.json")));
stubFor(get("/leagues/Ligue-1_v2.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20220327.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Player p = mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getPlayer("Mbappé");
Assert.assertEquals(47, p.getPrice());
}

@Test
public void testApiV2DateRefreshMechanismOldChampionshipDate() {
// No league date refresh
stubFor(get("/builds.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20220327.json")));
stubFor(get("/leagues/Ligue-1_v2.json")
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-1.20220327-old-refresh.json")));
MpgStatsClient mpgStatsClient = MpgStatsClient.build(getConfig(), "http://localhost:" + getServer().port());

Player p = mpgStatsClient.getStats(ChampionshipStatsType.LIGUE_1).getPlayer("Mbappé");
Assert.assertEquals(47, p.getPrice());
}

@Test
public void testApiV2L1() {
stubFor(get("/builds.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2":"2022-03-25T15:35:23.614Z","3":"2022-03-25T15:35:43.968Z","4":"2022-03-25T15:35:57.096Z","5":"2022-03-25T15:36:06.884Z","Ligue-1-2020-2021":"2022-08-04T15:04:23.095Z","Ligue-1-2019-2020":"2022-08-04T15:28:19.922Z","Ligue-1-2021-2022":"2022-08-04T15:29:32.154Z"}

Large diffs are not rendered by default.

0 comments on commit 5a98969

Please sign in to comment.